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

@cache = external dso_local global %struct.cache_def, align 8
@__const.test_find.V = external hidden unnamed_addr constant [13 x i32], align 16
@__const.test_find.POS_R = external hidden unnamed_addr constant [13 x i32], align 16

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @test_find() #3 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca [13 x i32], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca [13 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %15 = call ptr @simple_cache_init(i32 noundef 5, i32 noundef 1, ptr noundef null)
  store ptr %15, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 52, ptr %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.test_find.V, i64 52, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %31, %0
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 13
  br i1 %18, label %19, label %34

19:                                               ; preds = %16
  %20 = load i32, ptr %2, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  %24 = mul nsw i32 %23, 2
  %25 = getelementptr inbounds [13 x i32], ptr %3, i64 0, i64 0
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %4, align 4, !tbaa !9
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds i32, ptr %25, i64 %28
  %30 = call i32 @bpt_insert_new_value(i32 noundef %20, i32 noundef %21, i32 noundef %24, ptr noundef %29, ptr noundef null, ptr noundef %7, ptr noundef %6, ptr noundef %8)
  store i32 %30, ptr %5, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %19
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %9, align 4, !tbaa !9
  br label %16, !llvm.loop !11

34:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !9
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 52, ptr %14) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %14, ptr align 16 @__const.test_find.POS_R, i64 52, i1 false)
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %71, %34
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = icmp sle i32 %36, 13
  br i1 %37, label %38, label %74

38:                                               ; preds = %35
  %39 = load i32, ptr %2, align 4, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = call i32 @bpt_find(i32 noundef %39, i32 noundef %40, ptr noundef %6, ptr noundef %12, i32 noundef %41)
  store i32 %42, ptr %10, align 4, !tbaa !9
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = srem i32 %43, 2
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %49

46:                                               ; preds = %38
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  call void @UnityAssertEqualNumber(i64 noundef 0, i64 noundef %48, ptr noundef null, i64 noundef 1562, i32 noundef 148)
  br label %70

49:                                               ; preds = %38
  %50 = load ptr, ptr getelementptr inbounds (%struct.cache_def, ptr @cache, i32 0, i32 3), align 8, !tbaa !13
  %51 = load i32, ptr %2, align 4, !tbaa !9
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = sub i32 %52, 1
  %54 = call ptr %50(i32 noundef %51, i32 noundef %53, ptr noundef null)
  store ptr %54, ptr %11, align 8, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = sdiv i32 %55, 2
  %57 = sext i32 %56 to i64
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  call void @UnityAssertEqualNumber(i64 noundef %57, i64 noundef %60, ptr noundef null, i64 noundef 1565, i32 noundef 148)
  %61 = load i32, ptr %13, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [13 x i32], ptr %14, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  call void @UnityAssertEqualNumber(i64 noundef %65, i64 noundef %67, ptr noundef null, i64 noundef 1566, i32 noundef 148)
  %68 = load i32, ptr %13, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %13, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %49, %46
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %9, align 4, !tbaa !9
  br label %35, !llvm.loop !15

74:                                               ; preds = %35
  %75 = load ptr, ptr getelementptr inbounds (%struct.cache_def, ptr @cache, i32 0, i32 6), align 8, !tbaa !16
  call void (...) %75()
  call void @llvm.lifetime.end.p0(i64 52, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 52, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

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

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

!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}


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

@cache = external dso_local local_unnamed_addr global %struct.cache_def, align 8
@__const.test_find.V = external hidden unnamed_addr constant [13 x i32], align 16
@__const.test_find.POS_R = external hidden unnamed_addr constant [13 x i32], align 16

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

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 #2

; Function Attrs: nounwind uwtable
define dso_local void @test_find() local_unnamed_addr #3 {
  %1 = alloca [13 x i32], align 16
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = tail call ptr @simple_cache_init(i32 noundef 5, i32 noundef 1, ptr noundef null) #4
  call void @llvm.lifetime.start.p0(i64 52, ptr nonnull %1) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(52) %1, ptr noundef nonnull align 16 dereferenceable(52) @__const.test_find.V, i64 52, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %7 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef 0, i32 noundef 2, ptr noundef nonnull %1, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %8 = getelementptr inbounds i8, ptr %1, i64 4
  %9 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %7, i32 noundef 4, ptr noundef nonnull %8, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %9, i32 noundef 6, ptr noundef nonnull %10, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %12 = getelementptr inbounds i8, ptr %1, i64 12
  %13 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %11, i32 noundef 8, ptr noundef nonnull %12, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %13, i32 noundef 10, ptr noundef nonnull %14, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %16 = getelementptr inbounds i8, ptr %1, i64 20
  %17 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %15, i32 noundef 12, ptr noundef nonnull %16, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %18 = getelementptr inbounds i8, ptr %1, i64 24
  %19 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %17, i32 noundef 14, ptr noundef nonnull %18, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %20 = getelementptr inbounds i8, ptr %1, i64 28
  %21 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %19, i32 noundef 16, ptr noundef nonnull %20, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %22 = getelementptr inbounds i8, ptr %1, i64 32
  %23 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %21, i32 noundef 18, ptr noundef nonnull %22, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %24 = getelementptr inbounds i8, ptr %1, i64 36
  %25 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %23, i32 noundef 20, ptr noundef nonnull %24, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %26 = getelementptr inbounds i8, ptr %1, i64 40
  %27 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %25, i32 noundef 22, ptr noundef nonnull %26, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %28 = getelementptr inbounds i8, ptr %1, i64 44
  %29 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %27, i32 noundef 24, ptr noundef nonnull %28, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  %30 = getelementptr inbounds i8, ptr %1, i64 48
  %31 = call i32 @bpt_insert_new_value(i32 noundef 0, i32 noundef %29, i32 noundef 26, ptr noundef nonnull %30, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  br label %32

32:                                               ; preds = %0, %52
  %.026 = phi i32 [ 0, %0 ], [ %.1, %52 ]
  %.12125 = phi i32 [ 1, %0 ], [ %53, %52 ]
  %33 = call i32 @bpt_find(i32 noundef 0, i32 noundef %31, ptr noundef nonnull %2, ptr noundef nonnull %5, i32 noundef %.12125) #4
  %34 = and i32 %.12125, 1
  %.not = icmp eq i32 %34, 0
  br i1 %.not, label %37, label %35

35:                                               ; preds = %32
  %36 = zext i32 %33 to i64
  call void @UnityAssertEqualNumber(i64 noundef 0, i64 noundef %36, ptr noundef null, i64 noundef 1562, i32 noundef 148) #4
  br label %52

37:                                               ; preds = %32
  %38 = load ptr, ptr getelementptr inbounds (i8, ptr @cache, i64 24), align 8, !tbaa !5
  %39 = add i32 %33, -1
  %40 = call ptr %38(i32 noundef 0, i32 noundef %39, ptr noundef null) #4
  %41 = lshr exact i32 %.12125, 1
  %42 = zext nneg i32 %41 to i64
  %43 = load i32, ptr %40, align 4, !tbaa !10
  %44 = sext i32 %43 to i64
  call void @UnityAssertEqualNumber(i64 noundef %42, i64 noundef %44, ptr noundef null, i64 noundef 1565, i32 noundef 148) #4
  %45 = sext i32 %.026 to i64
  %46 = getelementptr inbounds [13 x i32], ptr @__const.test_find.POS_R, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !10
  %48 = sext i32 %47 to i64
  %49 = load i32, ptr %5, align 4, !tbaa !10
  %50 = sext i32 %49 to i64
  call void @UnityAssertEqualNumber(i64 noundef %48, i64 noundef %50, ptr noundef null, i64 noundef 1566, i32 noundef 148) #4
  %51 = add nsw i32 %.026, 1
  br label %52

52:                                               ; preds = %35, %37
  %.1 = phi i32 [ %.026, %35 ], [ %51, %37 ]
  %53 = add nuw nsw i32 %.12125, 1
  %exitcond.not = icmp eq i32 %53, 14
  br i1 %exitcond.not, label %54, label %32, !llvm.loop !12

54:                                               ; preds = %52
  %55 = load ptr, ptr getelementptr inbounds (i8, ptr @cache, i64 48), align 8, !tbaa !14
  call void (...) %55() #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 52, ptr nonnull %1) #4
  ret void
}

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

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

!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, !7, i64 24}
!6 = !{!"cache_def", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !7, i64 48}


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