; 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_iterator = type { ptr, ptr, i64, i32, i32, i64 }
%struct.rl_skiplist = type { i64, i64, 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_iterator_create(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4, i32 noundef %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !11
  store i32 %5, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %15 = call noalias ptr @malloc(i64 noundef 40) #4
  store ptr %15, ptr %14, align 8, !tbaa !5
  %16 = load ptr, ptr %14, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %6
  store i32 4, ptr %13, align 4, !tbaa !11
  br label %88

19:                                               ; preds = %6
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %14, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %21, i32 0, i32 0
  store ptr %20, ptr %22, align 8, !tbaa !13
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load ptr, ptr %14, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %24, i32 0, i32 1
  store ptr %23, ptr %25, align 8, !tbaa !15
  %26 = load i32, ptr %11, align 4, !tbaa !11
  %27 = icmp eq i32 %26, -1
  br i1 %27, label %28, label %31

28:                                               ; preds = %19
  %29 = load ptr, ptr %14, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %29, i32 0, i32 3
  store i32 -1, ptr %30, align 8, !tbaa !16
  br label %34

31:                                               ; preds = %19
  %32 = load ptr, ptr %14, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %32, i32 0, i32 3
  store i32 1, ptr %33, align 8, !tbaa !16
  br label %34

34:                                               ; preds = %31, %28
  %35 = load i64, ptr %10, align 8, !tbaa !9
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %41

37:                                               ; preds = %34
  %38 = load i64, ptr %10, align 8, !tbaa !9
  %39 = load ptr, ptr %14, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %39, i32 0, i32 2
  store i64 %38, ptr %40, align 8, !tbaa !17
  br label %69

41:                                               ; preds = %34
  %42 = load ptr, ptr %14, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %42, i32 0, i32 3
  %44 = load i32, ptr %43, align 8, !tbaa !16
  %45 = icmp eq i32 %44, 1
  br i1 %45, label %46, label %62

46:                                               ; preds = %41
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.rl_skiplist, ptr %47, i32 0, i32 0
  %49 = load i64, ptr %48, align 8, !tbaa !18
  %50 = load ptr, ptr %14, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %50, i32 0, i32 2
  store i64 %49, ptr %51, align 8, !tbaa !17
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %52, i32 0, i32 5
  store i64 1, ptr %53, align 8, !tbaa !20
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %54, i32 0, i32 4
  store i32 0, ptr %55, align 4, !tbaa !21
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = call i32 @rl_skiplist_iterator_next(ptr noundef %56, ptr noundef null)
  store i32 %57, ptr %13, align 4, !tbaa !11
  %58 = load i32, ptr %13, align 4, !tbaa !11
  %59 = icmp ne i32 0, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %46
  br label %88

61:                                               ; preds = %46
  br label %68

62:                                               ; preds = %41
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.rl_skiplist, ptr %63, i32 0, i32 1
  %65 = load i64, ptr %64, align 8, !tbaa !22
  %66 = load ptr, ptr %14, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %66, i32 0, i32 2
  store i64 %65, ptr %67, align 8, !tbaa !17
  br label %68

68:                                               ; preds = %62, %61
  br label %69

69:                                               ; preds = %68, %37
  %70 = load i32, ptr %12, align 4, !tbaa !11
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %77

72:                                               ; preds = %69
  %73 = load i32, ptr %12, align 4, !tbaa !11
  %74 = sext i32 %73 to i64
  %75 = load ptr, ptr %14, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %75, i32 0, i32 5
  store i64 %74, ptr %76, align 8, !tbaa !20
  br label %83

77:                                               ; preds = %69
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.rl_skiplist, ptr %78, i32 0, i32 2
  %80 = load i64, ptr %79, align 8, !tbaa !23
  %81 = load ptr, ptr %14, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %81, i32 0, i32 5
  store i64 %80, ptr %82, align 8, !tbaa !20
  br label %83

83:                                               ; preds = %77, %72
  %84 = load ptr, ptr %14, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %84, i32 0, i32 4
  store i32 0, ptr %85, align 4, !tbaa !21
  %86 = load ptr, ptr %14, align 8, !tbaa !5
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %86, ptr %87, align 8, !tbaa !5
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %88

88:                                               ; preds = %83, %60, %18
  %89 = load i32, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret i32 %89
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_skiplist_iterator_next(ptr noundef, ptr noundef) #2

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 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"rl_skiplist_iterator", !6, i64 0, !6, i64 8, !10, i64 16, !12, i64 24, !12, i64 28, !10, i64 32}
!15 = !{!14, !6, i64 8}
!16 = !{!14, !12, i64 24}
!17 = !{!14, !10, i64 16}
!18 = !{!19, !10, i64 0}
!19 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!20 = !{!14, !10, i64 32}
!21 = !{!14, !12, i64 28}
!22 = !{!19, !10, i64 8}
!23 = !{!19, !10, i64 16}


; 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: nounwind uwtable
define dso_local i32 @rl_skiplist_iterator_create(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2, i64 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #1 {
  %7 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #2
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %31, label %8

8:                                                ; preds = %6
  store ptr %0, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  store ptr %2, ptr %9, align 8, !tbaa !12
  %.not36 = icmp eq i32 %4, -1
  %10 = getelementptr inbounds i8, ptr %7, i64 24
  %.not32 = icmp eq i64 %3, 0
  br i1 %.not36, label %11, label %.thread

11:                                               ; preds = %8
  store i32 -1, ptr %10, align 8
  br i1 %.not32, label %18, label %.sink.split

.thread:                                          ; preds = %8
  store i32 1, ptr %10, align 8
  br i1 %.not32, label %12, label %.sink.split

12:                                               ; preds = %.thread
  %13 = load i64, ptr %2, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %7, i64 16
  store i64 %13, ptr %14, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %7, i64 32
  store i64 1, ptr %15, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %7, i64 28
  store i32 0, ptr %16, align 4, !tbaa !17
  %17 = tail call i32 @rl_skiplist_iterator_next(ptr noundef nonnull %7, ptr noundef null)
  %.not33 = icmp eq i32 %17, 0
  br i1 %.not33, label %22, label %31

18:                                               ; preds = %11
  %19 = getelementptr inbounds i8, ptr %2, i64 8
  %20 = load i64, ptr %19, align 8, !tbaa !18
  br label %.sink.split

.sink.split:                                      ; preds = %11, %.thread, %18
  %.sink = phi i64 [ %20, %18 ], [ %3, %.thread ], [ %3, %11 ]
  %21 = getelementptr inbounds i8, ptr %7, i64 16
  store i64 %.sink, ptr %21, align 8, !tbaa !15
  br label %22

22:                                               ; preds = %.sink.split, %12
  %.not34 = icmp eq i32 %5, 0
  br i1 %.not34, label %25, label %23

23:                                               ; preds = %22
  %24 = sext i32 %5 to i64
  br label %28

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %2, i64 16
  %27 = load i64, ptr %26, align 8, !tbaa !19
  br label %28

28:                                               ; preds = %25, %23
  %.sink35 = phi i64 [ %27, %25 ], [ %24, %23 ]
  %29 = getelementptr inbounds i8, ptr %7, i64 32
  store i64 %.sink35, ptr %29, align 8
  %30 = getelementptr inbounds i8, ptr %7, i64 28
  store i32 0, ptr %30, align 4, !tbaa !17
  store ptr %7, ptr %1, align 8, !tbaa !20
  br label %31

31:                                               ; preds = %6, %12, %28
  %.0 = phi i32 [ 0, %28 ], [ %17, %12 ], [ 4, %6 ]
  ret i32 %.0
}

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

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 = { 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 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, !7, i64 0}
!6 = !{!"rl_skiplist_iterator", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !11, i64 28, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!15 = !{!6, !10, i64 16}
!16 = !{!6, !10, i64 32}
!17 = !{!6, !11, i64 28}
!18 = !{!14, !10, i64 8}
!19 = !{!14, !10, i64 16}
!20 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass