; 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: nounwind uwtable
define dso_local ptr @test_insert_seq() #0 {
  %1 = 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 %2

2:                                                ; preds = %14, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 10
  br i1 %4, label %6, label %5

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

6:                                                ; preds = %2
  %7 = load ptr, ptr @s, align 8, !tbaa !9
  %8 = load i64, ptr @root, align 8, !tbaa !11
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = call i64 @btree_add(ptr noundef %7, i64 noundef %8, i64 noundef %10, i64 noundef %12)
  store i64 %13, ptr @root, align 8, !tbaa !11
  br label %14

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

17:                                               ; preds = %5
  ret ptr null
}

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

declare i64 @btree_add(ptr noundef, i64 noundef, i64 noundef, i64 noundef) #2

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

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 = { 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

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @test_insert_seq() local_unnamed_addr #0 {
  %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 0, 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 2, 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 3, 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 4, 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 5, 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 6, 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 7, 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 8, 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 9, i64 noundef 9) #2
  store i64 %21, ptr @root, align 8, !tbaa !9
  ret ptr null
}

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

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 = { "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