; LLVM IR from ismdeep/sort-algos-c :: sort-algos (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 double], 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 160000, 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 = sitofp i64 %12 to double
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [20000 x double], ptr %2, i64 0, i64 %15
  store double %13, ptr %16, align 8, !tbaa !9
  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 !11

20:                                               ; preds = %9
  %21 = getelementptr inbounds [20000 x double], ptr %2, i64 0, i64 0
  %22 = getelementptr inbounds [20000 x double], ptr %2, i64 0, i64 0
  %23 = getelementptr inbounds double, ptr %22, i64 20000
  call void @sort_test(ptr noundef %21, ptr noundef %23, i64 noundef 8, ptr noundef @selection_sort, ptr noundef @.str, ptr noundef @cmp)
  %24 = getelementptr inbounds [20000 x double], ptr %2, i64 0, i64 0
  %25 = getelementptr inbounds [20000 x double], ptr %2, i64 0, i64 0
  %26 = getelementptr inbounds double, ptr %25, i64 20000
  call void @sort_test(ptr noundef %24, ptr noundef %26, i64 noundef 8, ptr noundef @bubble_sort, ptr noundef @.str.1, ptr noundef @cmp)
  %27 = getelementptr inbounds [20000 x double], ptr %2, i64 0, i64 0
  %28 = getelementptr inbounds [20000 x double], ptr %2, i64 0, i64 0
  %29 = getelementptr inbounds double, ptr %28, i64 20000
  call void @sort_test(ptr noundef %27, ptr noundef %29, i64 noundef 8, ptr noundef @cocktail_sort, ptr noundef @.str.2, ptr noundef @cmp)
  %30 = getelementptr inbounds [20000 x double], ptr %2, i64 0, i64 0
  %31 = getelementptr inbounds [20000 x double], ptr %2, i64 0, i64 0
  %32 = getelementptr inbounds double, ptr %31, i64 20000
  call void @sort_test(ptr noundef %30, ptr noundef %32, i64 noundef 8, ptr noundef @insertion_sort, ptr noundef @.str.3, ptr noundef @cmp)
  %33 = getelementptr inbounds [20000 x double], ptr %2, i64 0, i64 0
  %34 = getelementptr inbounds [20000 x double], ptr %2, i64 0, i64 0
  %35 = getelementptr inbounds double, ptr %34, i64 20000
  call void @sort_test(ptr noundef %33, ptr noundef %35, i64 noundef 8, ptr noundef @quick_sort, ptr noundef @.str.4, ptr noundef @cmp)
  call void @llvm.lifetime.end.p0(i64 160000, 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, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #3

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

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

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

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

declare void @quick_sort(ptr noundef, ptr noundef, i64 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 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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 double], 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 160000, ptr nonnull %1) #4
  br label %6

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

6:                                                ; preds = %0, %6
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %6 ]
  %7 = tail call i64 @random() #4
  %8 = srem i64 %7, 1000
  %9 = sitofp i64 %8 to double
  %10 = getelementptr inbounds [20000 x double], ptr %1, i64 0, i64 %indvars.iv
  store double %9, ptr %10, align 8, !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 %6, !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, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

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

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

declare void @quick_sort(ptr noundef, ptr noundef, i64 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 = !{!"double", !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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass