; 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_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 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [46 x i8], align 1

; 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
define dso_local i32 @rl_zset_iterator_next(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  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 ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %14 = load ptr, ptr %10, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %22

16:                                               ; preds = %5
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %22, label %19

19:                                               ; preds = %16
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str) #4
  store i32 6, ptr %6, align 4
  br label %69

22:                                               ; preds = %16, %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call i32 @rl_skiplist_iterator_next(ptr noundef %23, ptr noundef %12)
  store i32 %24, ptr %13, align 4, !tbaa !9
  %25 = load i32, ptr %13, align 4, !tbaa !9
  %26 = icmp ne i32 0, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  br label %67

28:                                               ; preds = %22
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %36

31:                                               ; preds = %28
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.rl_skiplist_node, ptr %32, i32 0, i32 0
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %34, ptr %35, align 8, !tbaa !11
  br label %36

36:                                               ; preds = %31, %28
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %58

39:                                               ; preds = %36
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.rl_skiplist_node, ptr %43, i32 0, i32 0
  %45 = load i64, ptr %44, align 8, !tbaa !11
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = call i32 @rl_multi_string_get(ptr noundef %42, i64 noundef %45, ptr noundef %46, ptr noundef %47)
  store i32 %48, ptr %13, align 4, !tbaa !9
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %57

51:                                               ; preds = %39
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = call i32 @rl_skiplist_iterator_destroy(ptr noundef %54, ptr noundef %55)
  br label %67

57:                                               ; preds = %39
  br label %58

58:                                               ; preds = %57, %36
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %66

61:                                               ; preds = %58
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.rl_skiplist_node, ptr %62, i32 0, i32 1
  %64 = load double, ptr %63, align 8, !tbaa !15
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  store double %64, ptr %65, align 8, !tbaa !15
  br label %66

66:                                               ; preds = %61, %58
  br label %67

67:                                               ; preds = %66, %51, %27
  %68 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %68, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %69

69:                                               ; preds = %67, %19
  %70 = load i32, ptr %6, align 4
  ret i32 %70
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

declare i32 @rl_skiplist_iterator_next(ptr noundef, ptr noundef) #3

declare i32 @rl_multi_string_get(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #3

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

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


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [46 x i8], align 1

; 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
define dso_local i32 @rl_zset_iterator_next(ptr noundef %0, ptr noundef writeonly %1, ptr noundef writeonly %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = alloca ptr, align 8
  %7 = icmp eq ptr %3, null
  %8 = icmp ne ptr %4, null
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %12, label %9

9:                                                ; preds = %5
  %10 = load ptr, ptr @stderr, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str) #4
  br label %33

12:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  %13 = call i32 @rl_skiplist_iterator_next(ptr noundef %0, ptr noundef nonnull %6) #5
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %14, label %32

14:                                               ; preds = %12
  %.not25 = icmp eq ptr %1, null
  br i1 %.not25, label %18, label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load i64, ptr %16, align 8, !tbaa !9
  store i64 %17, ptr %1, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %15, %14
  br i1 %8, label %19, label %27

19:                                               ; preds = %18
  %20 = load ptr, ptr %0, align 8, !tbaa !11
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = call i32 @rl_multi_string_get(ptr noundef %20, i64 noundef %22, ptr noundef %3, ptr noundef nonnull %4) #5
  %.not26 = icmp eq i32 %23, 0
  br i1 %.not26, label %27, label %24

24:                                               ; preds = %19
  %25 = load ptr, ptr %0, align 8, !tbaa !11
  %26 = call i32 @rl_skiplist_iterator_destroy(ptr noundef %25, ptr noundef nonnull %0) #5
  br label %32

27:                                               ; preds = %19, %18
  %.not27 = icmp eq ptr %2, null
  br i1 %.not27, label %32, label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  %31 = load double, ptr %30, align 8, !tbaa !14
  store double %31, ptr %2, align 8, !tbaa !14
  br label %32

32:                                               ; preds = %27, %28, %12, %24
  %.1 = phi i32 [ %13, %12 ], [ %23, %24 ], [ 0, %28 ], [ 0, %27 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  br label %33

33:                                               ; preds = %32, %9
  %.017 = phi i32 [ %.1, %32 ], [ 6, %9 ]
  ret i32 %.017
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare i32 @rl_skiplist_iterator_next(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @rl_multi_string_get(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

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 = { nofree nounwind "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 = { "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 #4 = { cold nounwind }
attributes #5 = { 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, !6, i64 0}
!12 = !{!"rl_skiplist_iterator", !6, i64 0, !6, i64 8, !10, i64 16, !13, i64 24, !13, i64 28, !10, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass