; LLVM IR from pavlosdais/Abstract-Data-Types :: tests (test_Vector)

; 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.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @acutest_check_(i32 noundef, ptr noundef, i32 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

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

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

; Function Attrs: noreturn nounwind uwtable
declare dso_local void @acutest_abort_() #3

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

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

declare ptr @vector_create(ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

declare void @vector_destroy(ptr noundef) #2

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @create_random_array(i32 noundef) #5

declare void @vector_push_back(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i64 @clock() #4

declare void @vector_sort(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @test_binary_search() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #6
  %8 = call ptr @vector_create(ptr noundef @free)
  store ptr %8, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  %9 = call i64 @time(ptr noundef %2) #6
  %10 = trunc i64 %9 to i32
  call void @srand(i32 noundef %10) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %11 = call ptr @create_random_array(i32 noundef 20000)
  store ptr %11, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %23, %0
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = icmp ult i64 %13, 20000
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  br label %26

16:                                               ; preds = %12
  %17 = load ptr, ptr %1, align 8, !tbaa !5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = getelementptr inbounds i32, ptr %18, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = call ptr @createData(i32 noundef %21)
  call void @vector_push_back(ptr noundef %17, ptr noundef %22)
  br label %23

23:                                               ; preds = %16
  %24 = load i64, ptr %4, align 8, !tbaa !9
  %25 = add i64 %24, 1
  store i64 %25, ptr %4, align 8, !tbaa !9
  br label %12, !llvm.loop !13

26:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %27 = call i64 @clock() #6
  store i64 %27, ptr %5, align 8, !tbaa !9
  %28 = load ptr, ptr %1, align 8, !tbaa !5
  call void @vector_sort(ptr noundef %28, ptr noundef @compareFunction)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %47, %26
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = icmp ult i64 %30, 20000
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %50

33:                                               ; preds = %29
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %1, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load i64, ptr %6, align 8, !tbaa !9
  %38 = getelementptr inbounds i32, ptr %36, i64 %37
  %39 = call zeroext i1 @vector_binary_search(ptr noundef %35, ptr noundef %38, ptr noundef @compareFunction)
  %40 = zext i1 %39 to i32
  %41 = call i32 (i32, ptr, i32, ptr, ...) @acutest_check_(i32 noundef %40, ptr noundef @.str.38, i32 noundef 140, ptr noundef @.str.5, ptr noundef @.str.48)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %34
  call void @acutest_abort_() #7
  unreachable

44:                                               ; preds = %34
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  br label %47

47:                                               ; preds = %46
  %48 = load i64, ptr %6, align 8, !tbaa !9
  %49 = add i64 %48, 1
  store i64 %49, ptr %6, align 8, !tbaa !9
  br label %29, !llvm.loop !15

50:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %51 = call i64 @clock() #6
  %52 = load i64, ptr %5, align 8, !tbaa !9
  %53 = sub nsw i64 %51, %52
  %54 = sitofp i64 %53 to double
  %55 = fdiv double %54, 1.000000e+06
  store double %55, ptr %7, align 8, !tbaa !16
  %56 = load ptr, ptr %1, align 8, !tbaa !5
  call void @vector_destroy(ptr noundef %56)
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %57) #6
  %58 = load double, ptr %7, align 8, !tbaa !16
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.49, double noundef %58)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #6
  ret void
}

declare zeroext i1 @vector_binary_search(ptr noundef, ptr noundef, ptr noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { noreturn 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 #4 = { 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 #5 = { inlinehint 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 #6 = { nounwind }
attributes #7 = { noreturn }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}


; 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.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @acutest_check_(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

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

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

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

; Function Attrs: noreturn nounwind uwtable
declare dso_local void @acutest_abort_() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @createData(i32 noundef) local_unnamed_addr #0

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

declare ptr @vector_create(ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) #5

declare void @vector_destroy(ptr noundef) local_unnamed_addr #4

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @create_random_array(i32 noundef) local_unnamed_addr #7

declare void @vector_push_back(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #6

declare void @vector_sort(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local void @test_binary_search() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = tail call ptr @vector_create(ptr noundef nonnull @free) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #8
  %3 = call i64 @time(ptr noundef nonnull %1) #8
  %4 = trunc i64 %3 to i32
  call void @srand(i32 noundef %4) #8
  %5 = call ptr @create_random_array(i32 noundef 20000)
  br label %8

6:                                                ; preds = %8
  %7 = call i64 @clock() #8
  call void @vector_sort(ptr noundef %2, ptr noundef nonnull @compareFunction) #8
  br label %21

8:                                                ; preds = %0, %8
  %.015 = phi i64 [ 0, %0 ], [ %12, %8 ]
  %9 = getelementptr inbounds i32, ptr %5, i64 %.015
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = call ptr @createData(i32 noundef %10)
  call void @vector_push_back(ptr noundef %2, ptr noundef %11) #8
  %12 = add nuw nsw i64 %.015, 1
  %exitcond.not = icmp eq i64 %12, 20000
  br i1 %exitcond.not, label %6, label %8, !llvm.loop !9

13:                                               ; preds = %21
  %14 = add nuw nsw i64 %.01416, 1
  %exitcond17.not = icmp eq i64 %14, 20000
  br i1 %exitcond17.not, label %15, label %21, !llvm.loop !11

15:                                               ; preds = %13
  %16 = call i64 @clock() #8
  %17 = sub nsw i64 %16, %7
  %18 = sitofp i64 %17 to double
  %19 = fdiv double %18, 1.000000e+06
  call void @vector_destroy(ptr noundef %2) #8
  call void @free(ptr noundef %5) #8
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.49, double noundef %19)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #8
  ret void

21:                                               ; preds = %6, %13
  %.01416 = phi i64 [ 0, %6 ], [ %14, %13 ]
  %22 = getelementptr inbounds i32, ptr %5, i64 %.01416
  %23 = call zeroext i1 @vector_binary_search(ptr noundef %2, ptr noundef %22, ptr noundef nonnull @compareFunction) #8
  %24 = zext i1 %23 to i32
  %25 = call i32 (i32, ptr, i32, ptr, ...) @acutest_check_(i32 noundef %24, ptr noundef nonnull @.str.38, i32 noundef 140, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.48)
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %26, label %13

26:                                               ; preds = %21
  call void @acutest_abort_() #9
  unreachable
}

declare zeroext i1 @vector_binary_search(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { noreturn 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #6 = { 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 #7 = { inlinehint 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 #8 = { nounwind }
attributes #9 = { noreturn }

!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"}
!11 = distinct !{!11, !10}


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