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

; 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_long(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
  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
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  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 !9
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.rl_btree_node, ptr %12, i32 0, i32 3
  %14 = load i64, ptr %13, align 8, !tbaa !11
  call void @put_4bytes(ptr noundef %11, i64 noundef %14)
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %15

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

21:                                               ; preds = %15
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %22, i64 %23
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.rl_btree_node, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = load i64, ptr %8, align 8, !tbaa !9
  %29 = getelementptr inbounds ptr, ptr %27, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %24, ptr align 1 %30, i64 20, i1 false)
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = add nsw i64 %32, 20
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.rl_btree_node, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = getelementptr inbounds ptr, ptr %37, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = sitofp i64 %41 to double
  call void @put_double(ptr noundef %34, double noundef %42)
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = add nsw i64 %44, 24
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.rl_btree_node, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %58

51:                                               ; preds = %21
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.rl_btree_node, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = load i64, ptr %8, align 8, !tbaa !9
  %56 = getelementptr inbounds i64, ptr %54, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !9
  br label %59

58:                                               ; preds = %21
  br label %59

59:                                               ; preds = %58, %51
  %60 = phi i64 [ %57, %51 ], [ 0, %58 ]
  call void @put_4bytes(ptr noundef %46, i64 noundef %60)
  %61 = load i64, ptr %9, align 8, !tbaa !9
  %62 = add nsw i64 %61, 28
  store i64 %62, ptr %9, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %59
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = add nsw i64 %64, 1
  store i64 %65, ptr %8, align 8, !tbaa !9
  br label %15, !llvm.loop !16

66:                                               ; preds = %15
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load i64, ptr %9, align 8, !tbaa !9
  %69 = getelementptr inbounds i8, ptr %67, i64 %68
  %70 = load ptr, ptr %7, 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 !15
  %73 = icmp ne ptr %72, null
  br i1 %73, label %74, label %83

74:                                               ; preds = %66
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.rl_btree_node, ptr %75, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !15
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.rl_btree_node, ptr %78, i32 0, i32 3
  %80 = load i64, ptr %79, align 8, !tbaa !11
  %81 = getelementptr inbounds i64, ptr %77, i64 %80
  %82 = load i64, ptr %81, align 8, !tbaa !9
  br label %84

83:                                               ; preds = %66
  br label %84

84:                                               ; preds = %83, %74
  %85 = phi i64 [ %82, %74 ], [ 0, %83 ]
  call void @put_4bytes(ptr noundef %69, i64 noundef %85)
  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
}

declare void @put_double(ptr noundef, double 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 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"rl_btree_node", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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_long(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, %26
  %.030 = phi i64 [ 4, %.lr.ph ], [ %28, %26 ]
  %.02429 = phi i64 [ 0, %.lr.ph ], [ %29, %26 ]
  %11 = getelementptr inbounds i8, ptr %2, i64 %.030
  %12 = load ptr, ptr %1, align 8, !tbaa !11
  %13 = getelementptr inbounds ptr, ptr %12, i64 %.02429
  %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 = getelementptr inbounds i8, ptr %11, i64 20
  %16 = load ptr, ptr %8, align 8, !tbaa !13
  %17 = getelementptr inbounds ptr, ptr %16, i64 %.02429
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = load i64, ptr %18, align 8, !tbaa !14
  %20 = sitofp i64 %19 to double
  tail call void @put_double(ptr noundef nonnull %15, double noundef %20) #3
  %21 = getelementptr inbounds i8, ptr %11, i64 24
  %22 = load ptr, ptr %9, align 8, !tbaa !15
  %.not28 = icmp eq ptr %22, null
  br i1 %.not28, label %26, label %23

23:                                               ; preds = %10
  %24 = getelementptr inbounds i64, ptr %22, i64 %.02429
  %25 = load i64, ptr %24, align 8, !tbaa !14
  br label %26

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

._crit_edge:                                      ; preds = %26, %3
  %.0.lcssa = phi i64 [ 4, %3 ], [ %28, %26 ]
  %.lcssa = phi i64 [ %6, %3 ], [ %30, %26 ]
  %32 = getelementptr inbounds i8, ptr %1, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %.not = icmp eq ptr %33, null
  br i1 %.not, label %37, label %34

34:                                               ; preds = %._crit_edge
  %35 = getelementptr inbounds i64, ptr %33, i64 %.lcssa
  %36 = load i64, ptr %35, align 8, !tbaa !14
  br label %37

37:                                               ; preds = %._crit_edge, %34
  %38 = phi i64 [ %36, %34 ], [ 0, %._crit_edge ]
  %39 = getelementptr inbounds i8, ptr %2, i64 %.0.lcssa
  tail call void @put_4bytes(ptr noundef nonnull %39, i64 noundef %38) #3
  ret i32 0
}

declare void @put_double(ptr noundef, double 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 = { 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 = !{!10, !10, i64 0}
!15 = !{!6, !7, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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