#import <stdio.h>
#import <stdlib.h>

typedef int Int;

Int compareInt(const void *a, const void *b) {
    return *(Int*)a - *(Int*)b;
}

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Int N, K;
        scanf("%d %d", &N, &K);
        Int *numbers = (int *)malloc(N * sizeof(Int));
        
        Int n;
        Int i = 0;
        while (scanf("%d", &n) != EOF) {
            numbers[i] = n;
            i++;
        }
        
        qsort(numbers, N, sizeof(Int), compareInt);
        
        Int min = numbers[N-1];
        for (Int i=0; i<=N-K; i++) {
            Int diff = numbers[i+K-1] - numbers[i];
            min = (min<diff) ? min : diff;
        }
        printf("%d\n", min);
    }
    return 0;
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_402/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_402/source.m"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

$.objc_sel_namealloc = comdat any

$.objc_sel_namedrain = comdat any

$.objc_sel_nameinit = comdat any

@0 = private unnamed_addr constant [18 x i8] c"NSAutoreleasePool\00", align 1
@__objc_class_name_NSAutoreleasePool = external global i64
@__objc_class_ref_NSAutoreleasePool = weak local_unnamed_addr constant ptr @__objc_class_name_NSAutoreleasePool
@.str = private unnamed_addr constant [6 x i8] c"%d %d\00", align 1
@.str.1 = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@.str.2 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@1 = private unnamed_addr constant [12 x i8] c"AnotherHack\00", align 1
@2 = private unnamed_addr constant [33 x i8] c"__ObjC_Protocol_Holder_Ugly_Hack\00", align 1
@.objc_protocol_list = internal global { ptr, i64, [0 x ptr] } zeroinitializer, align 8
@3 = internal global { ptr, ptr, ptr, ptr, ptr } { ptr @1, ptr @2, ptr null, ptr null, ptr @.objc_protocol_list }, align 8
@.objc_sel_namealloc = linkonce_odr constant [6 x i8] c"alloc\00", comdat
@.objc_sel_namedrain = linkonce_odr constant [6 x i8] c"drain\00", comdat
@.objc_sel_nameinit = linkonce_odr constant [5 x i8] c"init\00", comdat
@.objc_selector_list = internal global [4 x { ptr, ptr }] [{ ptr, ptr } { ptr @.objc_sel_namealloc, ptr null }, { ptr, ptr } { ptr @.objc_sel_namedrain, ptr null }, { ptr, ptr } { ptr @.objc_sel_nameinit, ptr null }, { ptr, ptr } zeroinitializer], align 8
@4 = internal global { i64, ptr, i16, i16, [3 x ptr] } { i64 3, ptr @.objc_selector_list, i16 0, i16 1, [3 x ptr] [ptr @3, ptr null, ptr null] }, align 8
@.objc_source_file_name = private unnamed_addr constant [129 x i8] c"/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_402//data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_402/source.m\00", align 1
@5 = internal global { i64, i64, ptr, ptr } { i64 8, i64 32, ptr @.objc_source_file_name, ptr @4 }, align 8
@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @.objc_load_function, ptr null }]

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local i32 @compareInt(ptr nocapture noundef readonly %a, ptr nocapture noundef readonly %b) #0 {
entry:
  %0 = load i32, ptr %a, align 4, !tbaa !5
  %1 = load i32, ptr %b, align 4, !tbaa !5
  %sub = sub nsw i32 %0, %1
  ret i32 %sub
}

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %argc, ptr nocapture noundef readnone %argv) local_unnamed_addr #1 {
entry:
  %N = alloca i32, align 4
  %K = alloca i32, align 4
  %n = alloca i32, align 4
  %0 = tail call ptr (ptr, ...) @objc_lookup_class(ptr nonnull @0) #7
  %1 = tail call ptr @objc_msg_lookup(ptr %0, ptr nonnull @.objc_selector_list) #7, !GNUObjCMessageSend !9
  %call = tail call ptr %1(ptr noundef %0, ptr noundef nonnull @.objc_selector_list) #7, !GNUObjCMessageSend !9
  %2 = tail call ptr @objc_msg_lookup(ptr %call, ptr nonnull getelementptr inbounds ([4 x { ptr, ptr }], ptr @.objc_selector_list, i64 0, i64 2)) #7, !GNUObjCMessageSend !10
  %call1 = tail call ptr %2(ptr noundef %call, ptr noundef nonnull getelementptr inbounds ([4 x { ptr, ptr }], ptr @.objc_selector_list, i64 0, i64 2)) #7, !GNUObjCMessageSend !10
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %N) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %K) #7
  %call2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %N, ptr noundef nonnull %K)
  %3 = load i32, ptr %N, align 4, !tbaa !5
  %conv = sext i32 %3 to i64
  %mul = shl nsw i64 %conv, 2
  %call3 = call noalias ptr @malloc(i64 noundef %mul) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %n) #7
  %call434 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %n)
  %cmp.not35 = icmp eq i32 %call434, -1
  br i1 %cmp.not35, label %while.end, label %while.body

while.body:                                       ; preds = %entry, %while.body
  %indvars.iv = phi i64 [ %indvars.iv.next, %while.body ], [ 0, %entry ]
  %4 = load i32, ptr %n, align 4, !tbaa !5
  %arrayidx = getelementptr inbounds i32, ptr %call3, i64 %indvars.iv
  store i32 %4, ptr %arrayidx, align 4, !tbaa !5
  %indvars.iv.next = add nuw i64 %indvars.iv, 1
  %call4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %n)
  %cmp.not = icmp eq i32 %call4, -1
  br i1 %cmp.not, label %while.end, label %while.body

while.end:                                        ; preds = %while.body, %entry
  %5 = load i32, ptr %N, align 4, !tbaa !5
  %conv6 = sext i32 %5 to i64
  call void @qsort(ptr noundef %call3, i64 noundef %conv6, i64 noundef 4, ptr noundef nonnull @compareInt) #7
  %6 = load i32, ptr %N, align 4, !tbaa !5
  %sub = add nsw i32 %6, -1
  %idxprom7 = sext i32 %sub to i64
  %arrayidx8 = getelementptr inbounds i32, ptr %call3, i64 %idxprom7
  %7 = load i32, ptr %arrayidx8, align 4, !tbaa !5
  %8 = load i32, ptr %K, align 4, !tbaa !5
  %cmp11.not37 = icmp slt i32 %6, %8
  br i1 %cmp11.not37, label %for.cond.cleanup, label %for.body.preheader

for.body.preheader:                               ; preds = %while.end
  %9 = add i32 %6, 1
  %10 = sub i32 %9, %8
  %wide.trip.count = zext i32 %10 to i64
  %min.iters.check = icmp ult i32 %10, 8
  br i1 %min.iters.check, label %for.body.preheader49, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %for.body.preheader
  %11 = add nsw i64 %wide.trip.count, -1
  %12 = add i32 %8, -1
  %13 = trunc i64 %11 to i32
  %14 = add i32 %12, %13
  %15 = icmp slt i32 %14, %12
  %16 = icmp ugt i64 %11, 4294967295
  %17 = or i1 %15, %16
  br i1 %17, label %for.body.preheader49, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %wide.trip.count, 4294967288
  %minmax.ident.splatinsert = insertelement <4 x i32> poison, i32 %7, i64 0
  %minmax.ident.splat = shufflevector <4 x i32> %minmax.ident.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %offset.idx = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ %minmax.ident.splat, %vector.ph ], [ %28, %vector.body ]
  %vec.phi45 = phi <4 x i32> [ %minmax.ident.splat, %vector.ph ], [ %29, %vector.body ]
  %18 = trunc i64 %offset.idx to i32
  %19 = add i32 %18, -1
  %20 = add i32 %19, %8
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr %call3, i64 %21
  %wide.load = load <4 x i32>, ptr %22, align 4, !tbaa !5
  %23 = getelementptr inbounds i32, ptr %22, i64 4
  %wide.load46 = load <4 x i32>, ptr %23, align 4, !tbaa !5
  %24 = getelementptr inbounds i32, ptr %call3, i64 %offset.idx
  %wide.load47 = load <4 x i32>, ptr %24, align 4, !tbaa !5
  %25 = getelementptr inbounds i32, ptr %24, i64 4
  %wide.load48 = load <4 x i32>, ptr %25, align 4, !tbaa !5
  %26 = sub nsw <4 x i32> %wide.load, %wide.load47
  %27 = sub nsw <4 x i32> %wide.load46, %wide.load48
  %28 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %vec.phi, <4 x i32> %26)
  %29 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %vec.phi45, <4 x i32> %27)
  %index.next = add nuw i64 %offset.idx, 8
  %30 = icmp eq i64 %index.next, %n.vec
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %rdx.minmax = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %28, <4 x i32> %29)
  %31 = call i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %rdx.minmax)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %for.cond.cleanup, label %for.body.preheader49

for.body.preheader49:                             ; preds = %vector.scevcheck, %for.body.preheader, %middle.block
  %indvars.iv41.ph = phi i64 [ 0, %vector.scevcheck ], [ 0, %for.body.preheader ], [ %n.vec, %middle.block ]
  %min.038.ph = phi i32 [ %7, %vector.scevcheck ], [ %7, %for.body.preheader ], [ %31, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %for.body.prol.loopexit, label %for.body.prol

for.body.prol:                                    ; preds = %for.body.preheader49
  %32 = trunc i64 %indvars.iv41.ph to i32
  %33 = add i32 %32, -1
  %sub13.prol = add i32 %33, %8
  %idxprom14.prol = sext i32 %sub13.prol to i64
  %arrayidx15.prol = getelementptr inbounds i32, ptr %call3, i64 %idxprom14.prol
  %34 = load i32, ptr %arrayidx15.prol, align 4, !tbaa !5
  %arrayidx17.prol = getelementptr inbounds i32, ptr %call3, i64 %indvars.iv41.ph
  %35 = load i32, ptr %arrayidx17.prol, align 4, !tbaa !5
  %sub18.prol = sub nsw i32 %34, %35
  %cond.prol = call i32 @llvm.smin.i32(i32 %min.038.ph, i32 %sub18.prol)
  %indvars.iv.next42.prol = or i64 %indvars.iv41.ph, 1
  br label %for.body.prol.loopexit

for.body.prol.loopexit:                           ; preds = %for.body.prol, %for.body.preheader49
  %cond.lcssa.unr = phi i32 [ undef, %for.body.preheader49 ], [ %cond.prol, %for.body.prol ]
  %indvars.iv41.unr = phi i64 [ %indvars.iv41.ph, %for.body.preheader49 ], [ %indvars.iv.next42.prol, %for.body.prol ]
  %min.038.unr = phi i32 [ %min.038.ph, %for.body.preheader49 ], [ %cond.prol, %for.body.prol ]
  %36 = sub nsw i64 0, %wide.trip.count
  %37 = xor i64 %indvars.iv41.ph, %36
  %38 = icmp eq i64 %37, -1
  br i1 %38, label %for.cond.cleanup, label %for.body

for.cond.cleanup:                                 ; preds = %for.body.prol.loopexit, %for.body, %middle.block, %while.end
  %min.0.lcssa = phi i32 [ %7, %while.end ], [ %31, %middle.block ], [ %cond.lcssa.unr, %for.body.prol.loopexit ], [ %cond.1, %for.body ]
  %call22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %min.0.lcssa)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %n) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %K) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %N) #7
  %39 = call ptr @objc_msg_lookup(ptr %call1, ptr nonnull getelementptr inbounds ([4 x { ptr, ptr }], ptr @.objc_selector_list, i64 0, i64 1)) #7, !GNUObjCMessageSend !14
  call void %39(ptr noundef %call1, ptr noundef nonnull getelementptr inbounds ([4 x { ptr, ptr }], ptr @.objc_selector_list, i64 0, i64 1)) #7, !GNUObjCMessageSend !14
  ret i32 0

for.body:                                         ; preds = %for.body.prol.loopexit, %for.body
  %indvars.iv41 = phi i64 [ %indvars.iv.next42.1, %for.body ], [ %indvars.iv41.unr, %for.body.prol.loopexit ]
  %min.038 = phi i32 [ %cond.1, %for.body ], [ %min.038.unr, %for.body.prol.loopexit ]
  %40 = trunc i64 %indvars.iv41 to i32
  %41 = add i32 %40, -1
  %sub13 = add i32 %41, %8
  %idxprom14 = sext i32 %sub13 to i64
  %arrayidx15 = getelementptr inbounds i32, ptr %call3, i64 %idxprom14
  %42 = load i32, ptr %arrayidx15, align 4, !tbaa !5
  %arrayidx17 = getelementptr inbounds i32, ptr %call3, i64 %indvars.iv41
  %43 = load i32, ptr %arrayidx17, align 4, !tbaa !5
  %sub18 = sub nsw i32 %42, %43
  %cond = call i32 @llvm.smin.i32(i32 %min.038, i32 %sub18)
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %44 = trunc i64 %indvars.iv.next42 to i32
  %45 = add i32 %44, -1
  %sub13.1 = add i32 %45, %8
  %idxprom14.1 = sext i32 %sub13.1 to i64
  %arrayidx15.1 = getelementptr inbounds i32, ptr %call3, i64 %idxprom14.1
  %46 = load i32, ptr %arrayidx15.1, align 4, !tbaa !5
  %arrayidx17.1 = getelementptr inbounds i32, ptr %call3, i64 %indvars.iv.next42
  %47 = load i32, ptr %arrayidx17.1, align 4, !tbaa !5
  %sub18.1 = sub nsw i32 %46, %47
  %cond.1 = call i32 @llvm.smin.i32(i32 %cond, i32 %sub18.1)
  %indvars.iv.next42.1 = add nuw nsw i64 %indvars.iv41, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next42.1, %wide.trip.count
  br i1 %exitcond.not.1, label %for.cond.cleanup, label %for.body, !llvm.loop !15
}

declare ptr @objc_lookup_class(ptr, ...) local_unnamed_addr

declare ptr @objc_msg_lookup(ptr, ptr) local_unnamed_addr

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

define internal void @.objc_load_function() {
entry:
  tail call void (ptr, ...) @__objc_exec_class(ptr nonnull @5)
  ret void
}

declare void @__objc_exec_class(ptr, ...) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #6

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.smin.v4i32(<4 x i32>, <4 x i32>) #6

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.smin.v4i32(<4 x i32>) #6

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nofree "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"alloc", !"", i1 false}
!10 = !{!"init", !"", i1 false}
!11 = distinct !{!11, !12, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = !{!"drain", !"", i1 false}
!15 = distinct !{!15, !12}
