; 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.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
declare void @free(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_btree_update_element(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #4 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = 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 ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.rl_btree, ptr %15, i32 0, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = mul i64 8, %17
  %19 = call noalias ptr @malloc(i64 noundef %18) #6
  store ptr %19, ptr %11, align 8, !tbaa !5
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %4
  store i32 4, ptr %9, align 4, !tbaa !12
  br label %129

23:                                               ; preds = %4
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.rl_btree, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !9
  %27 = mul i64 8, %26
  %28 = call noalias ptr @malloc(i64 noundef %27) #6
  store ptr %28, ptr %10, align 8, !tbaa !5
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %23
  store i32 4, ptr %9, align 4, !tbaa !12
  br label %129

32:                                               ; preds = %23
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = call i32 @rl_btree_find_score(ptr noundef %33, ptr noundef %34, ptr noundef %35, ptr noundef null, ptr noundef %36, ptr noundef %37)
  store i32 %38, ptr %9, align 4, !tbaa !12
  %39 = load i32, ptr %9, align 4, !tbaa !12
  %40 = icmp ne i32 2, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %32
  br label %129

42:                                               ; preds = %32
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.rl_btree, ptr %43, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = sub nsw i64 %45, 1
  store i64 %46, ptr %12, align 8, !tbaa !14
  br label %47

47:                                               ; preds = %125, %42
  %48 = load i64, ptr %12, align 8, !tbaa !14
  %49 = icmp sge i64 %48, 0
  br i1 %49, label %50, label %128

50:                                               ; preds = %47
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = load i64, ptr %12, align 8, !tbaa !14
  %53 = getelementptr inbounds ptr, ptr %51, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  store ptr %54, ptr %14, align 8, !tbaa !5
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %58, label %57

57:                                               ; preds = %50
  br label %125

58:                                               ; preds = %50
  %59 = load i64, ptr %12, align 8, !tbaa !14
  %60 = icmp eq i64 %59, 0
  br i1 %60, label %61, label %65

61:                                               ; preds = %58
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.rl_btree, ptr %62, i32 0, i32 4
  %64 = load i64, ptr %63, align 8, !tbaa !15
  store i64 %64, ptr %13, align 8, !tbaa !14
  br label %80

65:                                               ; preds = %58
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = load i64, ptr %12, align 8, !tbaa !14
  %68 = sub nsw i64 %67, 1
  %69 = getelementptr inbounds ptr, ptr %66, i64 %68
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.rl_btree_node, ptr %70, i32 0, i32 1
  %72 = load ptr, ptr %71, align 8, !tbaa !16
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = load i64, ptr %12, align 8, !tbaa !14
  %75 = sub nsw i64 %74, 1
  %76 = getelementptr inbounds i64, ptr %73, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !14
  %78 = getelementptr inbounds i64, ptr %72, i64 %77
  %79 = load i64, ptr %78, align 8, !tbaa !14
  store i64 %79, ptr %13, align 8, !tbaa !14
  br label %80

80:                                               ; preds = %65, %61
  %81 = load ptr, ptr %14, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.rl_btree_node, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !18
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = load i64, ptr %12, align 8, !tbaa !14
  %86 = getelementptr inbounds i64, ptr %84, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !14
  %88 = getelementptr inbounds ptr, ptr %83, i64 %87
  %89 = load ptr, ptr %88, align 8, !tbaa !5
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = icmp ne ptr %89, %90
  br i1 %91, label %92, label %111

92:                                               ; preds = %80
  %93 = load ptr, ptr %14, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.rl_btree_node, ptr %93, i32 0, i32 2
  %95 = load ptr, ptr %94, align 8, !tbaa !18
  %96 = load ptr, ptr %10, align 8, !tbaa !5
  %97 = load i64, ptr %12, align 8, !tbaa !14
  %98 = getelementptr inbounds i64, ptr %96, i64 %97
  %99 = load i64, ptr %98, align 8, !tbaa !14
  %100 = getelementptr inbounds ptr, ptr %95, i64 %99
  %101 = load ptr, ptr %100, align 8, !tbaa !5
  call void @free(ptr noundef %101) #5
  %102 = load ptr, ptr %8, align 8, !tbaa !5
  %103 = load ptr, ptr %14, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.rl_btree_node, ptr %103, i32 0, i32 2
  %105 = load ptr, ptr %104, align 8, !tbaa !18
  %106 = load ptr, ptr %10, align 8, !tbaa !5
  %107 = load i64, ptr %12, align 8, !tbaa !14
  %108 = getelementptr inbounds i64, ptr %106, i64 %107
  %109 = load i64, ptr %108, align 8, !tbaa !14
  %110 = getelementptr inbounds ptr, ptr %105, i64 %109
  store ptr %102, ptr %110, align 8, !tbaa !5
  br label %111

111:                                              ; preds = %92, %80
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.rl_btree, ptr %113, i32 0, i32 3
  %115 = load ptr, ptr %114, align 8, !tbaa !19
  %116 = getelementptr inbounds %struct.rl_btree_type, ptr %115, i32 0, i32 1
  %117 = load ptr, ptr %116, align 8, !tbaa !20
  %118 = load i64, ptr %13, align 8, !tbaa !14
  %119 = load ptr, ptr %14, align 8, !tbaa !5
  %120 = call i32 @rl_write(ptr noundef %112, ptr noundef %117, i64 noundef %118, ptr noundef %119)
  store i32 %120, ptr %9, align 4, !tbaa !12
  %121 = load i32, ptr %9, align 4, !tbaa !12
  %122 = icmp ne i32 0, %121
  br i1 %122, label %123, label %124

123:                                              ; preds = %111
  br label %129

124:                                              ; preds = %111
  br label %128

125:                                              ; preds = %57
  %126 = load i64, ptr %12, align 8, !tbaa !14
  %127 = add nsw i64 %126, -1
  store i64 %127, ptr %12, align 8, !tbaa !14
  br label %47, !llvm.loop !22

128:                                              ; preds = %124, %47
  br label %129

129:                                              ; preds = %128, %123, %41, %31, %22
  %130 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %130) #5
  %131 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %131) #5
  %132 = load i32, ptr %9, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret i32 %132
}

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 "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 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 #5 = { nounwind }
attributes #6 = { 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 16}
!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 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 32}
!16 = !{!17, !6, i64 8}
!17 = !{!"rl_btree_node", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!18 = !{!17, !6, i64 16}
!19 = !{!10, !6, i64 24}
!20 = !{!21, !6, i64 8}
!21 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20, !6, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"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"

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_btree_update_element(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = shl i64 %6, 3
  %8 = tail call noalias ptr @malloc(i64 noundef %7) #4
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %.loopexit, label %9

9:                                                ; preds = %4
  %10 = tail call noalias ptr @malloc(i64 noundef %7) #4
  %.not49 = icmp eq ptr %10, null
  br i1 %.not49, label %.loopexit, label %11

11:                                               ; preds = %9
  %12 = tail call i32 @rl_btree_find_score(ptr noundef %0, ptr noundef nonnull %1, ptr noundef %2, ptr noundef null, ptr noundef nonnull %8, ptr noundef nonnull %10)
  %.not50 = icmp eq i32 %12, 2
  br i1 %.not50, label %13, label %.loopexit

13:                                               ; preds = %11
  %14 = load i64, ptr %5, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %17, %13
  %.040.in = phi i64 [ %14, %13 ], [ %.040, %17 ]
  %16 = icmp sgt i64 %.040.in, 0
  br i1 %16, label %17, label %.loopexit

17:                                               ; preds = %15
  %.040 = add nsw i64 %.040.in, -1
  %18 = getelementptr inbounds ptr, ptr %8, i64 %.040
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %.not51 = icmp eq ptr %19, null
  br i1 %.not51, label %15, label %20, !llvm.loop !12

20:                                               ; preds = %17
  %21 = icmp eq i64 %.040, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %1, i64 32
  br label %33

24:                                               ; preds = %20
  %25 = add nsw i64 %.040.in, -2
  %26 = getelementptr inbounds ptr, ptr %8, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = getelementptr inbounds i64, ptr %10, i64 %25
  %31 = load i64, ptr %30, align 8, !tbaa !16
  %32 = getelementptr inbounds i64, ptr %29, i64 %31
  br label %33

33:                                               ; preds = %24, %22
  %.039.in = phi ptr [ %23, %22 ], [ %32, %24 ]
  %.039 = load i64, ptr %.039.in, align 8, !tbaa !16
  %34 = getelementptr inbounds i8, ptr %19, i64 16
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = getelementptr inbounds i64, ptr %10, i64 %.040
  %37 = load i64, ptr %36, align 8, !tbaa !16
  %38 = getelementptr inbounds ptr, ptr %35, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %.not52 = icmp eq ptr %39, %3
  br i1 %.not52, label %44, label %40

40:                                               ; preds = %33
  tail call void @free(ptr noundef %39) #5
  %41 = load ptr, ptr %34, align 8, !tbaa !17
  %42 = load i64, ptr %36, align 8, !tbaa !16
  %43 = getelementptr inbounds ptr, ptr %41, i64 %42
  store ptr %3, ptr %43, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %40, %33
  %45 = getelementptr inbounds i8, ptr %1, i64 24
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = getelementptr inbounds i8, ptr %46, i64 8
  %48 = load ptr, ptr %47, align 8, !tbaa !19
  %49 = tail call i32 @rl_write(ptr noundef %0, ptr noundef %48, i64 noundef %.039, ptr noundef nonnull %19) #5
  br label %.loopexit

.loopexit:                                        ; preds = %15, %9, %4, %44, %11
  %.041 = phi ptr [ %10, %11 ], [ %10, %44 ], [ null, %4 ], [ null, %9 ], [ %10, %15 ]
  %.0 = phi i32 [ %12, %11 ], [ %49, %44 ], [ 4, %4 ], [ 4, %9 ], [ 2, %15 ]
  tail call void @free(ptr noundef %8) #5
  tail call void @free(ptr noundef %.041) #5
  ret i32 %.0
}

attributes #0 = { 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 #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 = { "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 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 allocsize(0) }
attributes #5 = { 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, !10, i64 16}
!6 = !{!"rl_btree", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !7, i64 8}
!15 = !{!"rl_btree_node", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!16 = !{!10, !10, i64 0}
!17 = !{!15, !7, i64 16}
!18 = !{!6, !7, i64 24}
!19 = !{!20, !7, i64 8}
!20 = !{!"", !7, i64 0, !7, i64 8, !21, i64 16, !21, i64 20, !7, i64 24}
!21 = !{!"int", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass