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

15:                                               ; preds = %3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 1, ptr %16, align 1, !tbaa !11
  br label %17

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

24:                                               ; preds = %17
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = call ptr @intsetUpgradeAndAdd(ptr noundef %25, i64 noundef %26)
  store ptr %27, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %69

28:                                               ; preds = %17
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = call zeroext i8 @intsetSearch(ptr noundef %29, i64 noundef %30, ptr noundef %9)
  %32 = icmp ne i8 %31, 0
  br i1 %32, label %33, label %40

33:                                               ; preds = %28
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %38

36:                                               ; preds = %33
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 0, ptr %37, align 1, !tbaa !11
  br label %38

38:                                               ; preds = %36, %33
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %39, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %69

40:                                               ; preds = %28
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.intset, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !12
  %45 = add i32 %44, 1
  %46 = call ptr @intsetResize(ptr noundef %41, i32 noundef %45)
  store ptr %46, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !12
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.intset, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !12
  %51 = icmp ult i32 %47, %50
  br i1 %51, label %52, label %57

52:                                               ; preds = %40
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i32, ptr %9, align 4, !tbaa !12
  %55 = load i32, ptr %9, align 4, !tbaa !12
  %56 = add i32 %55, 1
  call void @intsetMoveTail(ptr noundef %53, i32 noundef %54, i32 noundef %56)
  br label %57

57:                                               ; preds = %52, %40
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !12
  %61 = load i64, ptr %6, align 8, !tbaa !9
  call void @_intsetSet(ptr noundef %59, i32 noundef %60, i64 noundef %61)
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.intset, ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 4, !tbaa !12
  %65 = add i32 %64, 1
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.intset, ptr %66, i32 0, i32 1
  store i32 %65, ptr %67, align 4, !tbaa !12
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %68, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %69

69:                                               ; preds = %58, %38, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  %70 = load ptr, ptr %4, align 8
  ret ptr %70
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @intsetUpgradeAndAdd(ptr noundef, 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
declare hidden void @_intsetSet(ptr noundef, i32 noundef, i64 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 = !{!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
define dso_local ptr @intsetAdd(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 i8 1, ptr %2, align 1, !tbaa !5
  br label %7

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

11:                                               ; preds = %7
  %12 = tail call ptr @intsetUpgradeAndAdd(ptr noundef nonnull %0, i64 noundef %1)
  br label %32

13:                                               ; preds = %7
  %14 = call zeroext i8 @intsetSearch(ptr noundef nonnull %0, i64 noundef %1, ptr noundef nonnull %4)
  %.not23 = icmp eq i8 %14, 0
  br i1 %.not23, label %17, label %15

15:                                               ; preds = %13
  br i1 %.not, label %32, label %16

16:                                               ; preds = %15
  store i8 0, ptr %2, align 1, !tbaa !5
  br label %32

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %0, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !8
  %20 = add i32 %19, 1
  %21 = call ptr @intsetResize(ptr noundef nonnull %0, i32 noundef %20)
  %22 = load i32, ptr %4, align 4, !tbaa !8
  %23 = getelementptr inbounds i8, ptr %21, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !8
  %25 = icmp ult i32 %22, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %17
  %27 = add nuw i32 %22, 1
  call void @intsetMoveTail(ptr noundef nonnull %21, i32 noundef %22, i32 noundef %27)
  %.pre = load i32, ptr %4, align 4, !tbaa !8
  br label %28

28:                                               ; preds = %17, %26
  %29 = phi i32 [ %22, %17 ], [ %.pre, %26 ]
  call void @_intsetSet(ptr noundef nonnull %21, i32 noundef %29, i64 noundef %1)
  %30 = load i32, ptr %23, align 4, !tbaa !8
  %31 = add i32 %30, 1
  store i32 %31, ptr %23, align 4, !tbaa !8
  br label %32

32:                                               ; preds = %15, %16, %28, %11
  %.0 = phi ptr [ %12, %11 ], [ %21, %28 ], [ %0, %16 ], [ %0, %15 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  ret ptr %.0
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @intsetUpgradeAndAdd(ptr noundef, 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
declare hidden void @_intsetSet(ptr noundef, i32 noundef, i64 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


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