; LLVM IR from scandum/binary_search :: monobound_bsearch (execute)

; 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"

@checks = external dso_local global i32, align 4
@rnd = external dso_local global i32, align 4
@best = external dso_local global i64, align 8
@runs = external dso_local global i32, align 4
@start = external dso_local global i64, align 8
@loop = external dso_local global i32, align 4
@r_array = external dso_local global ptr, align 8
@o_array = external dso_local global ptr, align 8
@max = external dso_local global i32, align 4
@end = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: noinline nounwind uwtable
declare dso_local i32 @cmp_int(ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @utime() #2

; Function Attrs: nounwind uwtable
define dso_local void @execute(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %9 = load i32, ptr @rnd, align 4, !tbaa !9
  call void @srand(i32 noundef %9) #5
  store i64 0, ptr @best, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %10 = load i32, ptr @runs, align 4, !tbaa !9
  store i32 %10, ptr %8, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %57, %2
  %12 = load i32, ptr %8, align 4, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %60

15:                                               ; preds = %11
  store i32 0, ptr %6, align 4, !tbaa !9
  store i32 0, ptr %7, align 4, !tbaa !9
  store i32 0, ptr @checks, align 4, !tbaa !9
  %16 = call i64 @utime()
  store i64 %16, ptr @start, align 8, !tbaa !11
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %39, %15
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = load i32, ptr @loop, align 4, !tbaa !9
  %20 = icmp ult i32 %18, %19
  br i1 %20, label %21, label %42

21:                                               ; preds = %17
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load ptr, ptr @r_array, align 8, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %23, i64 %25
  %27 = load ptr, ptr @o_array, align 8, !tbaa !5
  %28 = load i32, ptr @max, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = call ptr %22(ptr noundef %26, ptr noundef %27, i64 noundef %29, i64 noundef 4, ptr noundef @cmp_int)
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %35

32:                                               ; preds = %21
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = add i32 %33, 1
  store i32 %34, ptr %6, align 4, !tbaa !9
  br label %38

35:                                               ; preds = %21
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = add i32 %36, 1
  store i32 %37, ptr %7, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %35, %32
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = add i32 %40, 1
  store i32 %41, ptr %5, align 4, !tbaa !9
  br label %17, !llvm.loop !13

42:                                               ; preds = %17
  %43 = call i64 @utime()
  store i64 %43, ptr @end, align 8, !tbaa !11
  %44 = load i64, ptr @best, align 8, !tbaa !11
  %45 = icmp eq i64 %44, 0
  br i1 %45, label %52, label %46

46:                                               ; preds = %42
  %47 = load i64, ptr @end, align 8, !tbaa !11
  %48 = load i64, ptr @start, align 8, !tbaa !11
  %49 = sub nsw i64 %47, %48
  %50 = load i64, ptr @best, align 8, !tbaa !11
  %51 = icmp slt i64 %49, %50
  br i1 %51, label %52, label %56

52:                                               ; preds = %46, %42
  %53 = load i64, ptr @end, align 8, !tbaa !11
  %54 = load i64, ptr @start, align 8, !tbaa !11
  %55 = sub nsw i64 %53, %54
  store i64 %55, ptr @best, align 8, !tbaa !11
  br label %56

56:                                               ; preds = %52, %46
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = add nsw i32 %58, -1
  store i32 %59, ptr %8, align 4, !tbaa !9
  br label %11, !llvm.loop !15

60:                                               ; preds = %14
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = load i32, ptr @max, align 4, !tbaa !9
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = load i32, ptr @checks, align 4, !tbaa !9
  %66 = load i64, ptr @best, align 8, !tbaa !11
  %67 = sitofp i64 %66 to double
  %68 = fdiv double %67, 1.000000e+06
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %61, i32 noundef %62, i32 noundef %63, i32 noundef %64, i32 noundef %65, double noundef %68)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret void
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) #3

declare i32 @printf(ptr noundef, ...) #4

attributes #0 = { noinline 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 = { "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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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"

@checks = external dso_local local_unnamed_addr global i32, align 4
@rnd = external dso_local local_unnamed_addr global i32, align 4
@best = external dso_local local_unnamed_addr global i64, align 8
@runs = external dso_local local_unnamed_addr global i32, align 4
@start = external dso_local local_unnamed_addr global i64, align 8
@loop = external dso_local local_unnamed_addr global i32, align 4
@r_array = external dso_local local_unnamed_addr global ptr, align 8
@o_array = external dso_local local_unnamed_addr global ptr, align 8
@max = external dso_local local_unnamed_addr global i32, align 4
@end = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: noinline nounwind uwtable
declare dso_local i32 @cmp_int(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @utime() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @execute(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = load i32, ptr @rnd, align 4, !tbaa !5
  tail call void @srand(i32 noundef %3) #5
  store i64 0, ptr @best, align 8, !tbaa !9
  %4 = load i32, ptr @runs, align 4, !tbaa !5
  %.not21 = icmp ne i32 %4, 0
  tail call void @llvm.assume(i1 %.not21)
  br label %.lr.ph24

._crit_edge25:                                    ; preds = %27
  %5 = load i32, ptr @max, align 4, !tbaa !5
  %6 = load i32, ptr @checks, align 4, !tbaa !5
  %7 = sitofp i64 %28 to double
  %8 = fdiv double %7, 1.000000e+06
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef %1, i32 noundef %5, i32 noundef %.112.lcssa, i32 noundef %.1.lcssa, i32 noundef %6, double noundef %8)
  ret void

.lr.ph24:                                         ; preds = %2, %27
  %.022 = phi i32 [ %29, %27 ], [ %4, %2 ]
  store i32 0, ptr @checks, align 4, !tbaa !5
  %10 = tail call i64 @utime()
  store i64 %10, ptr @start, align 8, !tbaa !9
  %11 = load i32, ptr @loop, align 4, !tbaa !5
  %.not28 = icmp eq i32 %11, 0
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph24, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph24 ]
  %.119 = phi i32 [ %.2, %.lr.ph ], [ 0, %.lr.ph24 ]
  %.11218 = phi i32 [ %.213, %.lr.ph ], [ 0, %.lr.ph24 ]
  %12 = load ptr, ptr @r_array, align 8, !tbaa !11
  %13 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv
  %14 = load ptr, ptr @o_array, align 8, !tbaa !11
  %15 = load i32, ptr @max, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = tail call ptr %0(ptr noundef %13, ptr noundef %14, i64 noundef %16, i64 noundef 4, ptr noundef nonnull @cmp_int) #5
  %.not16 = icmp ne ptr %17, null
  %18 = zext i1 %.not16 to i32
  %.213 = add i32 %.11218, %18
  %not..not16 = xor i1 %.not16, true
  %19 = zext i1 %not..not16 to i32
  %.2 = add i32 %.119, %19
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i32, ptr @loop, align 4, !tbaa !5
  %21 = zext i32 %20 to i64
  %22 = icmp ult i64 %indvars.iv.next, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph24
  %.112.lcssa = phi i32 [ 0, %.lr.ph24 ], [ %.213, %.lr.ph ]
  %.1.lcssa = phi i32 [ 0, %.lr.ph24 ], [ %.2, %.lr.ph ]
  %23 = tail call i64 @utime()
  store i64 %23, ptr @end, align 8, !tbaa !9
  %24 = load i64, ptr @best, align 8, !tbaa !9
  %25 = icmp eq i64 %24, 0
  %.pre = load i64, ptr @start, align 8, !tbaa !9
  %.pre30 = sub nsw i64 %23, %.pre
  %26 = icmp slt i64 %.pre30, %24
  %or.cond = select i1 %25, i1 true, i1 %26
  br i1 %or.cond, label %._crit_edge._crit_edge, label %27

._crit_edge._crit_edge:                           ; preds = %._crit_edge
  store i64 %.pre30, ptr @best, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %._crit_edge, %._crit_edge._crit_edge
  %28 = phi i64 [ %.pre30, %._crit_edge._crit_edge ], [ %24, %._crit_edge ]
  %29 = add nsw i32 %.022, -1
  %.not = icmp eq i32 %29, 0
  br i1 %.not, label %._crit_edge25, label %.lr.ph24, !llvm.loop !15
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #4

attributes #0 = { noinline 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 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 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
attributes #5 = { 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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass