; LLVM IR from mitdbg/deneva :: storage/index_btree.ll (ZN11index_btree20insert_into_new_rootE10glob_paramP7bt_nodemS2_)

; 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.glob_param = type { i64 }
%struct.bt_node = type { ptr, i8, ptr, ptr, i32, ptr, i8, %union.pthread_mutex_t, i32, i32 }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%class.index_btree = type { %class.index_base, i64, i32, ptr, ptr, ptr }
%class.index_base = type { ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [36 x i8], align 1
@stdout = external global ptr, align 8
@.str.18 = external hidden unnamed_addr constant [22 x i8], align 1

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

declare i32 @fflush(ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11index_btree7make_nlEmRP7bt_node(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef, ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11index_btree20insert_into_new_rootE10glob_paramP7bt_nodemS2_(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #3 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca %struct.glob_param, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = getelementptr inbounds %struct.glob_param, ptr %7, i32 0, i32 0
  store i64 %1, ptr %16, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %18 = getelementptr inbounds %struct.glob_param, ptr %7, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !11
  store i64 %19, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %20 = load i64, ptr %13, align 8, !tbaa !9
  %21 = call noundef i32 @_ZN11index_btree7make_nlEmRP7bt_node(ptr noundef nonnull align 8 dereferenceable(56) %17, i64 noundef %20, ptr noundef nonnull align 8 dereferenceable(8) %14)
  store i32 %21, ptr %12, align 4, !tbaa !13
  %22 = load i32, ptr %12, align 4, !tbaa !13
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %5
  %25 = load i32, ptr %12, align 4, !tbaa !13
  store i32 %25, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %73

26:                                               ; preds = %5
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = load ptr, ptr %14, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.bt_node, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = getelementptr inbounds i64, ptr %30, i64 0
  store i64 %27, ptr %31, align 8, !tbaa !9
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = load ptr, ptr %14, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.bt_node, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  %36 = getelementptr inbounds ptr, ptr %35, i64 0
  store ptr %32, ptr %36, align 8, !tbaa !5
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = load ptr, ptr %14, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.bt_node, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !20
  %41 = getelementptr inbounds ptr, ptr %40, i64 1
  store ptr %37, ptr %41, align 8, !tbaa !5
  %42 = load ptr, ptr %14, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.bt_node, ptr %42, i32 0, i32 4
  %44 = load i32, ptr %43, align 8, !tbaa !21
  %45 = add i32 %44, 1
  store i32 %45, ptr %43, align 8, !tbaa !21
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.bt_node, ptr %46, i32 0, i32 4
  %48 = load i32, ptr %47, align 8, !tbaa !21
  %49 = getelementptr inbounds %class.index_btree, ptr %17, i32 0, i32 2
  %50 = load i32, ptr %49, align 8, !tbaa !22
  %51 = icmp ult i32 %48, %50
  br i1 %51, label %56, label %52

52:                                               ; preds = %26
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 541, ptr noundef @.str.18)
  %54 = load ptr, ptr @stdout, align 8, !tbaa !5
  %55 = call i32 @fflush(ptr noundef %54)
  call void @exit(i32 noundef 0) #5
  unreachable

56:                                               ; preds = %26
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.bt_node, ptr %57, i32 0, i32 3
  store ptr null, ptr %58, align 8, !tbaa !25
  %59 = load ptr, ptr %14, align 8, !tbaa !5
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.bt_node, ptr %60, i32 0, i32 3
  store ptr %59, ptr %61, align 8, !tbaa !25
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.bt_node, ptr %63, i32 0, i32 3
  store ptr %62, ptr %64, align 8, !tbaa !25
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.bt_node, ptr %66, i32 0, i32 5
  store ptr %65, ptr %67, align 8, !tbaa !26
  %68 = load ptr, ptr %14, align 8, !tbaa !5
  %69 = getelementptr inbounds %class.index_btree, ptr %17, i32 0, i32 3
  %70 = load ptr, ptr %69, align 8, !tbaa !27
  %71 = load i64, ptr %13, align 8, !tbaa !9
  %72 = getelementptr inbounds ptr, ptr %70, i64 %71
  store ptr %68, ptr %72, align 8, !tbaa !5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %73

73:                                               ; preds = %56, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %74 = load i32, ptr %6, align 4
  ret i32 %74
}

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 = { noreturn 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 = { mustprogress 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 }
attributes #5 = { noreturn 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS10glob_param", !10, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_ZTS2RC", !7, i64 0}
!15 = !{!16, !6, i64 16}
!16 = !{!"_ZTS7bt_node", !6, i64 0, !17, i64 8, !6, i64 16, !6, i64 24, !18, i64 32, !6, i64 40, !17, i64 48, !7, i64 56, !19, i64 96, !18, i64 100}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!"_ZTS7latch_t", !7, i64 0}
!20 = !{!16, !6, i64 0}
!21 = !{!16, !18, i64 32}
!22 = !{!23, !18, i64 24}
!23 = !{!"_ZTS11index_btree", !24, i64 0, !10, i64 16, !18, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!24 = !{!"_ZTS10index_base", !6, i64 8}
!25 = !{!16, !6, i64 24}
!26 = !{!16, !6, i64 40}
!27 = !{!23, !6, i64 32}


; 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.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [36 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.18 = external hidden unnamed_addr constant [22 x i8], align 1

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN11index_btree7make_nlEmRP7bt_node(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11index_btree20insert_into_new_rootE10glob_paramP7bt_nodemS2_(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #3 align 2 {
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %7 = call noundef i32 @_ZN11index_btree7make_nlEmRP7bt_node(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %34

8:                                                ; preds = %5
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store i64 %3, ptr %11, align 8, !tbaa !14
  %12 = load ptr, ptr %9, align 8, !tbaa !16
  store ptr %2, ptr %12, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr %4, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %13, i64 32
  %17 = load i32, ptr %16, align 8, !tbaa !17
  %18 = add i32 %17, 1
  store i32 %18, ptr %16, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  %20 = load i32, ptr %19, align 8, !tbaa !18
  %21 = icmp ult i32 %18, %20
  br i1 %21, label %26, label %22

22:                                               ; preds = %8
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef nonnull @.str.1, i32 noundef 541, ptr noundef nonnull @.str.18)
  %24 = load ptr, ptr @stdout, align 8, !tbaa !5
  %25 = call i32 @fflush(ptr noundef %24)
  call void @exit(i32 noundef 0) #5
  unreachable

26:                                               ; preds = %8
  %27 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr null, ptr %27, align 8, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr %13, ptr %28, align 8, !tbaa !21
  %29 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr %13, ptr %29, align 8, !tbaa !21
  %30 = getelementptr inbounds i8, ptr %2, i64 40
  store ptr %4, ptr %30, align 8, !tbaa !22
  %31 = getelementptr inbounds i8, ptr %0, i64 32
  %32 = load ptr, ptr %31, align 8, !tbaa !23
  %33 = getelementptr inbounds ptr, ptr %32, i64 %1
  store ptr %13, ptr %33, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %5, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  ret i32 %7
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { noreturn 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 = { mustprogress 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 }
attributes #5 = { noreturn 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++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"_ZTS7bt_node", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !6, i64 40, !11, i64 48, !7, i64 56, !13, i64 96, !12, i64 100}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS7latch_t", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!10, !6, i64 0}
!17 = !{!10, !12, i64 32}
!18 = !{!19, !12, i64 24}
!19 = !{!"_ZTS11index_btree", !20, i64 0, !15, i64 16, !12, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!20 = !{!"_ZTS10index_base", !6, i64 8}
!21 = !{!10, !6, i64 24}
!22 = !{!10, !6, i64 40}
!23 = !{!19, !6, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass