; 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_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: nounwind uwtable
declare hidden i32 @rl_zset_get_objects(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 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
declare hidden i32 @_rl_zrange(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i32 noundef, ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_zrevrangebylex(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, i64 noundef %7, i64 noundef %8, ptr noundef %9) #1 {
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i64, align 8
  %22 = alloca i64, align 8
  %23 = alloca ptr, align 8
  %24 = alloca i32, align 4
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %1, ptr %12, align 8, !tbaa !5
  store i64 %2, ptr %13, align 8, !tbaa !9
  store ptr %3, ptr %14, align 8, !tbaa !5
  store i64 %4, ptr %15, align 8, !tbaa !9
  store ptr %5, ptr %16, align 8, !tbaa !5
  store i64 %6, ptr %17, align 8, !tbaa !9
  store i64 %7, ptr %18, align 8, !tbaa !9
  store i64 %8, ptr %19, align 8, !tbaa !9
  store ptr %9, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #2
  %25 = load ptr, ptr %16, align 8, !tbaa !5
  %26 = load i64, ptr %17, align 8, !tbaa !9
  %27 = load ptr, ptr %14, align 8, !tbaa !5
  %28 = load i64, ptr %15, align 8, !tbaa !9
  %29 = call i32 @validate_lex_range(ptr noundef %25, i64 noundef %26, ptr noundef %27, i64 noundef %28)
  store i32 %29, ptr %24, align 4, !tbaa !11
  %30 = load i32, ptr %24, align 4, !tbaa !11
  %31 = icmp ne i32 0, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %10
  br label %81

33:                                               ; preds = %10
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = load i64, ptr %13, align 8, !tbaa !9
  %37 = call i32 @rl_zset_get_objects(ptr noundef %34, ptr noundef %35, i64 noundef %36, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef %23, ptr noundef null, i32 noundef 0, i32 noundef 0)
  store i32 %37, ptr %24, align 4, !tbaa !11
  %38 = load i32, ptr %24, align 4, !tbaa !11
  %39 = icmp ne i32 0, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %33
  br label %81

41:                                               ; preds = %33
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = load ptr, ptr %16, align 8, !tbaa !5
  %44 = load i64, ptr %17, align 8, !tbaa !9
  %45 = load ptr, ptr %14, align 8, !tbaa !5
  %46 = load i64, ptr %15, align 8, !tbaa !9
  %47 = load ptr, ptr %23, align 8, !tbaa !5
  %48 = call i32 @lex_get_range(ptr noundef %42, ptr noundef %43, i64 noundef %44, ptr noundef %45, i64 noundef %46, ptr noundef %47, ptr noundef %21, ptr noundef %22)
  store i32 %48, ptr %24, align 4, !tbaa !11
  %49 = load i32, ptr %24, align 4, !tbaa !11
  %50 = icmp ne i32 0, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %41
  br label %81

52:                                               ; preds = %41
  %53 = load i64, ptr %18, align 8, !tbaa !9
  %54 = load i64, ptr %22, align 8, !tbaa !9
  %55 = sub nsw i64 %54, %53
  store i64 %55, ptr %22, align 8, !tbaa !9
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load ptr, ptr %23, align 8, !tbaa !5
  %58 = load i64, ptr %21, align 8, !tbaa !9
  %59 = load i64, ptr %22, align 8, !tbaa !9
  %60 = load ptr, ptr %20, align 8, !tbaa !5
  %61 = call i32 @_rl_zrange(ptr noundef %56, ptr noundef %57, i64 noundef %58, i64 noundef %59, i32 noundef -1, ptr noundef %60)
  store i32 %61, ptr %24, align 4, !tbaa !11
  %62 = load i32, ptr %24, align 4, !tbaa !11
  %63 = icmp ne i32 0, %62
  br i1 %63, label %64, label %65

64:                                               ; preds = %52
  br label %81

65:                                               ; preds = %52
  %66 = load i64, ptr %19, align 8, !tbaa !9
  %67 = icmp sge i64 %66, 0
  br i1 %67, label %68, label %80

68:                                               ; preds = %65
  %69 = load ptr, ptr %20, align 8, !tbaa !5
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %70, i32 0, i32 5
  %72 = load i64, ptr %71, align 8, !tbaa !13
  %73 = load i64, ptr %19, align 8, !tbaa !9
  %74 = icmp sgt i64 %72, %73
  br i1 %74, label %75, label %80

75:                                               ; preds = %68
  %76 = load i64, ptr %19, align 8, !tbaa !9
  %77 = load ptr, ptr %20, align 8, !tbaa !5
  %78 = load ptr, ptr %77, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.rl_skiplist_iterator, ptr %78, i32 0, i32 5
  store i64 %76, ptr %79, align 8, !tbaa !13
  br label %80

80:                                               ; preds = %75, %68, %65
  br label %81

81:                                               ; preds = %80, %64, %51, %40, %32
  %82 = load i32, ptr %24, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #2
  ret i32 %82
}

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


; 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: nounwind uwtable
declare hidden i32 @rl_zset_get_objects(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_zrevrangebylex(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, i64 noundef %7, i64 noundef %8, ptr noundef %9) local_unnamed_addr #1 {
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %12) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %13) #2
  %14 = tail call i32 @validate_lex_range(ptr noundef %5, i64 noundef %6, ptr noundef %3, i64 noundef %4)
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %15, label %34

15:                                               ; preds = %10
  %16 = call i32 @rl_zset_get_objects(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef nonnull %13, ptr noundef null, i32 noundef 0, i32 noundef 0)
  %.not30 = icmp eq i32 %16, 0
  br i1 %.not30, label %17, label %34

17:                                               ; preds = %15
  %18 = load ptr, ptr %13, align 8, !tbaa !5
  %19 = call i32 @lex_get_range(ptr noundef %0, ptr noundef %5, i64 noundef %6, ptr noundef %3, i64 noundef %4, ptr noundef %18, ptr noundef nonnull %11, ptr noundef nonnull %12)
  %.not31 = icmp eq i32 %19, 0
  br i1 %.not31, label %20, label %34

20:                                               ; preds = %17
  %21 = load i64, ptr %12, align 8, !tbaa !9
  %22 = sub nsw i64 %21, %7
  store i64 %22, ptr %12, align 8, !tbaa !9
  %23 = load ptr, ptr %13, align 8, !tbaa !5
  %24 = load i64, ptr %11, align 8, !tbaa !9
  %25 = call i32 @_rl_zrange(ptr noundef %0, ptr noundef %23, i64 noundef %24, i64 noundef %22, i32 noundef -1, ptr noundef %9)
  %26 = icmp eq i32 %25, 0
  %27 = icmp sgt i64 %8, -1
  %or.cond = and i1 %27, %26
  br i1 %or.cond, label %28, label %34

28:                                               ; preds = %20
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 32
  %31 = load i64, ptr %30, align 8, !tbaa !11
  %32 = icmp sgt i64 %31, %8
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  store i64 %8, ptr %30, align 8, !tbaa !11
  br label %34

34:                                               ; preds = %28, %33, %20, %17, %15, %10
  %.0 = phi i32 [ %14, %10 ], [ %16, %15 ], [ %19, %17 ], [ 0, %33 ], [ 0, %28 ], [ %25, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #2
  ret i32 %.0
}

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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 32}
!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}


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