; LLVM IR from seppo0010/rlite :: src (page_btree)

; 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.rl_btree = type { ptr, i64, i64, ptr, i64, i64 }
%struct.rlite = type { i64, i64, i32, ptr, i64, i64, i64, ptr, i32, i32, i32, i32, ptr, i64, i64, ptr, i64, i64, ptr, ptr, ptr, ptr }
%struct.rl_btree_node = type { ptr, ptr, ptr, i64 }
%struct.rl_btree_type = type { ptr, ptr, i32, i32, ptr }

; 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_btree_node_create(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_btree_create_size(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store ptr null, ptr %11, align 8, !tbaa !5
  %12 = call noalias ptr @malloc(i64 noundef 48) #5
  store ptr %12, ptr %10, align 8, !tbaa !5
  %13 = load ptr, ptr %10, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %4
  store i32 4, ptr %9, align 4, !tbaa !11
  br label %59

16:                                               ; preds = %4
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.rl_btree, ptr %17, i32 0, i32 5
  store i64 0, ptr %18, align 8, !tbaa !13
  %19 = load i64, ptr %8, align 8, !tbaa !9
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.rl_btree, ptr %20, i32 0, i32 1
  store i64 %19, ptr %21, align 8, !tbaa !15
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.rl_btree, ptr %23, i32 0, i32 3
  store ptr %22, ptr %24, align 8, !tbaa !16
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.rl_btree, ptr %26, i32 0, i32 0
  store ptr %25, ptr %27, align 8, !tbaa !17
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.rlite, ptr %28, i32 0, i32 5
  %30 = load i64, ptr %29, align 8, !tbaa !18
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.rl_btree, ptr %31, i32 0, i32 4
  store i64 %30, ptr %32, align 8, !tbaa !20
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.rl_btree, ptr %33, i32 0, i32 2
  store i64 1, ptr %34, align 8, !tbaa !21
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = call i32 @rl_btree_node_create(ptr noundef %35, ptr noundef %36, ptr noundef %11)
  store i32 %37, ptr %9, align 4, !tbaa !11
  %38 = load i32, ptr %9, align 4, !tbaa !11
  %39 = icmp ne i32 0, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %16
  br label %59

41:                                               ; preds = %16
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rl_btree_node, ptr %42, i32 0, i32 3
  store i64 0, ptr %43, align 8, !tbaa !22
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.rl_btree_type, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !24
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.rlite, ptr %48, i32 0, i32 5
  %50 = load i64, ptr %49, align 8, !tbaa !18
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = call i32 @rl_write(ptr noundef %44, ptr noundef %47, i64 noundef %50, ptr noundef %51)
  store i32 %52, ptr %9, align 4, !tbaa !11
  %53 = load i32, ptr %9, align 4, !tbaa !11
  %54 = icmp ne i32 0, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %41
  br label %59

56:                                               ; preds = %41
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %57, ptr %58, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %59

59:                                               ; preds = %56, %55, %40, %15
  %60 = load i32, ptr %9, align 4, !tbaa !11
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %66

62:                                               ; preds = %59
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = call i32 @rl_btree_destroy(ptr noundef %63, ptr noundef %64)
  br label %66

66:                                               ; preds = %62, %59
  %67 = load i32, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 %67
}

declare i32 @rl_write(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_btree_destroy(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 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 = { "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 = { nounwind allocsize(0) }

!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}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 40}
!14 = !{!"rl_btree", !6, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !10, i64 40}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !6, i64 24}
!17 = !{!14, !6, i64 0}
!18 = !{!19, !10, i64 40}
!19 = !{!"rlite", !10, i64 0, !10, i64 8, !12, i64 16, !6, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !6, i64 80, !10, i64 88, !10, i64 96, !6, i64 104, !10, i64 112, !10, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!20 = !{!14, !10, i64 32}
!21 = !{!14, !10, i64 16}
!22 = !{!23, !10, i64 24}
!23 = !{!"rl_btree_node", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!24 = !{!25, !6, i64 8}
!25 = !{!"", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !6, i64 24}


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

; 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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_btree_node_create(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_btree_create_size(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store ptr null, ptr %5, align 8, !tbaa !5
  %6 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %24, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %6, i64 40
  store i64 0, ptr %8, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 %3, ptr %9, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr %2, ptr %10, align 8, !tbaa !13
  store ptr %0, ptr %6, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = load i64, ptr %11, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %6, i64 32
  store i64 %12, ptr %13, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %6, i64 16
  store i64 1, ptr %14, align 8, !tbaa !19
  %15 = call i32 @rl_btree_node_create(ptr noundef %0, ptr noundef nonnull %6, ptr noundef nonnull %5)
  %.not26 = icmp eq i32 %15, 0
  br i1 %.not26, label %16, label %24

16:                                               ; preds = %7
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 24
  store i64 0, ptr %18, align 8, !tbaa !20
  %19 = getelementptr inbounds i8, ptr %2, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !22
  %21 = load i64, ptr %11, align 8, !tbaa !15
  %22 = call i32 @rl_write(ptr noundef nonnull %0, ptr noundef %20, i64 noundef %21, ptr noundef %17) #4
  %.not27 = icmp eq i32 %22, 0
  br i1 %.not27, label %23, label %24

23:                                               ; preds = %16
  store ptr %6, ptr %1, align 8, !tbaa !5
  br label %26

24:                                               ; preds = %7, %16, %4
  %.0.ph = phi i32 [ 4, %4 ], [ %22, %16 ], [ %15, %7 ]
  %25 = call i32 @rl_btree_destroy(ptr noundef %0, ptr noundef %6)
  br label %26

26:                                               ; preds = %23, %24
  %.032 = phi i32 [ %.0.ph, %24 ], [ 0, %23 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i32 %.032
}

declare i32 @rl_write(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_btree_destroy(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 = { nounwind allocsize(0) }

!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, !11, i64 40}
!10 = !{!"rl_btree", !6, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !11, i64 32, !11, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !6, i64 24}
!14 = !{!10, !6, i64 0}
!15 = !{!16, !11, i64 40}
!16 = !{!"rlite", !11, i64 0, !11, i64 8, !17, i64 16, !6, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !6, i64 56, !17, i64 64, !17, i64 68, !17, i64 72, !17, i64 76, !6, i64 80, !11, i64 88, !11, i64 96, !6, i64 104, !11, i64 112, !11, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!17 = !{!"int", !7, i64 0}
!18 = !{!10, !11, i64 32}
!19 = !{!10, !11, i64 16}
!20 = !{!21, !11, i64 24}
!21 = !{!"rl_btree_node", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!22 = !{!23, !6, i64 8}
!23 = !{!"", !6, i64 0, !6, i64 8, !17, i64 16, !17, i64 20, !6, i64 24}


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