; LLVM IR from ryanlayer/giggle :: test/unit (test_bpt)

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

%struct.cache_def = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@ORDER = external dso_local global i32, align 4
@cache = external dso_local global %struct.cache_def, align 8
@bpt_node_repair = external dso_local global ptr, align 8

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

declare void @UnityAssertEqualNumber(i64 noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef) #1

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

declare ptr @simple_cache_init(i32 noundef, i32 noundef, ptr noundef) #1

declare i32 @bpt_insert_new_value(i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @bpt_find(i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @test_rand_test() #4 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  store ptr null, ptr @bpt_node_repair, align 8, !tbaa !5
  store i32 10, ptr @ORDER, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  %16 = call ptr @simple_cache_init(i32 noundef 5, i32 noundef 1, ptr noundef null)
  store ptr %16, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #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
  store i32 1000, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = mul i64 %18, 4
  %20 = call noalias ptr @malloc(i64 noundef %19) #6
  store ptr %20, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = mul i64 %22, 4
  %24 = call noalias ptr @malloc(i64 noundef %23) #6
  store ptr %24, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %25 = call i64 @time(ptr noundef null) #5
  store i64 %25, ptr %10, align 8, !tbaa !11
  %26 = load i64, ptr %10, align 8, !tbaa !11
  %27 = trunc i64 %26 to i32
  call void @srand(i32 noundef %27) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %61, %0
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp ult i32 %29, %30
  br i1 %31, label %32, label %64

32:                                               ; preds = %28
  %33 = call i32 @rand() #5
  %34 = srem i32 %33, 100000
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %35, i64 %37
  store i32 %34, ptr %38, align 4, !tbaa !9
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %39, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = udiv i32 %43, 2
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %45, i64 %47
  store i32 %44, ptr %48, align 4, !tbaa !9
  %49 = load i32, ptr %2, align 4, !tbaa !9
  %50 = load i32, ptr %3, align 4, !tbaa !9
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %51, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %56, i64 %58
  %60 = call i32 @bpt_insert_new_value(i32 noundef %49, i32 noundef %50, i32 noundef %55, ptr noundef %59, ptr noundef null, ptr noundef %5, ptr noundef %4, ptr noundef %6)
  store i32 %60, ptr %3, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %32
  %62 = load i32, ptr %11, align 4, !tbaa !9
  %63 = add i32 %62, 1
  store i32 %63, ptr %11, align 4, !tbaa !9
  br label %28, !llvm.loop !13

64:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %93, %64
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = icmp ult i32 %66, %67
  br i1 %68, label %69, label %96

69:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %70 = load i32, ptr %2, align 4, !tbaa !9
  %71 = load i32, ptr %3, align 4, !tbaa !9
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load i32, ptr %11, align 4, !tbaa !9
  %74 = zext i32 %73 to i64
  %75 = getelementptr inbounds i32, ptr %72, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = call i32 @bpt_find(i32 noundef %70, i32 noundef %71, ptr noundef %4, ptr noundef %13, i32 noundef %76)
  store i32 %77, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %78 = load ptr, ptr getelementptr inbounds (%struct.cache_def, ptr @cache, i32 0, i32 3), align 8, !tbaa !15
  %79 = load i32, ptr %2, align 4, !tbaa !9
  %80 = load i32, ptr %14, align 4, !tbaa !9
  %81 = sub i32 %80, 1
  %82 = call ptr %78(i32 noundef %79, i32 noundef %81, ptr noundef null)
  store ptr %82, ptr %15, align 8, !tbaa !5
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = load i32, ptr %11, align 4, !tbaa !9
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds i32, ptr %83, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = udiv i32 %87, 2
  %89 = zext i32 %88 to i64
  %90 = load ptr, ptr %15, align 8, !tbaa !5
  %91 = load i32, ptr %90, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  call void @UnityAssertEqualNumber(i64 noundef %89, i64 noundef %92, ptr noundef null, i64 noundef 1754, i32 noundef 148)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %93

93:                                               ; preds = %69
  %94 = load i32, ptr %11, align 4, !tbaa !9
  %95 = add i32 %94, 1
  store i32 %95, ptr %11, align 4, !tbaa !9
  br label %65, !llvm.loop !17

96:                                               ; preds = %65
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %97) #5
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %98) #5
  %99 = load ptr, ptr getelementptr inbounds (%struct.cache_def, ptr @cache, i32 0, i32 6), align 8, !tbaa !18
  call void (...) %99()
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  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
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret void
}

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

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

; Function Attrs: nounwind
declare i32 @rand() #3

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

!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", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 24}
!16 = !{!"cache_def", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!17 = distinct !{!17, !14}
!18 = !{!16, !6, i64 48}


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

%struct.cache_def = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@ORDER = external dso_local local_unnamed_addr global i32, align 4
@cache = external dso_local local_unnamed_addr global %struct.cache_def, align 8
@bpt_node_repair = external dso_local local_unnamed_addr global ptr, align 8

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

declare void @UnityAssertEqualNumber(i64 noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef) 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) #0

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

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

declare ptr @simple_cache_init(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @bpt_insert_new_value(i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @bpt_find(i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @test_rand_test() local_unnamed_addr #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr null, ptr @bpt_node_repair, align 8, !tbaa !5
  store i32 10, ptr @ORDER, align 4, !tbaa !9
  %5 = tail call ptr @simple_cache_init(i32 noundef 5, i32 noundef 1, ptr noundef null) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  %6 = tail call noalias dereferenceable_or_null(4000) ptr @malloc(i64 noundef 4000) #7
  %7 = tail call noalias dereferenceable_or_null(4000) ptr @malloc(i64 noundef 4000) #7
  %8 = tail call i64 @time(ptr noundef null) #6
  %9 = trunc i64 %8 to i32
  tail call void @srand(i32 noundef %9) #6
  br label %10

10:                                               ; preds = %0, %10
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %10 ]
  %.033 = phi i32 [ 0, %0 ], [ %16, %10 ]
  %11 = call i32 @rand() #6
  %12 = srem i32 %11, 100000
  %13 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv
  store i32 %12, ptr %13, align 4, !tbaa !9
  %14 = lshr i32 %12, 1
  %15 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv
  store i32 %14, ptr %15, align 4, !tbaa !9
  %16 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %.033, i32 noundef %12, ptr noundef nonnull %15, ptr noundef null, ptr noundef nonnull %2, ptr noundef nonnull %1, ptr noundef nonnull %3) #6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1000
  br i1 %exitcond.not, label %17, label %10, !llvm.loop !11

17:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  br label %18

18:                                               ; preds = %17, %18
  %indvars.iv36 = phi i64 [ 0, %17 ], [ %indvars.iv.next37, %18 ]
  %19 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv36
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = call i32 @bpt_find(i32 noundef 0, i32 noundef %16, ptr noundef nonnull %1, ptr noundef nonnull %4, i32 noundef %20) #6
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @cache, i64 24), align 8, !tbaa !13
  %23 = add i32 %21, -1
  %24 = call ptr %22(i32 noundef 0, i32 noundef %23, ptr noundef null) #6
  %25 = lshr i32 %20, 1
  %26 = zext nneg i32 %25 to i64
  %27 = load i32, ptr %24, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  call void @UnityAssertEqualNumber(i64 noundef %26, i64 noundef %28, ptr noundef null, i64 noundef 1754, i32 noundef 148) #6
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next37, 1000
  br i1 %exitcond39.not, label %29, label %18, !llvm.loop !15

29:                                               ; preds = %18
  call void @free(ptr noundef nonnull %6) #6
  call void @free(ptr noundef %7) #6
  %30 = load ptr, ptr getelementptr inbounds (i8, ptr @cache, i64 48), align 8, !tbaa !16
  call void (...) %30() #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret void
}

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

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

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #5

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

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 24}
!14 = !{!"cache_def", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!15 = distinct !{!15, !12}
!16 = !{!14, !6, i64 48}


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