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

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

%class.mem_alloc = type { i8 }
%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 }

@mem_allocator = external global %class.mem_alloc, align 1
@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__._ZN11index_btree9make_nodeEmRP7bt_node = external hidden unnamed_addr constant [48 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [53 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

declare noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1), 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11index_btree9make_nodeEmRP7bt_node(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef 104)
  store ptr %9, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  br label %15

13:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.12, ptr noundef @.str.1, i32 noundef 194, ptr noundef @__PRETTY_FUNCTION__._ZN11index_btree9make_nodeEmRP7bt_node) #5
  unreachable

14:                                               ; No predecessors!
  br label %15

15:                                               ; preds = %14, %12
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.bt_node, ptr %16, i32 0, i32 0
  store ptr null, ptr %17, align 8, !tbaa !11
  %18 = getelementptr inbounds %class.index_btree, ptr %8, i32 0, i32 2
  %19 = load i32, ptr %18, align 8, !tbaa !16
  %20 = sub i32 %19, 1
  %21 = zext i32 %20 to i64
  %22 = mul i64 %21, 8
  %23 = call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef %22)
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.bt_node, ptr %24, i32 0, i32 2
  store ptr %23, ptr %25, align 8, !tbaa !19
  %26 = getelementptr inbounds %class.index_btree, ptr %8, i32 0, i32 2
  %27 = load i32, ptr %26, align 8, !tbaa !16
  %28 = zext i32 %27 to i64
  %29 = mul i64 %28, 8
  %30 = call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef %29)
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.bt_node, ptr %31, i32 0, i32 0
  store ptr %30, ptr %32, align 8, !tbaa !11
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.bt_node, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !19
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %42

37:                                               ; preds = %15
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.bt_node, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = icmp ne ptr %40, null
  br label %42

42:                                               ; preds = %37, %15
  %43 = phi i1 [ false, %15 ], [ %41, %37 ]
  br i1 %43, label %44, label %45

44:                                               ; preds = %42
  br label %47

45:                                               ; preds = %42
  call void @__assert_fail(ptr noundef @.str.13, ptr noundef @.str.1, i32 noundef 198, ptr noundef @__PRETTY_FUNCTION__._ZN11index_btree9make_nodeEmRP7bt_node) #5
  unreachable

46:                                               ; No predecessors!
  br label %47

47:                                               ; preds = %46, %44
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.bt_node, ptr %48, i32 0, i32 1
  store i8 0, ptr %49, align 8, !tbaa !20
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.bt_node, ptr %50, i32 0, i32 4
  store i32 0, ptr %51, align 8, !tbaa !21
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.bt_node, ptr %52, i32 0, i32 3
  store ptr null, ptr %53, align 8, !tbaa !22
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.bt_node, ptr %54, i32 0, i32 5
  store ptr null, ptr %55, align 8, !tbaa !23
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.bt_node, ptr %56, i32 0, i32 6
  store i8 0, ptr %57, align 8, !tbaa !24
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.bt_node, ptr %58, i32 0, i32 8
  store i32 2, ptr %59, align 8, !tbaa !25
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %60, ptr %61, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i32 0
}

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, !6, i64 0}
!12 = !{!"_ZTS7bt_node", !6, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !6, i64 40, !13, i64 48, !7, i64 56, !15, i64 96, !14, i64 100}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTS7latch_t", !7, i64 0}
!16 = !{!17, !14, i64 24}
!17 = !{!"_ZTS11index_btree", !18, i64 0, !10, i64 16, !14, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!18 = !{!"_ZTS10index_base", !6, i64 8}
!19 = !{!12, !6, i64 16}
!20 = !{!12, !13, i64 8}
!21 = !{!12, !14, i64 32}
!22 = !{!12, !6, i64 24}
!23 = !{!12, !6, i64 40}
!24 = !{!12, !13, i64 48}
!25 = !{!12, !15, i64 96}


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

%class.mem_alloc = type { i8 }

@mem_allocator = external global %class.mem_alloc, align 1
@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__._ZN11index_btree9make_nodeEmRP7bt_node = external hidden unnamed_addr constant [48 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [53 x i8], align 1

declare noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1), i64 noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN11index_btree9make_nodeEmRP7bt_node(ptr nocapture noundef nonnull readonly align 8 dereferenceable(56) %0, i64 noundef %1, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %2) local_unnamed_addr #2 align 2 {
  %4 = tail call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef 104)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %6

5:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.1, i32 noundef 194, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN11index_btree9make_nodeEmRP7bt_node) #3
  unreachable

6:                                                ; preds = %3
  store ptr null, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = add i32 %8, -1
  %10 = zext i32 %9 to i64
  %11 = shl nuw nsw i64 %10, 3
  %12 = tail call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef %11)
  %13 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %12, ptr %13, align 8, !tbaa !17
  %14 = load i32, ptr %7, align 8, !tbaa !13
  %15 = zext i32 %14 to i64
  %16 = shl nuw nsw i64 %15, 3
  %17 = tail call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef %16)
  store ptr %17, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %13, align 8, !tbaa !17
  %.not15 = icmp eq ptr %18, null
  %.not16 = icmp eq ptr %17, null
  %or.cond = or i1 %.not16, %.not15
  br i1 %or.cond, label %.critedge, label %19

.critedge:                                        ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.1, i32 noundef 198, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN11index_btree9make_nodeEmRP7bt_node) #3
  unreachable

19:                                               ; preds = %6
  %20 = getelementptr inbounds i8, ptr %4, i64 8
  store i8 0, ptr %20, align 8, !tbaa !18
  %21 = getelementptr inbounds i8, ptr %4, i64 32
  store i32 0, ptr %21, align 8, !tbaa !19
  %22 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr null, ptr %22, align 8, !tbaa !20
  %23 = getelementptr inbounds i8, ptr %4, i64 40
  store ptr null, ptr %23, align 8, !tbaa !21
  %24 = getelementptr inbounds i8, ptr %4, i64 48
  store i8 0, ptr %24, align 8, !tbaa !22
  %25 = getelementptr inbounds i8, ptr %4, i64 96
  store i32 2, ptr %25, align 8, !tbaa !23
  store ptr %4, ptr %2, align 8, !tbaa !24
  ret i32 0
}

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 = { 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 #2 = { 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 #3 = { 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, !7, i64 0}
!6 = !{!"_ZTS7bt_node", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !7, i64 40, !10, i64 48, !8, i64 56, !12, i64 96, !11, i64 100}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"_ZTS7latch_t", !8, i64 0}
!13 = !{!14, !11, i64 24}
!14 = !{!"_ZTS11index_btree", !15, i64 0, !16, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!15 = !{!"_ZTS10index_base", !7, i64 8}
!16 = !{!"long", !8, i64 0}
!17 = !{!6, !7, i64 16}
!18 = !{!6, !10, i64 8}
!19 = !{!6, !11, i64 32}
!20 = !{!6, !7, i64 24}
!21 = !{!6, !7, i64 40}
!22 = !{!6, !10, i64 48}
!23 = !{!6, !12, i64 96}
!24 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass