; 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 = type { i64, i64, i64, i64 }
%struct.rl_skiplist_iterator = type { ptr, ptr, i64, i32, i32, 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_iterator_create(ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef) #1

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

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

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

14:                                               ; preds = %3
  br label %47

15:                                               ; preds = %3
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.rl_skiplist, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds i16, ptr %16, i64 %19
  store i16 1, ptr %20, align 2, !tbaa !14
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.rl_skiplist, ptr %22, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !16
  %25 = getelementptr inbounds i16, ptr %21, i64 %24
  store i16 1, ptr %25, align 2, !tbaa !14
  br label %26

26:                                               ; preds = %38, %15
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %27, i32 0, i32 2
  %29 = load i64, ptr %28, align 8, !tbaa !17
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %31, label %37

31:                                               ; preds = %26
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %33, i32 0, i32 2
  %35 = load i64, ptr %34, align 8, !tbaa !17
  %36 = getelementptr inbounds i16, ptr %32, i64 %35
  store i16 1, ptr %36, align 2, !tbaa !14
  br label %37

37:                                               ; preds = %31, %26
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = call i32 @rl_skiplist_iterator_next(ptr noundef %39, ptr noundef null)
  store i32 %40, ptr %7, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %26, label %42, !llvm.loop !19

42:                                               ; preds = %38
  store ptr null, ptr %8, align 8, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = icmp ne i32 %43, 9
  br i1 %44, label %45, label %46

45:                                               ; preds = %42
  br label %47

46:                                               ; preds = %42
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %46, %45, %14
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %54

50:                                               ; preds = %47
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = call i32 @rl_skiplist_iterator_destroy(ptr noundef %51, ptr noundef %52)
  br label %54

54:                                               ; preds = %50, %47
  %55 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %55
}

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 = { 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 8}
!12 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!12, !13, i64 0}
!17 = !{!18, !13, i64 16}
!18 = !{!"rl_skiplist_iterator", !6, i64 0, !6, i64 8, !13, i64 16, !10, i64 24, !10, i64 28, !13, i64 32}
!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"

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_skiplist_pages(ptr noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  store ptr null, ptr %4, align 8, !tbaa !5
  %5 = call i32 @rl_skiplist_iterator_create(ptr noundef %0, ptr noundef nonnull %4, ptr noundef %1, i64 noundef 0, i32 noundef 1, i32 noundef 0)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %._crit_edge

._crit_edge:                                      ; preds = %3
  %.pre = load ptr, ptr %4, align 8, !tbaa !5
  br label %22

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds i16, ptr %2, i64 %8
  store i16 1, ptr %9, align 2, !tbaa !12
  %10 = load i64, ptr %1, align 8, !tbaa !14
  %11 = getelementptr inbounds i16, ptr %2, i64 %10
  store i16 1, ptr %11, align 2, !tbaa !12
  br label %12

12:                                               ; preds = %18, %6
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %15 = load i64, ptr %14, align 8, !tbaa !15
  %.not14 = icmp eq i64 %15, 0
  br i1 %.not14, label %18, label %16

16:                                               ; preds = %12
  %17 = getelementptr inbounds i16, ptr %2, i64 %15
  store i16 1, ptr %17, align 2, !tbaa !12
  br label %18

18:                                               ; preds = %12, %16
  %19 = call i32 @rl_skiplist_iterator_next(ptr noundef nonnull %13, ptr noundef null)
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %12, label %21, !llvm.loop !18

21:                                               ; preds = %18
  store ptr null, ptr %4, align 8, !tbaa !5
  %.not15 = icmp eq i32 %19, 9
  br i1 %.not15, label %25, label %22

22:                                               ; preds = %._crit_edge, %21
  %23 = phi ptr [ null, %21 ], [ %.pre, %._crit_edge ]
  %.0.ph = phi i32 [ %19, %21 ], [ %5, %._crit_edge ]
  %24 = call i32 @rl_skiplist_iterator_destroy(ptr noundef %0, ptr noundef %23)
  br label %25

25:                                               ; preds = %21, %22
  %.020 = phi i32 [ %.0.ph, %22 ], [ 0, %21 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  ret i32 %.020
}

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 = { 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, !11, i64 8}
!10 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !11, i64 0}
!15 = !{!16, !11, i64 16}
!16 = !{!"rl_skiplist_iterator", !6, i64 0, !6, i64 8, !11, i64 16, !17, i64 24, !17, i64 28, !11, i64 32}
!17 = !{!"int", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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