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

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

29:                                               ; preds = %7
  br label %83

30:                                               ; preds = %7
  store i64 0, ptr %22, align 8, !tbaa !9
  store i64 0, ptr %21, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %77, %30
  %32 = load i64, ptr %21, align 8, !tbaa !9
  %33 = load i64, ptr %11, align 8, !tbaa !9
  %34 = icmp slt i64 %32, %33
  br i1 %34, label %35, label %80

35:                                               ; preds = %31
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load i64, ptr %10, align 8, !tbaa !9
  %39 = load i64, ptr %19, align 8, !tbaa !9
  %40 = load ptr, ptr %15, align 8, !tbaa !5
  %41 = load i64, ptr %17, align 8, !tbaa !9
  %42 = load ptr, ptr %16, align 8, !tbaa !5
  %43 = load i64, ptr %18, align 8, !tbaa !9
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = load i64, ptr %21, align 8, !tbaa !9
  %46 = getelementptr inbounds ptr, ptr %44, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = load ptr, ptr %13, align 8, !tbaa !5
  %49 = load i64, ptr %21, align 8, !tbaa !9
  %50 = getelementptr inbounds i64, ptr %48, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !9
  %52 = call i32 @remove_member(ptr noundef %36, ptr noundef %37, i64 noundef %38, i64 noundef %39, ptr noundef %40, i64 noundef %41, ptr noundef %42, i64 noundef %43, ptr noundef %47, i64 noundef %51)
  store i32 %52, ptr %20, align 4, !tbaa !11
  %53 = load i32, ptr %20, align 4, !tbaa !11
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %62

55:                                               ; preds = %35
  %56 = load i32, ptr %20, align 4, !tbaa !11
  %57 = icmp ne i32 %56, 3
  br i1 %57, label %58, label %62

58:                                               ; preds = %55
  %59 = load i32, ptr %20, align 4, !tbaa !11
  %60 = icmp ne i32 %59, 10
  br i1 %60, label %61, label %62

61:                                               ; preds = %58
  br label %83

62:                                               ; preds = %58, %55, %35
  %63 = load i32, ptr %20, align 4, !tbaa !11
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %68, label %65

65:                                               ; preds = %62
  %66 = load i32, ptr %20, align 4, !tbaa !11
  %67 = icmp eq i32 %66, 10
  br i1 %67, label %68, label %75

68:                                               ; preds = %65, %62
  %69 = load i64, ptr %22, align 8, !tbaa !9
  %70 = add nsw i64 %69, 1
  store i64 %70, ptr %22, align 8, !tbaa !9
  %71 = load i32, ptr %20, align 4, !tbaa !11
  %72 = icmp eq i32 %71, 10
  br i1 %72, label %73, label %74

73:                                               ; preds = %68
  br label %80

74:                                               ; preds = %68
  br label %75

75:                                               ; preds = %74, %65
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  %78 = load i64, ptr %21, align 8, !tbaa !9
  %79 = add nsw i64 %78, 1
  store i64 %79, ptr %21, align 8, !tbaa !9
  br label %31, !llvm.loop !13

80:                                               ; preds = %73, %31
  %81 = load i64, ptr %22, align 8, !tbaa !9
  %82 = load ptr, ptr %14, align 8, !tbaa !5
  store i64 %81, ptr %82, align 8, !tbaa !9
  store i32 0, ptr %20, align 4, !tbaa !11
  br label %83

83:                                               ; preds = %80, %61, %29
  %84 = 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  ret i32 %84
}

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 = distinct !{!13, !14}
!14 = !{!"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: 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: nounwind uwtable
declare hidden i32 @remove_member(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 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_zrem(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef readonly %4, ptr nocapture noundef readonly %5, ptr nocapture noundef writeonly %6) local_unnamed_addr #1 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #2
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %12) #2
  %13 = call i32 @rl_zset_get_objects(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %12, ptr noundef nonnull %8, ptr noundef nonnull %10, ptr noundef nonnull %9, ptr noundef nonnull %11, i32 noundef 1, i32 noundef 1)
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %7
  %14 = icmp sgt i64 %3, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %28
  %.033 = phi i64 [ %.1, %28 ], [ 0, %.preheader ]
  %.02832 = phi i64 [ %29, %28 ], [ 0, %.preheader ]
  %15 = load i64, ptr %12, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !9
  %17 = load i64, ptr %10, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !9
  %19 = load i64, ptr %11, align 8, !tbaa !5
  %20 = getelementptr inbounds ptr, ptr %4, i64 %.02832
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds i64, ptr %5, i64 %.02832
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = call i32 @remove_member(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %15, ptr noundef %16, i64 noundef %17, ptr noundef %18, i64 noundef %19, ptr noundef %21, i64 noundef %23)
  switch i32 %24, label %.loopexit [
    i32 10, label %25
    i32 0, label %25
    i32 3, label %28
  ]

25:                                               ; preds = %.lr.ph, %.lr.ph
  %26 = icmp eq i32 %24, 10
  %27 = add nsw i64 %.033, 1
  br i1 %26, label %._crit_edge, label %28

28:                                               ; preds = %.lr.ph, %25
  %.1 = phi i64 [ %27, %25 ], [ %.033, %.lr.ph ]
  %29 = add nuw nsw i64 %.02832, 1
  %exitcond.not = icmp eq i64 %29, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %28, %25, %.preheader
  %.2 = phi i64 [ 0, %.preheader ], [ %27, %25 ], [ %.1, %28 ]
  store i64 %.2, ptr %6, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %7, %._crit_edge
  %.029 = phi i32 [ %13, %7 ], [ 0, %._crit_edge ], [ %24, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %12) #2
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #2
  ret i32 %.029
}

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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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