; LLVM IR from adventure-db/adventure :: tests/db (btree_tests)

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

@s = external hidden global ptr, align 8
@root = external hidden global i64, align 8

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

declare i64 @btree_add(ptr noundef, i64 noundef, i64 noundef, i64 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 uwtable
define dso_local ptr @test_insert_dup() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %15, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 20
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %18

7:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  %8 = load ptr, ptr @s, align 8, !tbaa !9
  %9 = load i64, ptr @root, align 8, !tbaa !11
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = call i64 @btree_add(ptr noundef %8, i64 noundef %9, i64 noundef %11, i64 noundef %13)
  store i64 %14, ptr @root, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %15

15:                                               ; preds = %7
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !13

18:                                               ; preds = %6
  ret ptr null
}

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

!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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@s = external hidden local_unnamed_addr global ptr, align 8
@root = external hidden local_unnamed_addr global i64, align 8

declare i64 @btree_add(ptr noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @test_insert_dup() local_unnamed_addr #1 {
  %1 = load ptr, ptr @s, align 8, !tbaa !5
  %2 = load i64, ptr @root, align 8, !tbaa !9
  %3 = tail call i64 @btree_add(ptr noundef %1, i64 noundef %2, i64 noundef 1, i64 noundef 0) #2
  store i64 %3, ptr @root, align 8, !tbaa !9
  %4 = load ptr, ptr @s, align 8, !tbaa !5
  %5 = tail call i64 @btree_add(ptr noundef %4, i64 noundef %3, i64 noundef 1, i64 noundef 1) #2
  store i64 %5, ptr @root, align 8, !tbaa !9
  %6 = load ptr, ptr @s, align 8, !tbaa !5
  %7 = tail call i64 @btree_add(ptr noundef %6, i64 noundef %5, i64 noundef 1, i64 noundef 2) #2
  store i64 %7, ptr @root, align 8, !tbaa !9
  %8 = load ptr, ptr @s, align 8, !tbaa !5
  %9 = tail call i64 @btree_add(ptr noundef %8, i64 noundef %7, i64 noundef 1, i64 noundef 3) #2
  store i64 %9, ptr @root, align 8, !tbaa !9
  %10 = load ptr, ptr @s, align 8, !tbaa !5
  %11 = tail call i64 @btree_add(ptr noundef %10, i64 noundef %9, i64 noundef 1, i64 noundef 4) #2
  store i64 %11, ptr @root, align 8, !tbaa !9
  %12 = load ptr, ptr @s, align 8, !tbaa !5
  %13 = tail call i64 @btree_add(ptr noundef %12, i64 noundef %11, i64 noundef 1, i64 noundef 5) #2
  store i64 %13, ptr @root, align 8, !tbaa !9
  %14 = load ptr, ptr @s, align 8, !tbaa !5
  %15 = tail call i64 @btree_add(ptr noundef %14, i64 noundef %13, i64 noundef 1, i64 noundef 6) #2
  store i64 %15, ptr @root, align 8, !tbaa !9
  %16 = load ptr, ptr @s, align 8, !tbaa !5
  %17 = tail call i64 @btree_add(ptr noundef %16, i64 noundef %15, i64 noundef 1, i64 noundef 7) #2
  store i64 %17, ptr @root, align 8, !tbaa !9
  %18 = load ptr, ptr @s, align 8, !tbaa !5
  %19 = tail call i64 @btree_add(ptr noundef %18, i64 noundef %17, i64 noundef 1, i64 noundef 8) #2
  store i64 %19, ptr @root, align 8, !tbaa !9
  %20 = load ptr, ptr @s, align 8, !tbaa !5
  %21 = tail call i64 @btree_add(ptr noundef %20, i64 noundef %19, i64 noundef 1, i64 noundef 9) #2
  store i64 %21, ptr @root, align 8, !tbaa !9
  %22 = load ptr, ptr @s, align 8, !tbaa !5
  %23 = tail call i64 @btree_add(ptr noundef %22, i64 noundef %21, i64 noundef 1, i64 noundef 10) #2
  store i64 %23, ptr @root, align 8, !tbaa !9
  %24 = load ptr, ptr @s, align 8, !tbaa !5
  %25 = tail call i64 @btree_add(ptr noundef %24, i64 noundef %23, i64 noundef 1, i64 noundef 11) #2
  store i64 %25, ptr @root, align 8, !tbaa !9
  %26 = load ptr, ptr @s, align 8, !tbaa !5
  %27 = tail call i64 @btree_add(ptr noundef %26, i64 noundef %25, i64 noundef 1, i64 noundef 12) #2
  store i64 %27, ptr @root, align 8, !tbaa !9
  %28 = load ptr, ptr @s, align 8, !tbaa !5
  %29 = tail call i64 @btree_add(ptr noundef %28, i64 noundef %27, i64 noundef 1, i64 noundef 13) #2
  store i64 %29, ptr @root, align 8, !tbaa !9
  %30 = load ptr, ptr @s, align 8, !tbaa !5
  %31 = tail call i64 @btree_add(ptr noundef %30, i64 noundef %29, i64 noundef 1, i64 noundef 14) #2
  store i64 %31, ptr @root, align 8, !tbaa !9
  %32 = load ptr, ptr @s, align 8, !tbaa !5
  %33 = tail call i64 @btree_add(ptr noundef %32, i64 noundef %31, i64 noundef 1, i64 noundef 15) #2
  store i64 %33, ptr @root, align 8, !tbaa !9
  %34 = load ptr, ptr @s, align 8, !tbaa !5
  %35 = tail call i64 @btree_add(ptr noundef %34, i64 noundef %33, i64 noundef 1, i64 noundef 16) #2
  store i64 %35, ptr @root, align 8, !tbaa !9
  %36 = load ptr, ptr @s, align 8, !tbaa !5
  %37 = tail call i64 @btree_add(ptr noundef %36, i64 noundef %35, i64 noundef 1, i64 noundef 17) #2
  store i64 %37, ptr @root, align 8, !tbaa !9
  %38 = load ptr, ptr @s, align 8, !tbaa !5
  %39 = tail call i64 @btree_add(ptr noundef %38, i64 noundef %37, i64 noundef 1, i64 noundef 18) #2
  store i64 %39, ptr @root, align 8, !tbaa !9
  %40 = load ptr, ptr @s, align 8, !tbaa !5
  %41 = tail call i64 @btree_add(ptr noundef %40, i64 noundef %39, i64 noundef 1, i64 noundef 19) #2
  store i64 %41, ptr @root, align 8, !tbaa !9
  ret ptr null
}

attributes #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 }

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


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