; 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_hashkey = type { 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: 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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_btree_node_serialize_hash_sha1_hashkey(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %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 = %72, %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 %75

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 %6, align 8, !tbaa !5
  %39 = load i64, ptr %9, align 8, !tbaa !12
  %40 = add nsw i64 %39, 20
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rl_hashkey, ptr %42, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !15
  call void @put_4bytes(ptr noundef %41, i64 noundef %44)
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr %9, align 8, !tbaa !12
  %47 = add nsw i64 %46, 24
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.rl_hashkey, ptr %49, i32 0, i32 1
  %51 = load i64, ptr %50, align 8, !tbaa !17
  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, 28
  %55 = getelementptr inbounds i8, ptr %52, i64 %54
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.rl_btree_node, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !18
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %67

60:                                               ; preds = %22
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.rl_btree_node, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !18
  %64 = load i64, ptr %8, align 8, !tbaa !12
  %65 = getelementptr inbounds i64, ptr %63, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !12
  br label %68

67:                                               ; preds = %22
  br label %68

68:                                               ; preds = %67, %60
  %69 = phi i64 [ %66, %60 ], [ 0, %67 ]
  call void @put_4bytes(ptr noundef %55, i64 noundef %69)
  %70 = load i64, ptr %9, align 8, !tbaa !12
  %71 = add nsw i64 %70, 32
  store i64 %71, ptr %9, align 8, !tbaa !12
  br label %72

72:                                               ; preds = %68
  %73 = load i64, ptr %8, align 8, !tbaa !12
  %74 = add nsw i64 %73, 1
  store i64 %74, ptr %8, align 8, !tbaa !12
  br label %16, !llvm.loop !19

75:                                               ; preds = %16
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load i64, ptr %9, align 8, !tbaa !12
  %78 = getelementptr inbounds i8, ptr %76, i64 %77
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.rl_btree_node, ptr %79, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !18
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %92

83:                                               ; preds = %75
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.rl_btree_node, ptr %84, i32 0, i32 1
  %86 = load ptr, ptr %85, align 8, !tbaa !18
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.rl_btree_node, ptr %87, i32 0, i32 3
  %89 = load i64, ptr %88, align 8, !tbaa !9
  %90 = getelementptr inbounds i64, ptr %86, i64 %89
  %91 = load i64, ptr %90, align 8, !tbaa !12
  br label %93

92:                                               ; preds = %75
  br label %93

93:                                               ; preds = %92, %83
  %94 = phi i64 [ %91, %83 ], [ 0, %92 ]
  call void @put_4bytes(ptr noundef %78, i64 noundef %94)
  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
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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, !11, i64 0}
!16 = !{!"rl_hashkey", !11, i64 0, !11, i64 8}
!17 = !{!16, !11, i64 8}
!18 = !{!10, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"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: 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) #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @rl_btree_node_serialize_hash_sha1_hashkey(ptr nocapture noundef readnone %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #2 {
  %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, %28
  %.034 = phi i64 [ 0, %.lr.ph ], [ %31, %28 ]
  %.02833 = phi i64 [ 4, %.lr.ph ], [ %30, %28 ]
  %11 = getelementptr inbounds i8, ptr %2, i64 %.02833
  %12 = load ptr, ptr %1, align 8, !tbaa !11
  %13 = getelementptr inbounds ptr, ptr %12, i64 %.034
  %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 %.034
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %11, i64 20
  %19 = load i64, ptr %17, align 8, !tbaa !14
  tail call void @put_4bytes(ptr noundef nonnull %18, i64 noundef %19) #3
  %20 = getelementptr inbounds i8, ptr %11, i64 24
  %21 = getelementptr inbounds i8, ptr %17, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !16
  tail call void @put_4bytes(ptr noundef nonnull %20, i64 noundef %22) #3
  %23 = getelementptr inbounds i8, ptr %11, i64 28
  %24 = load ptr, ptr %9, align 8, !tbaa !17
  %.not32 = icmp eq ptr %24, null
  br i1 %.not32, label %28, label %25

25:                                               ; preds = %10
  %26 = getelementptr inbounds i64, ptr %24, i64 %.034
  %27 = load i64, ptr %26, align 8, !tbaa !18
  br label %28

28:                                               ; preds = %10, %25
  %29 = phi i64 [ %27, %25 ], [ 0, %10 ]
  tail call void @put_4bytes(ptr noundef nonnull %23, i64 noundef %29) #3
  %30 = add nuw nsw i64 %.02833, 32
  %31 = add nuw nsw i64 %.034, 1
  %32 = load i64, ptr %4, align 8, !tbaa !5
  %33 = icmp slt i64 %31, %32
  br i1 %33, label %10, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %28, %3
  %.028.lcssa = phi i64 [ 4, %3 ], [ %30, %28 ]
  %.lcssa = phi i64 [ %6, %3 ], [ %32, %28 ]
  %34 = getelementptr inbounds i8, ptr %1, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %.not = icmp eq ptr %35, null
  br i1 %.not, label %39, label %36

36:                                               ; preds = %._crit_edge
  %37 = getelementptr inbounds i64, ptr %35, i64 %.lcssa
  %38 = load i64, ptr %37, align 8, !tbaa !18
  br label %39

39:                                               ; preds = %._crit_edge, %36
  %40 = phi i64 [ %38, %36 ], [ 0, %._crit_edge ]
  %41 = getelementptr inbounds i8, ptr %2, i64 %.028.lcssa
  tail call void @put_4bytes(ptr noundef nonnull %41, i64 noundef %40) #3
  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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 0}
!15 = !{!"rl_hashkey", !10, i64 0, !10, i64 8}
!16 = !{!15, !10, i64 8}
!17 = !{!6, !7, i64 8}
!18 = !{!10, !10, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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