; LLVM IR from seppo0010/rlite :: src (type_zset)

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

@rl_data_type_list_long = external global %struct.rl_data_type, align 8
@rl_list_type_long = external global %struct.rl_list_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_skiplist_iterator_next(ptr noundef, ptr noundef) #1

declare i32 @rl_skiplist_iterator_destroy(ptr noundef, ptr noundef) #1

declare i32 @rl_skiplist_iterator_create(ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef, i32 noundef) #1

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

21:                                               ; preds = %3
  br label %91

22:                                               ; preds = %3
  %23 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %23, ptr %15, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load ptr, ptr %15, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = call i32 @rl_list_pages(ptr noundef %24, ptr noundef %25, ptr noundef %26)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr %5, align 8, !tbaa !9
  %30 = call i32 @rl_zset_read(ptr noundef %28, i64 noundef %29, ptr noundef %7, ptr noundef %11, ptr noundef %8, ptr noundef %12)
  store i32 %30, ptr %13, align 4, !tbaa !11
  %31 = load i32, ptr %13, align 4, !tbaa !11
  %32 = icmp ne i32 0, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %22
  br label %91

34:                                               ; preds = %22
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i64, ptr %11, align 8, !tbaa !9
  %37 = getelementptr inbounds i16, ptr %35, i64 %36
  store i16 1, ptr %37, align 2, !tbaa !13
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i64, ptr %12, align 8, !tbaa !9
  %40 = getelementptr inbounds i16, ptr %38, i64 %39
  store i16 1, ptr %40, align 2, !tbaa !13
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = call i32 @rl_btree_pages(ptr noundef %41, ptr noundef %42, ptr noundef %43)
  store i32 %44, ptr %13, align 4, !tbaa !11
  %45 = load i32, ptr %13, align 4, !tbaa !11
  %46 = icmp ne i32 0, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %34
  br label %91

48:                                               ; preds = %34
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = call i32 @rl_skiplist_pages(ptr noundef %49, ptr noundef %50, ptr noundef %51)
  store i32 %52, ptr %13, align 4, !tbaa !11
  %53 = load i32, ptr %13, align 4, !tbaa !11
  %54 = icmp ne i32 0, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %48
  br label %91

56:                                               ; preds = %48
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = call i32 @rl_skiplist_iterator_create(ptr noundef %57, ptr noundef %9, ptr noundef %58, i64 noundef 0, i32 noundef 1, i32 noundef 0)
  store i32 %59, ptr %13, align 4, !tbaa !11
  %60 = load i32, ptr %13, align 4, !tbaa !11
  %61 = icmp ne i32 0, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %56
  br label %91

63:                                               ; preds = %56
  br label %64

64:                                               ; preds = %85, %63
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = call i32 @rl_skiplist_iterator_next(ptr noundef %65, ptr noundef %10)
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %86

68:                                               ; preds = %64
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.rl_skiplist_node, ptr %70, i32 0, i32 0
  %72 = load i64, ptr %71, align 8, !tbaa !9
  %73 = getelementptr inbounds i16, ptr %69, i64 %72
  store i16 1, ptr %73, align 2, !tbaa !13
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !15
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.rl_skiplist_node, ptr %77, i32 0, i32 0
  %79 = load i64, ptr %78, align 8, !tbaa !9
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = call i32 @rl_multi_string_pages(ptr noundef %76, i64 noundef %79, ptr noundef %80)
  store i32 %81, ptr %13, align 4, !tbaa !11
  %82 = load i32, ptr %13, align 4, !tbaa !11
  %83 = icmp ne i32 0, %82
  br i1 %83, label %84, label %85

84:                                               ; preds = %68
  br label %91

85:                                               ; preds = %68
  br label %64, !llvm.loop !17

86:                                               ; preds = %64
  store ptr null, ptr %9, align 8, !tbaa !5
  %87 = load i32, ptr %13, align 4, !tbaa !11
  %88 = icmp ne i32 %87, 9
  br i1 %88, label %89, label %90

89:                                               ; preds = %86
  br label %91

90:                                               ; preds = %86
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %91

91:                                               ; preds = %90, %89, %84, %62, %55, %47, %33, %21
  %92 = load i32, ptr %13, align 4, !tbaa !11
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %102

94:                                               ; preds = %91
  %95 = load ptr, ptr %9, align 8, !tbaa !5
  %96 = icmp ne ptr %95, null
  br i1 %96, label %97, label %101

97:                                               ; preds = %94
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  %100 = call i32 @rl_skiplist_iterator_destroy(ptr noundef %98, ptr noundef %99)
  br label %101

101:                                              ; preds = %97, %94
  br label %102

102:                                              ; preds = %101, %91
  %103 = load i32, ptr %13, align 4, !tbaa !11
  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 4, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i32 %103
}

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

declare i32 @rl_list_pages(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @rl_zset_read(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @rl_btree_pages(ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @rl_skiplist_pages(ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @rl_multi_string_pages(ptr noundef, i64 noundef, ptr noundef) #1

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

@rl_data_type_list_long = external global %struct.rl_data_type, align 8
@rl_list_type_long = external global %struct.rl_list_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_skiplist_iterator_next(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @rl_skiplist_iterator_destroy(ptr noundef, ptr noundef) local_unnamed_addr #1

declare 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
define dso_local i32 @rl_zset_pages(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #3
  %11 = call i32 @rl_read(ptr noundef %0, ptr noundef nonnull @rl_data_type_list_long, i64 noundef %1, ptr noundef nonnull @rl_list_type_long, ptr noundef nonnull %10, i32 noundef 1) #3
  %.not = icmp eq i32 %11, 2
  br i1 %.not, label %12, label %.loopexit

12:                                               ; preds = %3
  %13 = load ptr, ptr %10, align 8, !tbaa !5
  %14 = call i32 @rl_list_pages(ptr noundef %0, ptr noundef %13, ptr noundef %2) #3
  %15 = call i32 @rl_zset_read(ptr noundef %0, i64 noundef %1, ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull %5, ptr noundef nonnull %9)
  %.not35 = icmp eq i32 %15, 0
  br i1 %.not35, label %16, label %.loopexit

16:                                               ; preds = %12
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = getelementptr inbounds i16, ptr %2, i64 %17
  store i16 1, ptr %18, align 2, !tbaa !11
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = getelementptr inbounds i16, ptr %2, i64 %19
  store i16 1, ptr %20, align 2, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call i32 @rl_btree_pages(ptr noundef %0, ptr noundef %21, ptr noundef %2) #3
  %.not36 = icmp eq i32 %22, 0
  br i1 %.not36, label %23, label %.loopexit

23:                                               ; preds = %16
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call i32 @rl_skiplist_pages(ptr noundef %0, ptr noundef %24, ptr noundef nonnull %2) #3
  %.not37 = icmp eq i32 %25, 0
  br i1 %.not37, label %26, label %.loopexit

26:                                               ; preds = %23
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = call i32 @rl_skiplist_iterator_create(ptr noundef %0, ptr noundef nonnull %6, ptr noundef %27, i64 noundef 0, i32 noundef 1, i32 noundef 0) #3
  %.not38 = icmp eq i32 %28, 0
  br i1 %.not38, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %26, %32
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call i32 @rl_skiplist_iterator_next(ptr noundef %29, ptr noundef nonnull %7) #3
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %.thread

32:                                               ; preds = %.preheader
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds i16, ptr %2, i64 %34
  store i16 1, ptr %35, align 2, !tbaa !11
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = call i32 @rl_multi_string_pages(ptr noundef %37, i64 noundef %34, ptr noundef nonnull %2) #3
  %.not39 = icmp eq i32 %38, 0
  br i1 %.not39, label %.preheader, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %32, %26, %23, %16, %12, %3
  %.1 = phi i32 [ %11, %3 ], [ %15, %12 ], [ %22, %16 ], [ %25, %23 ], [ %28, %26 ], [ %38, %32 ]
  %39 = icmp ne i32 %.1, 0
  %40 = load ptr, ptr %6, align 8
  %41 = icmp ne ptr %40, null
  %or.cond = select i1 %39, i1 %41, i1 false
  br i1 %or.cond, label %42, label %.thread

42:                                               ; preds = %.loopexit
  %43 = call i32 @rl_skiplist_iterator_destroy(ptr noundef %0, ptr noundef nonnull %40) #3
  br label %.thread

.thread:                                          ; preds = %.preheader, %42, %.loopexit
  %.142 = phi i32 [ %.1, %42 ], [ %.1, %.loopexit ], [ 0, %.preheader ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret i32 %.142
}

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

declare i32 @rl_list_pages(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @rl_zset_read(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @rl_btree_pages(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @rl_skiplist_pages(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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


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