; LLVM IR from ismdeep/sort-algos-c :: sort-algos-int-with-func (main)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @cmp(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [20000 x i32], align 16
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call i64 @time(ptr noundef null) #4
  %5 = trunc i64 %4 to i32
  call void @srandom(i32 noundef %5) #4
  call void @llvm.lifetime.start.p0(i64 80000, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %17, %0
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 20000
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %20

10:                                               ; preds = %6
  %11 = call i64 @random() #4
  %12 = srem i64 %11, 1000
  %13 = trunc i64 %12 to i32
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [20000 x i32], ptr %2, i64 0, i64 %15
  store i32 %13, ptr %16, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %10
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %3, align 4, !tbaa !5
  br label %6, !llvm.loop !9

20:                                               ; preds = %9
  %21 = getelementptr inbounds [20000 x i32], ptr %2, i64 0, i64 0
  call void @sort_test(ptr noundef %21, i32 noundef 20000, ptr noundef @selection_sort, ptr noundef @.str, ptr noundef @cmp)
  %22 = getelementptr inbounds [20000 x i32], ptr %2, i64 0, i64 0
  call void @sort_test(ptr noundef %22, i32 noundef 20000, ptr noundef @bubble_sort, ptr noundef @.str.1, ptr noundef @cmp)
  %23 = getelementptr inbounds [20000 x i32], ptr %2, i64 0, i64 0
  call void @sort_test(ptr noundef %23, i32 noundef 20000, ptr noundef @cocktail_sort, ptr noundef @.str.2, ptr noundef @cmp)
  %24 = getelementptr inbounds [20000 x i32], ptr %2, i64 0, i64 0
  call void @sort_test(ptr noundef %24, i32 noundef 20000, ptr noundef @insertion_sort, ptr noundef @.str.3, ptr noundef @cmp)
  %25 = getelementptr inbounds [20000 x i32], ptr %2, i64 0, i64 0
  call void @sort_test(ptr noundef %25, i32 noundef 20000, ptr noundef @quick_sort, ptr noundef @.str.4, ptr noundef @cmp)
  call void @llvm.lifetime.end.p0(i64 80000, ptr %2) #4
  ret i32 0
}

; Function Attrs: nounwind
declare void @srandom(i32 noundef) #1

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #1

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

; Function Attrs: nounwind
declare i64 @random() #1

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

declare void @sort_test(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #3

declare void @selection_sort(ptr noundef, i32 noundef, ptr noundef) #3

declare void @bubble_sort(ptr noundef, i32 noundef, ptr noundef) #3

declare void @cocktail_sort(ptr noundef, i32 noundef, ptr noundef) #3

declare void @insertion_sort(ptr noundef, i32 noundef, ptr noundef) #3

declare void @quick_sort(ptr noundef, i32 noundef, ptr noundef) #3

attributes #0 = { 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { nounwind }

!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 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @cmp(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [20000 x i32], align 16
  %2 = tail call i64 @time(ptr noundef null) #4
  %3 = trunc i64 %2 to i32
  tail call void @srandom(i32 noundef %3) #4
  call void @llvm.lifetime.start.p0(i64 80000, ptr nonnull %1) #4
  br label %5

4:                                                ; preds = %5
  call void @sort_test(ptr noundef nonnull %1, i32 noundef 20000, ptr noundef nonnull @selection_sort, ptr noundef nonnull @.str, ptr noundef nonnull @cmp) #4
  call void @sort_test(ptr noundef nonnull %1, i32 noundef 20000, ptr noundef nonnull @bubble_sort, ptr noundef nonnull @.str.1, ptr noundef nonnull @cmp) #4
  call void @sort_test(ptr noundef nonnull %1, i32 noundef 20000, ptr noundef nonnull @cocktail_sort, ptr noundef nonnull @.str.2, ptr noundef nonnull @cmp) #4
  call void @sort_test(ptr noundef nonnull %1, i32 noundef 20000, ptr noundef nonnull @insertion_sort, ptr noundef nonnull @.str.3, ptr noundef nonnull @cmp) #4
  call void @sort_test(ptr noundef nonnull %1, i32 noundef 20000, ptr noundef nonnull @quick_sort, ptr noundef nonnull @.str.4, ptr noundef nonnull @cmp) #4
  call void @llvm.lifetime.end.p0(i64 80000, ptr nonnull %1) #4
  ret i32 0

5:                                                ; preds = %0, %5
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %5 ]
  %6 = tail call i64 @random() #4
  %7 = srem i64 %6, 1000
  %8 = trunc nsw i64 %7 to i32
  %9 = getelementptr inbounds [20000 x i32], ptr %1, i64 0, i64 %indvars.iv
  store i32 %8, ptr %9, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 20000
  br i1 %exitcond.not, label %4, label %5, !llvm.loop !9
}

; Function Attrs: nounwind
declare void @srandom(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind
declare i64 @random() local_unnamed_addr #1

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

declare void @sort_test(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @selection_sort(ptr noundef, i32 noundef, ptr noundef) #3

declare void @bubble_sort(ptr noundef, i32 noundef, ptr noundef) #3

declare void @cocktail_sort(ptr noundef, i32 noundef, ptr noundef) #3

declare void @insertion_sort(ptr noundef, i32 noundef, ptr noundef) #3

declare void @quick_sort(ptr noundef, i32 noundef, ptr noundef) #3

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { nounwind }

!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 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass