; LLVM IR from yinqiwen/ardb :: src/common/redis (intset)

; 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.intset = type { i32, i32, [0 x i8] }

; 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
declare hidden zeroext i8 @_intsetValueEncoding(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @intsetSearch(ptr noundef, i64 noundef, ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @intsetRemove(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  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 1, ptr %7) #2
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = call zeroext i8 @_intsetValueEncoding(i64 noundef %10)
  store i8 %11, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %16

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %15, align 4, !tbaa !12
  br label %16

16:                                               ; preds = %14, %3
  %17 = load i8, ptr %7, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.intset, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = icmp ule i32 %18, %21
  br i1 %22, label %23, label %56

23:                                               ; preds = %16
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = call zeroext i8 @intsetSearch(ptr noundef %24, i64 noundef %25, ptr noundef %8)
  %27 = zext i8 %26 to i32
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %56

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.intset, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !12
  store i32 %32, ptr %9, align 4, !tbaa !12
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %37

35:                                               ; preds = %29
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 1, ptr %36, align 4, !tbaa !12
  br label %37

37:                                               ; preds = %35, %29
  %38 = load i32, ptr %8, align 4, !tbaa !12
  %39 = load i32, ptr %9, align 4, !tbaa !12
  %40 = sub i32 %39, 1
  %41 = icmp ult i32 %38, %40
  br i1 %41, label %42, label %47

42:                                               ; preds = %37
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !12
  %45 = add i32 %44, 1
  %46 = load i32, ptr %8, align 4, !tbaa !12
  call void @intsetMoveTail(ptr noundef %43, i32 noundef %45, i32 noundef %46)
  br label %47

47:                                               ; preds = %42, %37
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !12
  %50 = sub i32 %49, 1
  %51 = call ptr @intsetResize(ptr noundef %48, i32 noundef %50)
  store ptr %51, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !12
  %53 = sub i32 %52, 1
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.intset, ptr %54, i32 0, i32 1
  store i32 %53, ptr %55, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %56

56:                                               ; preds = %47, %23, %16
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  ret ptr %57
}

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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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"

; 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
declare hidden zeroext i8 @_intsetValueEncoding(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @intsetSearch(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @intsetRemove(ptr noundef %0, i64 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  %5 = tail call zeroext i8 @_intsetValueEncoding(i64 noundef %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #2
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %7, label %6

6:                                                ; preds = %3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %6, %3
  %8 = zext i8 %5 to i32
  %9 = load i32, ptr %0, align 4, !tbaa !5
  %.not18 = icmp ult i32 %9, %8
  br i1 %.not18, label %25, label %10

10:                                               ; preds = %7
  %11 = call zeroext i8 @intsetSearch(ptr noundef nonnull %0, i64 noundef %1, ptr noundef nonnull %4)
  %.not19 = icmp eq i8 %11, 0
  br i1 %.not19, label %25, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %0, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !5
  br i1 %.not, label %16, label %15

15:                                               ; preds = %12
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %15, %12
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = add i32 %14, -1
  %19 = icmp ult i32 %17, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %16
  %21 = add nuw i32 %17, 1
  call void @intsetMoveTail(ptr noundef nonnull %0, i32 noundef %21, i32 noundef %17)
  br label %22

22:                                               ; preds = %20, %16
  %23 = call ptr @intsetResize(ptr noundef nonnull %0, i32 noundef %18)
  %24 = getelementptr inbounds i8, ptr %23, i64 4
  store i32 %18, ptr %24, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %22, %10, %7
  %.0 = phi ptr [ %23, %22 ], [ %0, %10 ], [ %0, %7 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  ret ptr %.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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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