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

; 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 }
%class.index_btree = type { %class.index_base, i64, i32, ptr, ptr, ptr }
%class.index_base = type { ptr, ptr }
%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 }

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__._ZN11index_btree14start_new_treeE10glob_parammP8itemid_t = external hidden unnamed_addr constant [66 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

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

; 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_btree14start_new_treeE10glob_parammP8itemid_t(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 %1, i64 noundef %2, ptr noundef %3) #1 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.glob_param, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = getelementptr inbounds %struct.glob_param, ptr %6, i32 0, i32 0
  store i64 %1, ptr %14, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %16 = getelementptr inbounds %struct.glob_param, ptr %6, i32 0, i32 0
  %17 = load i64, ptr %16, align 8, !tbaa !11
  store i64 %17, ptr %11, align 8, !tbaa !9
  %18 = load i64, ptr %11, align 8, !tbaa !9
  %19 = getelementptr inbounds %class.index_btree, ptr %15, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load i64, ptr %11, align 8, !tbaa !9
  %22 = getelementptr inbounds %class.index_btree, ptr %15, i32 0, i32 1
  %23 = load i64, ptr %22, align 8, !tbaa !17
  %24 = urem i64 %21, %23
  %25 = getelementptr inbounds ptr, ptr %20, i64 %24
  %26 = call noundef i32 @_ZN11index_btree7make_lfEmRP7bt_node(ptr noundef nonnull align 8 dereferenceable(56) %15, i64 noundef %18, ptr noundef nonnull align 8 dereferenceable(8) %25)
  store i32 %26, ptr %10, align 4, !tbaa !18
  %27 = load i32, ptr %10, align 4, !tbaa !18
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %4
  %30 = load i32, ptr %10, align 4, !tbaa !18
  store i32 %30, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %62

31:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %32 = getelementptr inbounds %class.index_btree, ptr %15, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load i64, ptr %11, align 8, !tbaa !9
  %35 = getelementptr inbounds %class.index_btree, ptr %15, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !17
  %37 = urem i64 %34, %36
  %38 = getelementptr inbounds ptr, ptr %33, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  store ptr %39, ptr %13, align 8, !tbaa !5
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %43

42:                                               ; preds = %31
  br label %45

43:                                               ; preds = %31
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.1, i32 noundef 217, ptr noundef @__PRETTY_FUNCTION__._ZN11index_btree14start_new_treeE10glob_parammP8itemid_t) #4
  unreachable

44:                                               ; No predecessors!
  br label %45

45:                                               ; preds = %44, %42
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.bt_node, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !20
  %50 = getelementptr inbounds i64, ptr %49, i64 0
  store i64 %46, ptr %50, align 8, !tbaa !9
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %13, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.bt_node, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !24
  %55 = getelementptr inbounds ptr, ptr %54, i64 0
  store ptr %51, ptr %55, align 8, !tbaa !5
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.bt_node, ptr %56, i32 0, i32 3
  store ptr null, ptr %57, align 8, !tbaa !25
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.bt_node, ptr %58, i32 0, i32 4
  %60 = load i32, ptr %59, align 8, !tbaa !26
  %61 = add i32 %60, 1
  store i32 %61, ptr %59, align 8, !tbaa !26
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %62

62:                                               ; preds = %45, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %63 = load i32, ptr %5, align 4
  ret i32 %63
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nounwind }
attributes #4 = { 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, !6, i64 32}
!14 = !{!"_ZTS11index_btree", !15, i64 0, !10, i64 16, !16, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!15 = !{!"_ZTS10index_base", !6, i64 8}
!16 = !{!"int", !7, i64 0}
!17 = !{!14, !10, i64 16}
!18 = !{!19, !19, i64 0}
!19 = !{!"_ZTS2RC", !7, i64 0}
!20 = !{!21, !6, i64 16}
!21 = !{!"_ZTS7bt_node", !6, i64 0, !22, i64 8, !6, i64 16, !6, i64 24, !16, i64 32, !6, i64 40, !22, i64 48, !7, i64 56, !23, i64 96, !16, i64 100}
!22 = !{!"bool", !7, i64 0}
!23 = !{!"_ZTS7latch_t", !7, i64 0}
!24 = !{!21, !6, i64 0}
!25 = !{!21, !6, i64 24}
!26 = !{!21, !16, 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.10 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__._ZN11index_btree14start_new_treeE10glob_parammP8itemid_t = external hidden unnamed_addr constant [66 x i8], align 1

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

; 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_btree14start_new_treeE10glob_parammP8itemid_t(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i64, ptr %7, align 8, !tbaa !13
  %9 = urem i64 %1, %8
  %10 = getelementptr inbounds ptr, ptr %6, i64 %9
  %11 = tail call noundef i32 @_ZN11index_btree7make_lfEmRP7bt_node(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %27

12:                                               ; preds = %4
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load i64, ptr %7, align 8, !tbaa !13
  %15 = urem i64 %1, %14
  %16 = getelementptr inbounds ptr, ptr %13, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %.not15 = icmp eq ptr %17, null
  br i1 %.not15, label %18, label %19

18:                                               ; preds = %12
  tail call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.1, i32 noundef 217, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN11index_btree14start_new_treeE10glob_parammP8itemid_t) #2
  unreachable

19:                                               ; preds = %12
  %20 = getelementptr inbounds i8, ptr %17, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  store i64 %2, ptr %21, align 8, !tbaa !19
  %22 = load ptr, ptr %17, align 8, !tbaa !20
  store ptr %3, ptr %22, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %17, i64 24
  store ptr null, ptr %23, align 8, !tbaa !21
  %24 = getelementptr inbounds i8, ptr %17, i64 32
  %25 = load i32, ptr %24, align 8, !tbaa !22
  %26 = add i32 %25, 1
  store i32 %26, ptr %24, align 8, !tbaa !22
  br label %27

27:                                               ; preds = %4, %19
  ret i32 %11
}

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


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