; 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 = 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 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
define dso_local i32 @rl_zlexcount(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7) #1 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, 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 ptr, align 8
  %20 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i64 %2, ptr %11, align 8, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store i64 %4, ptr %13, align 8, !tbaa !9
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i64 %6, ptr %15, align 8, !tbaa !9
  store ptr %7, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #2
  %21 = load ptr, ptr %12, align 8, !tbaa !5
  %22 = load i64, ptr %13, align 8, !tbaa !9
  %23 = load ptr, ptr %14, align 8, !tbaa !5
  %24 = load i64, ptr %15, align 8, !tbaa !9
  %25 = call i32 @validate_lex_range(ptr noundef %21, i64 noundef %22, ptr noundef %23, i64 noundef %24)
  store i32 %25, ptr %20, align 4, !tbaa !11
  %26 = load i32, ptr %20, align 4, !tbaa !11
  %27 = icmp ne i32 0, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %8
  br label %70

29:                                               ; preds = %8
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = load i64, ptr %11, align 8, !tbaa !9
  %33 = call i32 @rl_zset_get_objects(ptr noundef %30, ptr noundef %31, i64 noundef %32, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef %19, ptr noundef null, i32 noundef 0, i32 noundef 0)
  store i32 %33, ptr %20, align 4, !tbaa !11
  %34 = load i32, ptr %20, align 4, !tbaa !11
  %35 = icmp ne i32 0, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %29
  br label %70

37:                                               ; preds = %29
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = load i64, ptr %13, align 8, !tbaa !9
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  %42 = load i64, ptr %15, align 8, !tbaa !9
  %43 = load ptr, ptr %19, align 8, !tbaa !5
  %44 = call i32 @lex_get_range(ptr noundef %38, ptr noundef %39, i64 noundef %40, ptr noundef %41, i64 noundef %42, ptr noundef %43, ptr noundef %17, ptr noundef %18)
  store i32 %44, ptr %20, align 4, !tbaa !11
  %45 = load i32, ptr %20, align 4, !tbaa !11
  %46 = icmp ne i32 0, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %37
  br label %70

48:                                               ; preds = %37
  %49 = load i64, ptr %18, align 8, !tbaa !9
  %50 = icmp slt i64 %49, 0
  br i1 %50, label %51, label %57

51:                                               ; preds = %48
  %52 = load ptr, ptr %19, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.rl_skiplist, ptr %52, i32 0, i32 2
  %54 = load i64, ptr %53, align 8, !tbaa !13
  %55 = load i64, ptr %18, align 8, !tbaa !9
  %56 = add nsw i64 %55, %54
  store i64 %56, ptr %18, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %51, %48
  %58 = load i64, ptr %18, align 8, !tbaa !9
  %59 = load i64, ptr %17, align 8, !tbaa !9
  %60 = icmp sge i64 %58, %59
  br i1 %60, label %61, label %67

61:                                               ; preds = %57
  %62 = load i64, ptr %18, align 8, !tbaa !9
  %63 = load i64, ptr %17, align 8, !tbaa !9
  %64 = sub nsw i64 %62, %63
  %65 = add nsw i64 %64, 1
  %66 = load ptr, ptr %16, align 8, !tbaa !5
  store i64 %65, ptr %66, align 8, !tbaa !9
  br label %69

67:                                               ; preds = %57
  %68 = load ptr, ptr %16, align 8, !tbaa !5
  store i64 0, ptr %68, align 8, !tbaa !9
  br label %69

69:                                               ; preds = %67, %61
  store i32 0, ptr %20, align 4, !tbaa !11
  br label %70

70:                                               ; preds = %69, %47, %36, %28
  %71 = load i32, ptr %20, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #2
  ret i32 %71
}

; 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

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 16}
!14 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}


; 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
define dso_local i32 @rl_zlexcount(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr nocapture noundef writeonly %7) local_unnamed_addr #1 {
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #2
  %12 = tail call i32 @validate_lex_range(ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6)
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %31

13:                                               ; preds = %8
  %14 = 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 %11, ptr noundef null, i32 noundef 0, i32 noundef 0)
  %.not23 = icmp eq i32 %14, 0
  br i1 %.not23, label %15, label %31

15:                                               ; preds = %13
  %16 = load ptr, ptr %11, align 8, !tbaa !5
  %17 = call i32 @lex_get_range(ptr noundef %0, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %16, ptr noundef nonnull %9, ptr noundef nonnull %10)
  %.not24 = icmp eq i32 %17, 0
  br i1 %.not24, label %18, label %31

18:                                               ; preds = %15
  %19 = load i64, ptr %10, align 8, !tbaa !9
  %20 = icmp slt i64 %19, 0
  br i1 %20, label %21, label %26

21:                                               ; preds = %18
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = add nsw i64 %24, %19
  br label %26

26:                                               ; preds = %21, %18
  %27 = phi i64 [ %25, %21 ], [ %19, %18 ]
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %.not25 = icmp slt i64 %27, %28
  %29 = add i64 %27, 1
  %30 = sub i64 %29, %28
  %storemerge = select i1 %.not25, i64 0, i64 %30
  store i64 %storemerge, ptr %7, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %15, %13, %8, %26
  %.0 = phi i32 [ %12, %8 ], [ %14, %13 ], [ %17, %15 ], [ 0, %26 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #2
  ret i32 %.0
}

; 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

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 16}
!12 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass