; 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.rlite = type { i64, i64, i32, ptr, i64, i64, i64, ptr, i32, i32, i32, i32, ptr, i64, i64, ptr, i64, i64, 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: nounwind uwtable
declare dso_local i32 @rl_skiplist_malloc(ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_skiplist_create(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call i32 @rl_skiplist_malloc(ptr noundef %8, ptr noundef %9)
  store i32 %10, ptr %5, align 4, !tbaa !9
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp ne i32 0, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  br label %55

14:                                               ; preds = %2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.rlite, ptr %15, i32 0, i32 5
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.rl_skiplist, ptr %19, i32 0, i32 0
  store i64 %17, ptr %20, align 8, !tbaa !14
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call i32 @rl_skiplist_node_create(ptr noundef %21, ptr noundef %6, i64 noundef 32, double noundef 0.000000e+00, i64 noundef 0)
  store i32 %22, ptr %5, align 4, !tbaa !9
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = icmp ne i32 0, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %14
  br label %55

26:                                               ; preds = %14
  store i64 0, ptr %7, align 8, !tbaa !16
  br label %27

27:                                               ; preds = %41, %26
  %28 = load i64, ptr %7, align 8, !tbaa !16
  %29 = icmp slt i64 %28, 32
  br i1 %29, label %30, label %44

30:                                               ; preds = %27
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.rl_skiplist_node, ptr %31, i32 0, i32 4
  %33 = load i64, ptr %7, align 8, !tbaa !16
  %34 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %32, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %34, i32 0, i32 0
  store i64 0, ptr %35, align 8, !tbaa !17
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.rl_skiplist_node, ptr %36, i32 0, i32 4
  %38 = load i64, ptr %7, align 8, !tbaa !16
  %39 = getelementptr inbounds [0 x %struct.rl_skiplist_node_level], ptr %37, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.rl_skiplist_node_level, ptr %39, i32 0, i32 1
  store i64 0, ptr %40, align 8, !tbaa !19
  br label %41

41:                                               ; preds = %30
  %42 = load i64, ptr %7, align 8, !tbaa !16
  %43 = add nsw i64 %42, 1
  store i64 %43, ptr %7, align 8, !tbaa !16
  br label %27, !llvm.loop !20

44:                                               ; preds = %27
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.rlite, ptr %46, i32 0, i32 5
  %48 = load i64, ptr %47, align 8, !tbaa !11
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = call i32 @rl_write(ptr noundef %45, ptr noundef @rl_data_type_skiplist_node, i64 noundef %48, ptr noundef %49)
  store i32 %50, ptr %5, align 4, !tbaa !9
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = icmp ne i32 0, %51
  br i1 %52, label %53, label %54

53:                                               ; preds = %44
  br label %55

54:                                               ; preds = %44
  br label %55

55:                                               ; preds = %54, %53, %25, %13
  %56 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %56
}

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

declare i32 @rl_write(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 40}
!12 = !{!"rlite", !13, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !6, i64 80, !13, i64 88, !13, i64 96, !6, i64 104, !13, i64 112, !13, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!16 = !{!13, !13, i64 0}
!17 = !{!18, !13, i64 0}
!18 = !{!"rl_skiplist_node_level", !13, i64 0, !13, i64 8}
!19 = !{!18, !13, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"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 }

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_skiplist_malloc(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_skiplist_create(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  %4 = tail call i32 @rl_skiplist_malloc(ptr noundef %0, ptr noundef %1)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %14

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %1, align 8, !tbaa !12
  store i64 %7, ptr %8, align 8, !tbaa !13
  %9 = call i32 @rl_skiplist_node_create(ptr noundef %0, ptr noundef nonnull %3, i64 noundef 32, double noundef 0.000000e+00, i64 noundef 0)
  %.not16 = icmp eq i32 %9, 0
  br i1 %.not16, label %.preheader, label %14

.preheader:                                       ; preds = %5
  %10 = load ptr, ptr %3, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %10, i64 32
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(512) %11, i8 0, i64 512, i1 false), !tbaa !15
  %12 = load i64, ptr %6, align 8, !tbaa !5
  %13 = call i32 @rl_write(ptr noundef nonnull %0, ptr noundef nonnull @rl_data_type_skiplist_node, i64 noundef %12, ptr noundef %10) #3
  br label %14

14:                                               ; preds = %.preheader, %5, %2
  %.013 = phi i32 [ %4, %2 ], [ %9, %5 ], [ %13, %.preheader ]
  ret i32 %.013
}

; 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 #0

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

; 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 = { 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 #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: write) }
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 40}
!6 = !{!"rlite", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !11, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !11, i64 80, !7, i64 88, !7, i64 96, !11, i64 104, !7, i64 112, !7, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!15 = !{!7, !7, i64 0}


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