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

@rl_data_type_skiplist_node = external global %struct.rl_data_type, align 8

; 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 i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_skiplist_node_by_rank(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store i64 0, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store i64 0, ptr %15, align 8, !tbaa !9
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = add nsw i64 %17, 1
  store i64 %18, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.rl_skiplist, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call i32 @rl_read(ptr noundef %19, ptr noundef @rl_data_type_skiplist_node, i64 noundef %22, ptr noundef %23, ptr noundef %11, i32 noundef 1)
  store i32 %24, ptr %16, align 4, !tbaa !13
  %25 = load i32, ptr %16, align 4, !tbaa !13
  %26 = icmp ne i32 2, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %5
  br label %111

28:                                               ; preds = %5
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %29, ptr %12, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.rl_skiplist, ptr %30, i32 0, i32 3
  %32 = load i64, ptr %31, align 8, !tbaa !15
  %33 = sub nsw i64 %32, 1
  store i64 %33, ptr %14, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %89, %28
  %35 = load i64, ptr %14, align 8, !tbaa !9
  %36 = icmp sge i64 %35, 0
  br i1 %36, label %37, label %92

37:                                               ; preds = %34
  %38 = load i64, ptr %15, align 8, !tbaa !9
  %39 = load i64, ptr %8, align 8, !tbaa !9
  %40 = icmp eq i64 %38, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %37
  br label %92

42:                                               ; preds = %37
  br label %43

43:                                               ; preds = %86, %42
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.rl_skiplist_node, ptr %45, i32 0, i32 4
  %47 = load i64, ptr %14, align 8, !tbaa !9
  %48 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %46, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %48, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !16
  %51 = icmp eq i64 %50, 0
  br i1 %51, label %63, label %52

52:                                               ; preds = %44
  %53 = load i64, ptr %15, align 8, !tbaa !9
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.rl_skiplist_node, ptr %54, i32 0, i32 4
  %56 = load i64, ptr %14, align 8, !tbaa !9
  %57 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %55, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !18
  %60 = add nsw i64 %53, %59
  %61 = load i64, ptr %8, align 8, !tbaa !9
  %62 = icmp sgt i64 %60, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %52, %44
  br label %88

64:                                               ; preds = %52
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.rl_skiplist_node, ptr %65, i32 0, i32 4
  %67 = load i64, ptr %14, align 8, !tbaa !9
  %68 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %66, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %68, i32 0, i32 1
  %70 = load i64, ptr %69, align 8, !tbaa !18
  %71 = load i64, ptr %15, align 8, !tbaa !9
  %72 = add nsw i64 %71, %70
  store i64 %72, ptr %15, align 8, !tbaa !9
  %73 = load ptr, ptr %12, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.rl_skiplist_node, ptr %73, i32 0, i32 4
  %75 = load i64, ptr %14, align 8, !tbaa !9
  %76 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %74, i64 0, i64 %75
  %77 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %76, i32 0, i32 0
  %78 = load i64, ptr %77, align 8, !tbaa !16
  store i64 %78, ptr %13, align 8, !tbaa !9
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load i64, ptr %13, align 8, !tbaa !9
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = call i32 @rl_read(ptr noundef %79, ptr noundef @rl_data_type_skiplist_node, i64 noundef %80, ptr noundef %81, ptr noundef %11, i32 noundef 1)
  store i32 %82, ptr %16, align 4, !tbaa !13
  %83 = load i32, ptr %16, align 4, !tbaa !13
  %84 = icmp ne i32 2, %83
  br i1 %84, label %85, label %86

85:                                               ; preds = %64
  br label %111

86:                                               ; preds = %64
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %87, ptr %12, align 8, !tbaa !5
  br label %43

88:                                               ; preds = %63
  br label %89

89:                                               ; preds = %88
  %90 = load i64, ptr %14, align 8, !tbaa !9
  %91 = add nsw i64 %90, -1
  store i64 %91, ptr %14, align 8, !tbaa !9
  br label %34, !llvm.loop !19

92:                                               ; preds = %41, %34
  %93 = load i64, ptr %8, align 8, !tbaa !9
  %94 = load i64, ptr %15, align 8, !tbaa !9
  %95 = icmp ne i64 %93, %94
  br i1 %95, label %96, label %97

96:                                               ; preds = %92
  store i32 3, ptr %16, align 4, !tbaa !13
  br label %110

97:                                               ; preds = %92
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  %99 = icmp ne ptr %98, null
  br i1 %99, label %100, label %103

100:                                              ; preds = %97
  %101 = load ptr, ptr %12, align 8, !tbaa !5
  %102 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %101, ptr %102, align 8, !tbaa !5
  br label %103

103:                                              ; preds = %100, %97
  %104 = load ptr, ptr %10, align 8, !tbaa !5
  %105 = icmp ne ptr %104, null
  br i1 %105, label %106, label %109

106:                                              ; preds = %103
  %107 = load i64, ptr %13, align 8, !tbaa !9
  %108 = load ptr, ptr %10, align 8, !tbaa !5
  store i64 %107, ptr %108, align 8, !tbaa !9
  br label %109

109:                                              ; preds = %106, %103
  store i32 0, ptr %16, align 4, !tbaa !13
  br label %110

110:                                              ; preds = %109, %96
  br label %111

111:                                              ; preds = %110, %85, %27
  %112 = load i32, ptr %16, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
  ret i32 %112
}

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, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !10, i64 24}
!16 = !{!17, !10, i64 0}
!17 = !{!"rl_skiplist_node_level", !10, i64 0, !10, i64 8}
!18 = !{!17, !10, 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"

%struct.rl_data_type = type { ptr, ptr, ptr, ptr }
%struct.rl_skiplist_node_level = type { i64, i64 }

@rl_data_type_skiplist_node = external global %struct.rl_data_type, align 8

; 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

declare i32 @rl_read(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 3, 2) i32 @rl_skiplist_node_by_rank(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef writeonly %3, ptr noundef writeonly %4) local_unnamed_addr #2 {
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %7 = add nsw i64 %2, 1
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %9 = call i32 @rl_read(ptr noundef %0, ptr noundef nonnull @rl_data_type_skiplist_node, i64 noundef %8, ptr noundef nonnull %1, ptr noundef nonnull %6, i32 noundef 1) #3
  %.not = icmp eq i32 %9, 2
  br i1 %.not, label %10, label %.loopexit

10:                                               ; preds = %5
  %11 = load ptr, ptr %6, align 8, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %1, i64 24
  %13 = load i64, ptr %12, align 8, !tbaa !12
  %14 = icmp slt i64 %13, 1
  %15 = icmp eq i64 %7, 0
  %or.cond66 = select i1 %14, i1 true, i1 %15
  br i1 %or.cond66, label %._crit_edge71, label %.preheader

.preheader:                                       ; preds = %10, %._crit_edge
  %.03470.in = phi i64 [ %.03470, %._crit_edge ], [ %13, %10 ]
  %.03369 = phi i64 [ %.1.lcssa, %._crit_edge ], [ 0, %10 ]
  %.03568 = phi i64 [ %.136.lcssa, %._crit_edge ], [ 0, %10 ]
  %.03767 = phi ptr [ %.138.lcssa, %._crit_edge ], [ %11, %10 ]
  %.03470 = add nsw i64 %.03470.in, -1
  %16 = getelementptr inbounds i8, ptr %.03767, i64 32
  %17 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %16, i64 0, i64 %.03470
  %18 = load i64, ptr %17, align 8, !tbaa !13
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %20 = getelementptr inbounds i8, ptr %.03767, i64 32
  %21 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %20, i64 0, i64 %.03470, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %23 = add nsw i64 %22, %.03369
  %24 = icmp sgt i64 %23, %7
  br i1 %24, label %._crit_edge, label %.lr.ph78

.lr.ph:                                           ; preds = %33
  %25 = getelementptr inbounds i8, ptr %34, i64 32
  %26 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %25, i64 0, i64 %.03470, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = add nsw i64 %27, %30
  %29 = icmp sgt i64 %28, %7
  br i1 %29, label %._crit_edge, label %.lr.ph78

.lr.ph78:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %30 = phi i64 [ %28, %.lr.ph ], [ %23, %.lr.ph.preheader ]
  %31 = phi i64 [ %37, %.lr.ph ], [ %18, %.lr.ph.preheader ]
  %32 = call i32 @rl_read(ptr noundef %0, ptr noundef nonnull @rl_data_type_skiplist_node, i64 noundef %31, ptr noundef nonnull %1, ptr noundef nonnull %6, i32 noundef 1) #3
  %.not45 = icmp eq i32 %32, 2
  br i1 %.not45, label %33, label %.loopexit

33:                                               ; preds = %.lr.ph78
  %34 = load ptr, ptr %6, align 8, !tbaa !10
  %35 = getelementptr inbounds i8, ptr %34, i64 32
  %36 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %35, i64 0, i64 %.03470
  %37 = load i64, ptr %36, align 8, !tbaa !13
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %33, %.lr.ph.preheader, %.preheader
  %.138.lcssa = phi ptr [ %.03767, %.preheader ], [ %.03767, %.lr.ph.preheader ], [ %34, %33 ], [ %34, %.lr.ph ]
  %.136.lcssa = phi i64 [ %.03568, %.preheader ], [ %.03568, %.lr.ph.preheader ], [ %31, %33 ], [ %31, %.lr.ph ]
  %.1.lcssa = phi i64 [ %.03369, %.preheader ], [ %.03369, %.lr.ph.preheader ], [ %30, %33 ], [ %30, %.lr.ph ]
  %39 = icmp slt i64 %.03470.in, 2
  %40 = icmp eq i64 %.1.lcssa, %7
  %or.cond = select i1 %39, i1 true, i1 %40
  br i1 %or.cond, label %._crit_edge71, label %.preheader, !llvm.loop !16

._crit_edge71:                                    ; preds = %._crit_edge, %10
  %.037.lcssa = phi ptr [ %11, %10 ], [ %.138.lcssa, %._crit_edge ]
  %.035.lcssa = phi i64 [ 0, %10 ], [ %.136.lcssa, %._crit_edge ]
  %.lcssa52 = phi i1 [ %15, %10 ], [ %40, %._crit_edge ]
  br i1 %.lcssa52, label %41, label %.loopexit

41:                                               ; preds = %._crit_edge71
  %.not47 = icmp eq ptr %3, null
  br i1 %.not47, label %43, label %42

42:                                               ; preds = %41
  store ptr %.037.lcssa, ptr %3, align 8, !tbaa !10
  br label %43

43:                                               ; preds = %42, %41
  %.not48 = icmp eq ptr %4, null
  br i1 %.not48, label %.loopexit, label %44

44:                                               ; preds = %43
  store i64 %.035.lcssa, ptr %4, align 8, !tbaa !18
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph78, %43, %44, %._crit_edge71, %5
  %.0 = phi i32 [ %9, %5 ], [ 3, %._crit_edge71 ], [ 0, %44 ], [ 0, %43 ], [ %32, %.lr.ph78 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i32 %.0
}

attributes #0 = { mustprogress 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 24}
!13 = !{!14, !7, i64 0}
!14 = !{!"rl_skiplist_node_level", !7, i64 0, !7, i64 8}
!15 = !{!14, !7, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!7, !7, i64 0}


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