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

; 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_skiplist_node = type { i64, double, i64, i64, [0 x %struct.rl_skiplist_node_level] }
%struct.rl_skiplist_node_level = type { i64, i64 }

; 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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_skiplist_node_serialize(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
  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) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.rl_skiplist_node, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !9
  call void @put_4bytes(ptr noundef %11, i64 noundef %14)
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.rl_skiplist_node, ptr %17, i32 0, i32 1
  %19 = load double, ptr %18, align 8, !tbaa !11
  call void @put_double(ptr noundef %16, double noundef %19)
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 12
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.rl_skiplist_node, ptr %22, i32 0, i32 2
  %24 = load i64, ptr %23, align 8, !tbaa !9
  call void @put_4bytes(ptr noundef %21, i64 noundef %24)
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.rl_skiplist_node, ptr %27, i32 0, i32 3
  %29 = load i64, ptr %28, align 8, !tbaa !9
  call void @put_4bytes(ptr noundef %26, i64 noundef %29)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 20, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %58, %3
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.rl_skiplist_node, ptr %32, i32 0, i32 3
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = icmp slt i64 %31, %34
  br i1 %35, label %36, label %61

36:                                               ; preds = %30
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %37, i64 %38
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.rl_skiplist_node, ptr %40, i32 0, i32 4
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %41, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %43, i32 0, i32 0
  %45 = load i64, ptr %44, align 8, !tbaa !13
  call void @put_4bytes(ptr noundef %39, i64 noundef %45)
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = add nsw i64 %47, 4
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.rl_skiplist_node, ptr %50, i32 0, i32 4
  %52 = load i64, ptr %8, align 8, !tbaa !9
  %53 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %51, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %53, i32 0, i32 1
  %55 = load i64, ptr %54, align 8, !tbaa !15
  call void @put_4bytes(ptr noundef %49, i64 noundef %55)
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = add nsw i64 %56, 8
  store i64 %57, ptr %9, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %36
  %59 = load i64, ptr %8, align 8, !tbaa !9
  %60 = add nsw i64 %59, 1
  store i64 %60, ptr %8, align 8, !tbaa !9
  br label %30, !llvm.loop !16

61:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  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 = { 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, !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 = !{!"double", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"rl_skiplist_node_level", !10, i64 0, !10, i64 8}
!15 = !{!14, !10, 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"

%struct.rl_skiplist_node_level = type { i64, i64 }

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @rl_skiplist_node_serialize(ptr nocapture noundef readnone %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = load i64, ptr %1, align 8, !tbaa !5
  tail call void @put_4bytes(ptr noundef %2, i64 noundef %4) #2
  %5 = getelementptr inbounds i8, ptr %2, i64 4
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load double, ptr %6, align 8, !tbaa !9
  tail call void @put_double(ptr noundef nonnull %5, double noundef %7) #2
  %8 = getelementptr inbounds i8, ptr %2, i64 12
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = load i64, ptr %9, align 8, !tbaa !5
  tail call void @put_4bytes(ptr noundef nonnull %8, i64 noundef %10) #2
  %11 = getelementptr inbounds i8, ptr %2, i64 16
  %12 = getelementptr inbounds i8, ptr %1, i64 24
  %13 = load i64, ptr %12, align 8, !tbaa !5
  tail call void @put_4bytes(ptr noundef nonnull %11, i64 noundef %13) #2
  %14 = load i64, ptr %12, align 8, !tbaa !5
  %15 = icmp sgt i64 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %16 = getelementptr inbounds i8, ptr %1, i64 32
  br label %17

17:                                               ; preds = %.lr.ph, %17
  %.022 = phi i64 [ 20, %.lr.ph ], [ %24, %17 ]
  %.02021 = phi i64 [ 0, %.lr.ph ], [ %25, %17 ]
  %18 = getelementptr inbounds i8, ptr %2, i64 %.022
  %19 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %16, i64 0, i64 %.02021
  %20 = load i64, ptr %19, align 8, !tbaa !11
  tail call void @put_4bytes(ptr noundef nonnull %18, i64 noundef %20) #2
  %21 = getelementptr inbounds i8, ptr %18, i64 4
  %22 = getelementptr inbounds i8, ptr %19, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !13
  tail call void @put_4bytes(ptr noundef nonnull %21, i64 noundef %23) #2
  %24 = add nuw nsw i64 %.022, 8
  %25 = add nuw nsw i64 %.02021, 1
  %26 = load i64, ptr %12, align 8, !tbaa !5
  %27 = icmp slt i64 %25, %26
  br i1 %27, label %17, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %17, %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 = { 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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"rl_skiplist_node_level", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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