; 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_skiplist_node_create(ptr noundef, ptr noundef, i64 noundef, double noundef, i64 noundef) #1

declare i32 @get_4bytes(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_skiplist_node_deserialize(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca double, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca i64, 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 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = call i32 @get_4bytes(ptr noundef %17)
  %19 = sext i32 %18 to i64
  store i64 %19, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 4
  %22 = call double @get_double(ptr noundef %21)
  store double %22, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 12
  %25 = call i32 @get_4bytes(ptr noundef %24)
  %26 = sext i32 %25 to i64
  store i64 %26, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %29 = call i32 @get_4bytes(ptr noundef %28)
  %30 = sext i32 %29 to i64
  store i64 %30, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %13, align 8, !tbaa !9
  %33 = load double, ptr %11, align 8, !tbaa !11
  %34 = load i64, ptr %10, align 8, !tbaa !9
  %35 = call i32 @rl_skiplist_node_create(ptr noundef %31, ptr noundef %9, i64 noundef %32, double noundef %33, i64 noundef %34)
  store i32 %35, ptr %14, align 4, !tbaa !13
  %36 = load i32, ptr %14, align 4, !tbaa !13
  %37 = icmp ne i32 0, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %4
  br label %79

39:                                               ; preds = %4
  %40 = load i64, ptr %12, align 8, !tbaa !9
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.rl_skiplist_node, ptr %41, i32 0, i32 2
  store i64 %40, ptr %42, align 8, !tbaa !9
  store i64 20, ptr %16, align 8, !tbaa !9
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %73, %39
  %44 = load i64, ptr %15, align 8, !tbaa !9
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.rl_skiplist_node, ptr %45, i32 0, i32 3
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = icmp slt i64 %44, %47
  br i1 %48, label %49, label %76

49:                                               ; preds = %43
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i64, ptr %16, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  %53 = call i32 @get_4bytes(ptr noundef %52)
  %54 = sext i32 %53 to i64
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.rl_skiplist_node, ptr %55, i32 0, i32 4
  %57 = load i64, ptr %15, align 8, !tbaa !9
  %58 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %56, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %58, i32 0, i32 0
  store i64 %54, ptr %59, align 8, !tbaa !15
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load i64, ptr %16, align 8, !tbaa !9
  %62 = add nsw i64 %61, 4
  %63 = getelementptr inbounds i8, ptr %60, i64 %62
  %64 = call i32 @get_4bytes(ptr noundef %63)
  %65 = sext i32 %64 to i64
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.rl_skiplist_node, ptr %66, i32 0, i32 4
  %68 = load i64, ptr %15, align 8, !tbaa !9
  %69 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %67, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %69, i32 0, i32 1
  store i64 %65, ptr %70, align 8, !tbaa !17
  %71 = load i64, ptr %16, align 8, !tbaa !9
  %72 = add nsw i64 %71, 8
  store i64 %72, ptr %16, align 8, !tbaa !9
  br label %73

73:                                               ; preds = %49
  %74 = load i64, ptr %15, align 8, !tbaa !9
  %75 = add nsw i64 %74, 1
  store i64 %75, ptr %15, align 8, !tbaa !9
  br label %43, !llvm.loop !18

76:                                               ; preds = %43
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %77, ptr %78, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %76, %38
  %80 = load i32, ptr %14, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i32 %80
}

declare double @get_double(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"rl_skiplist_node_level", !10, i64 0, !10, i64 8}
!17 = !{!16, !10, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"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 }

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_skiplist_node_create(ptr noundef, ptr noundef, i64 noundef, double noundef, i64 noundef) local_unnamed_addr #1

declare i32 @get_4bytes(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_skiplist_node_deserialize(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef readnone %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %6 = tail call i32 @get_4bytes(ptr noundef %3) #3
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds i8, ptr %3, i64 4
  %9 = tail call double @get_double(ptr noundef nonnull %8) #3
  %10 = getelementptr inbounds i8, ptr %3, i64 12
  %11 = tail call i32 @get_4bytes(ptr noundef nonnull %10) #3
  %12 = getelementptr inbounds i8, ptr %3, i64 16
  %13 = tail call i32 @get_4bytes(ptr noundef nonnull %12) #3
  %14 = sext i32 %13 to i64
  %15 = call i32 @rl_skiplist_node_create(ptr noundef %0, ptr noundef nonnull %5, i64 noundef %14, double noundef %9, i64 noundef %7)
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %16, label %40

16:                                               ; preds = %4
  %17 = sext i32 %11 to i64
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  store i64 %17, ptr %19, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %18, i64 24
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = icmp sgt i64 %21, 0
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %16, %.lr.ph
  %.022 = phi i64 [ %35, %.lr.ph ], [ 20, %16 ]
  %.02021 = phi i64 [ %36, %.lr.ph ], [ 0, %16 ]
  %23 = getelementptr inbounds i8, ptr %3, i64 %.022
  %24 = call i32 @get_4bytes(ptr noundef nonnull %23) #3
  %25 = sext i32 %24 to i64
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 32
  %28 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %27, i64 0, i64 %.02021
  store i64 %25, ptr %28, align 8, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %23, i64 4
  %30 = call i32 @get_4bytes(ptr noundef nonnull %29) #3
  %31 = sext i32 %30 to i64
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 32
  %34 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %33, i64 0, i64 %.02021, i32 1
  store i64 %31, ptr %34, align 8, !tbaa !13
  %35 = add nuw nsw i64 %.022, 8
  %36 = add nuw nsw i64 %.02021, 1
  %37 = getelementptr inbounds i8, ptr %32, i64 24
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = icmp slt i64 %36, %38
  br i1 %39, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %16
  %.lcssa = phi ptr [ %18, %16 ], [ %32, %.lr.ph ]
  store ptr %.lcssa, ptr %1, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %4, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  ret i32 %15
}

declare double @get_double(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !10, i64 0}
!12 = !{!"rl_skiplist_node_level", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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