; 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_node = type { ptr, ptr, ptr, i64 }
%struct.rl_key = type { i8, i64, i64, i64, i64 }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @put_4bytes(ptr noundef, 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: nounwind uwtable
define dso_local i32 @rl_btree_node_serialize_hash_sha1_key(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %11, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.rl_btree_node, ptr %13, i32 0, i32 3
  %15 = load i64, ptr %14, align 8, !tbaa !9
  call void @put_4bytes(ptr noundef %12, i64 noundef %15)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 4, ptr %9, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %8, align 8, !tbaa !12
  br label %16

16:                                               ; preds = %93, %3
  %17 = load i64, ptr %8, align 8, !tbaa !12
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.rl_btree_node, ptr %18, i32 0, i32 3
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = icmp slt i64 %17, %20
  br i1 %21, label %22, label %96

22:                                               ; preds = %16
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i64, ptr %9, align 8, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %23, i64 %24
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.rl_btree_node, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = load i64, ptr %8, align 8, !tbaa !12
  %30 = getelementptr inbounds ptr, ptr %28, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %25, ptr align 1 %31, i64 20, i1 false)
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.rl_btree_node, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load i64, ptr %8, align 8, !tbaa !12
  %36 = getelementptr inbounds ptr, ptr %34, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  store ptr %37, ptr %10, align 8, !tbaa !5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.rl_key, ptr %38, i32 0, i32 0
  %40 = load i8, ptr %39, align 8, !tbaa !15
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i64, ptr %9, align 8, !tbaa !12
  %43 = add nsw i64 %42, 20
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  store i8 %40, ptr %44, align 1, !tbaa !18
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr %9, align 8, !tbaa !12
  %47 = add nsw i64 %46, 21
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.rl_key, ptr %49, i32 0, i32 1
  %51 = load i64, ptr %50, align 8, !tbaa !19
  call void @put_4bytes(ptr noundef %48, i64 noundef %51)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i64, ptr %9, align 8, !tbaa !12
  %54 = add nsw i64 %53, 25
  %55 = getelementptr inbounds i8, ptr %52, i64 %54
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.rl_key, ptr %56, i32 0, i32 2
  %58 = load i64, ptr %57, align 8, !tbaa !20
  call void @put_4bytes(ptr noundef %55, i64 noundef %58)
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i64, ptr %9, align 8, !tbaa !12
  %61 = add nsw i64 %60, 29
  %62 = getelementptr inbounds i8, ptr %59, i64 %61
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.rl_key, ptr %63, i32 0, i32 3
  %65 = load i64, ptr %64, align 8, !tbaa !21
  call void @put_8bytes(ptr noundef %62, i64 noundef %65)
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load i64, ptr %9, align 8, !tbaa !12
  %68 = add nsw i64 %67, 37
  %69 = getelementptr inbounds i8, ptr %66, i64 %68
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.rl_key, ptr %70, i32 0, i32 4
  %72 = load i64, ptr %71, align 8, !tbaa !22
  call void @put_4bytes(ptr noundef %69, i64 noundef %72)
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load i64, ptr %9, align 8, !tbaa !12
  %75 = add nsw i64 %74, 41
  %76 = getelementptr inbounds i8, ptr %73, i64 %75
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.rl_btree_node, ptr %77, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !23
  %80 = icmp ne ptr %79, null
  br i1 %80, label %81, label %88

81:                                               ; preds = %22
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.rl_btree_node, ptr %82, i32 0, i32 1
  %84 = load ptr, ptr %83, align 8, !tbaa !23
  %85 = load i64, ptr %8, align 8, !tbaa !12
  %86 = getelementptr inbounds i64, ptr %84, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !12
  br label %89

88:                                               ; preds = %22
  br label %89

89:                                               ; preds = %88, %81
  %90 = phi i64 [ %87, %81 ], [ 0, %88 ]
  call void @put_4bytes(ptr noundef %76, i64 noundef %90)
  %91 = load i64, ptr %9, align 8, !tbaa !12
  %92 = add nsw i64 %91, 45
  store i64 %92, ptr %9, align 8, !tbaa !12
  br label %93

93:                                               ; preds = %89
  %94 = load i64, ptr %8, align 8, !tbaa !12
  %95 = add nsw i64 %94, 1
  store i64 %95, ptr %8, align 8, !tbaa !12
  br label %16, !llvm.loop !24

96:                                               ; preds = %16
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = load i64, ptr %9, align 8, !tbaa !12
  %99 = getelementptr inbounds i8, ptr %97, i64 %98
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.rl_btree_node, ptr %100, i32 0, i32 1
  %102 = load ptr, ptr %101, align 8, !tbaa !23
  %103 = icmp ne ptr %102, null
  br i1 %103, label %104, label %113

104:                                              ; preds = %96
  %105 = load ptr, ptr %7, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.rl_btree_node, ptr %105, i32 0, i32 1
  %107 = load ptr, ptr %106, align 8, !tbaa !23
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.rl_btree_node, ptr %108, i32 0, i32 3
  %110 = load i64, ptr %109, align 8, !tbaa !9
  %111 = getelementptr inbounds i64, ptr %107, i64 %110
  %112 = load i64, ptr %111, align 8, !tbaa !12
  br label %114

113:                                              ; preds = %96
  br label %114

114:                                              ; preds = %113, %104
  %115 = phi i64 [ %112, %104 ], [ 0, %113 ]
  call void @put_4bytes(ptr noundef %99, i64 noundef %115)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare void @put_8bytes(ptr noundef, i64 noundef) #1

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !11, i64 24}
!10 = !{!"rl_btree_node", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!10, !6, i64 16}
!15 = !{!16, !7, i64 0}
!16 = !{!"rl_key", !7, i64 0, !11, i64 8, !11, i64 16, !17, i64 24, !11, i64 32}
!17 = !{!"long long", !7, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!16, !11, i64 8}
!20 = !{!16, !11, i64 16}
!21 = !{!16, !17, i64 24}
!22 = !{!16, !11, i64 32}
!23 = !{!10, !6, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"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"

declare void @put_4bytes(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @rl_btree_node_serialize_hash_sha1_key(ptr nocapture noundef readnone %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %1, i64 24
  %5 = load i64, ptr %4, align 8, !tbaa !5
  tail call void @put_4bytes(ptr noundef %2, i64 noundef %5) #3
  %6 = load i64, ptr %4, align 8, !tbaa !5
  %7 = icmp sgt i64 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  br label %10

10:                                               ; preds = %.lr.ph, %37
  %.043 = phi i64 [ 0, %.lr.ph ], [ %40, %37 ]
  %.03742 = phi i64 [ 4, %.lr.ph ], [ %39, %37 ]
  %11 = getelementptr inbounds i8, ptr %2, i64 %.03742
  %12 = load ptr, ptr %1, align 8, !tbaa !11
  %13 = getelementptr inbounds ptr, ptr %12, i64 %.043
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(20) %11, ptr noundef nonnull align 1 dereferenceable(20) %14, i64 20, i1 false)
  %15 = load ptr, ptr %8, align 8, !tbaa !13
  %16 = getelementptr inbounds ptr, ptr %15, i64 %.043
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = load i8, ptr %17, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %11, i64 20
  store i8 %18, ptr %19, align 1, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %11, i64 21
  %21 = getelementptr inbounds i8, ptr %17, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !18
  tail call void @put_4bytes(ptr noundef nonnull %20, i64 noundef %22) #3
  %23 = getelementptr inbounds i8, ptr %11, i64 25
  %24 = getelementptr inbounds i8, ptr %17, i64 16
  %25 = load i64, ptr %24, align 8, !tbaa !19
  tail call void @put_4bytes(ptr noundef nonnull %23, i64 noundef %25) #3
  %26 = getelementptr inbounds i8, ptr %11, i64 29
  %27 = getelementptr inbounds i8, ptr %17, i64 24
  %28 = load i64, ptr %27, align 8, !tbaa !20
  tail call void @put_8bytes(ptr noundef nonnull %26, i64 noundef %28) #3
  %29 = getelementptr inbounds i8, ptr %11, i64 37
  %30 = getelementptr inbounds i8, ptr %17, i64 32
  %31 = load i64, ptr %30, align 8, !tbaa !21
  tail call void @put_4bytes(ptr noundef nonnull %29, i64 noundef %31) #3
  %32 = getelementptr inbounds i8, ptr %11, i64 41
  %33 = load ptr, ptr %9, align 8, !tbaa !22
  %.not41 = icmp eq ptr %33, null
  br i1 %.not41, label %37, label %34

34:                                               ; preds = %10
  %35 = getelementptr inbounds i64, ptr %33, i64 %.043
  %36 = load i64, ptr %35, align 8, !tbaa !23
  br label %37

37:                                               ; preds = %10, %34
  %38 = phi i64 [ %36, %34 ], [ 0, %10 ]
  tail call void @put_4bytes(ptr noundef nonnull %32, i64 noundef %38) #3
  %39 = add nuw nsw i64 %.03742, 45
  %40 = add nuw nsw i64 %.043, 1
  %41 = load i64, ptr %4, align 8, !tbaa !5
  %42 = icmp slt i64 %40, %41
  br i1 %42, label %10, label %._crit_edge, !llvm.loop !24

._crit_edge:                                      ; preds = %37, %3
  %.037.lcssa = phi i64 [ 4, %3 ], [ %39, %37 ]
  %.lcssa = phi i64 [ %6, %3 ], [ %41, %37 ]
  %43 = getelementptr inbounds i8, ptr %1, i64 8
  %44 = load ptr, ptr %43, align 8, !tbaa !22
  %.not = icmp eq ptr %44, null
  br i1 %.not, label %48, label %45

45:                                               ; preds = %._crit_edge
  %46 = getelementptr inbounds i64, ptr %44, i64 %.lcssa
  %47 = load i64, ptr %46, align 8, !tbaa !23
  br label %48

48:                                               ; preds = %._crit_edge, %45
  %49 = phi i64 [ %47, %45 ], [ 0, %._crit_edge ]
  %50 = getelementptr inbounds i8, ptr %2, i64 %.037.lcssa
  tail call void @put_4bytes(ptr noundef nonnull %50, i64 noundef %49) #3
  ret i32 0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare void @put_8bytes(ptr noundef, i64 noundef) local_unnamed_addr #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 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 24}
!6 = !{!"rl_btree_node", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 16}
!14 = !{!15, !8, i64 0}
!15 = !{!"rl_key", !8, i64 0, !10, i64 8, !10, i64 16, !16, i64 24, !10, i64 32}
!16 = !{!"long long", !8, i64 0}
!17 = !{!8, !8, i64 0}
!18 = !{!15, !10, i64 8}
!19 = !{!15, !10, i64 16}
!20 = !{!15, !16, i64 24}
!21 = !{!15, !10, i64 32}
!22 = !{!6, !7, i64 8}
!23 = !{!10, !10, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass