; 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: nounwind allocsize(0)
declare noalias ptr @malloc(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: nounwind uwtable
define dso_local i32 @rl_skiplist_node_create(ptr noundef %0, ptr noundef %1, i64 noundef %2, double noundef %3, i64 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca double, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  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 double %3, ptr %9, align 8, !tbaa !11
  store i64 %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load i64, ptr %8, align 8, !tbaa !9
  %15 = mul i64 %14, 16
  %16 = add i64 32, %15
  %17 = call noalias ptr @malloc(i64 noundef %16) #4
  store ptr %17, ptr %12, align 8, !tbaa !5
  %18 = load ptr, ptr %12, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %5
  store i32 4, ptr %11, align 4, !tbaa !13
  br label %54

21:                                               ; preds = %5
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.rl_skiplist_node, ptr %23, i32 0, i32 3
  store i64 %22, ptr %24, align 8, !tbaa !9
  %25 = load double, ptr %9, align 8, !tbaa !11
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.rl_skiplist_node, ptr %26, i32 0, i32 1
  store double %25, ptr %27, align 8, !tbaa !11
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.rl_skiplist_node, ptr %29, i32 0, i32 0
  store i64 %28, ptr %30, align 8, !tbaa !9
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.rl_skiplist_node, ptr %31, i32 0, i32 2
  store i64 0, ptr %32, align 8, !tbaa !9
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %48, %21
  %34 = load i64, ptr %13, align 8, !tbaa !9
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = icmp slt i64 %34, %35
  br i1 %36, label %37, label %51

37:                                               ; preds = %33
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.rl_skiplist_node, ptr %38, i32 0, i32 4
  %40 = load i64, ptr %13, align 8, !tbaa !9
  %41 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %39, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %41, i32 0, i32 0
  store i64 0, ptr %42, align 8, !tbaa !15
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.rl_skiplist_node, ptr %43, i32 0, i32 4
  %45 = load i64, ptr %13, align 8, !tbaa !9
  %46 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %44, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %46, i32 0, i32 1
  store i64 0, ptr %47, align 8, !tbaa !17
  br label %48

48:                                               ; preds = %37
  %49 = load i64, ptr %13, align 8, !tbaa !9
  %50 = add nsw i64 %49, 1
  store i64 %50, ptr %13, align 8, !tbaa !9
  br label %33, !llvm.loop !18

51:                                               ; preds = %33
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %52, ptr %53, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %51, %20
  %55 = load i32, ptr %11, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret i32 %55
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 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 }
attributes #4 = { nounwind allocsize(0) }

!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"

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, inaccessiblemem: readwrite) uwtable
define dso_local range(i32 0, 5) i32 @rl_skiplist_node_create(ptr nocapture noundef readnone %0, ptr nocapture noundef writeonly %1, i64 noundef %2, double noundef %3, i64 noundef %4) local_unnamed_addr #1 {
  %6 = shl i64 %2, 4
  %7 = add i64 %6, 32
  %8 = tail call noalias ptr @malloc(i64 noundef %7) #3
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %15, label %9

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %8, i64 24
  store i64 %2, ptr %10, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %8, i64 8
  store double %3, ptr %11, align 8, !tbaa !9
  store i64 %4, ptr %8, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %8, i64 16
  store i64 0, ptr %12, align 8, !tbaa !5
  %13 = icmp sgt i64 %2, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9
  %14 = getelementptr inbounds i8, ptr %8, i64 32
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %14, i8 0, i64 %6, i1 false), !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %9
  store ptr %8, ptr %1, align 8, !tbaa !11
  br label %15

15:                                               ; preds = %5, %._crit_edge
  %.018 = phi i32 [ 0, %._crit_edge ], [ 4, %5 ]
  ret i32 %.018
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nofree nounwind willreturn memory(write, inaccessiblemem: readwrite) 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind allocsize(0) }

!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, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass