; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (705)

; 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.MyHashSet = type { ptr, i32, i32 }
%struct.slot = type { i8, i32 }

; Function Attrs: nounwind uwtable
declare dso_local i32 @next_prime(i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @setCreateWithSize(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @resizeSetStorage(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.MyHashSet, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = call i32 @next_prime(i32 noundef %10)
  store i32 %11, ptr %3, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %12 = load i32, ptr %3, align 4, !tbaa !12
  %13 = call ptr @setCreateWithSize(i32 noundef %12)
  store ptr %13, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MyHashSet, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  store ptr %16, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.MyHashSet, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !9
  store i32 %19, ptr %6, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %20

20:                                               ; preds = %43, %1
  %21 = load i32, ptr %7, align 4, !tbaa !12
  %22 = load i32, ptr %6, align 4, !tbaa !12
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %46

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !12
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds %struct.slot, ptr %26, i64 %28
  %30 = getelementptr inbounds %struct.slot, ptr %29, i32 0, i32 0
  %31 = load i8, ptr %30, align 4, !tbaa !14
  %32 = zext i8 %31 to i32
  %33 = icmp eq i32 %32, 111
  br i1 %33, label %34, label %42

34:                                               ; preds = %25
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !12
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %struct.slot, ptr %36, i64 %38
  %40 = getelementptr inbounds %struct.slot, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !16
  call void @myHashSetAdd(ptr noundef %35, i32 noundef %41)
  br label %42

42:                                               ; preds = %34, %25
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %7, align 4, !tbaa !12
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %7, align 4, !tbaa !12
  br label %20, !llvm.loop !17

46:                                               ; preds = %24
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.MyHashSet, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 8, !tbaa !9
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.MyHashSet, ptr %50, i32 0, i32 1
  store i32 %49, ptr %51, align 8, !tbaa !9
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.MyHashSet, ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 4, !tbaa !19
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.MyHashSet, ptr %55, i32 0, i32 2
  store i32 %54, ptr %56, align 4, !tbaa !19
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.MyHashSet, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MyHashSet, ptr %60, i32 0, i32 0
  store ptr %59, ptr %61, align 8, !tbaa !13
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.MyHashSet, ptr %63, i32 0, i32 0
  store ptr %62, ptr %64, align 8, !tbaa !13
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  call void @myHashSetFree(ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @myHashSetAdd(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @myHashSetFree(ptr noundef) #0

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 8}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!15, !7, i64 0}
!15 = !{!"", !7, i64 0, !11, i64 4}
!16 = !{!15, !11, i64 4}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!10, !11, i64 12}


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

%struct.slot = type { i8, i32 }

; Function Attrs: nounwind uwtable
declare dso_local i32 @next_prime(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @setCreateWithSize(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @resizeSetStorage(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = tail call i32 @next_prime(i32 noundef %3)
  %5 = tail call ptr @setCreateWithSize(i32 noundef %4)
  %6 = load ptr, ptr %0, align 8, !tbaa !11
  %7 = load i32, ptr %2, align 8, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = zext nneg i32 %7 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %18, %1
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  %10 = load <2 x i32>, ptr %9, align 8, !tbaa !12
  store <2 x i32> %10, ptr %2, align 8, !tbaa !12
  %11 = load ptr, ptr %5, align 8, !tbaa !11
  store ptr %11, ptr %0, align 8, !tbaa !11
  store ptr %6, ptr %5, align 8, !tbaa !11
  tail call void @myHashSetFree(ptr noundef nonnull %5)
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %18
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %18 ]
  %12 = getelementptr inbounds %struct.slot, ptr %6, i64 %indvars.iv
  %13 = load i8, ptr %12, align 4, !tbaa !13
  %14 = icmp eq i8 %13, 111
  br i1 %14, label %15, label %18

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %12, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !15
  tail call void @myHashSetAdd(ptr noundef %5, i32 noundef %17)
  br label %18

18:                                               ; preds = %.lr.ph, %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16
}

; Function Attrs: nounwind uwtable
declare dso_local void @myHashSetAdd(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @myHashSetFree(ptr noundef) local_unnamed_addr #0

attributes #0 = { 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" }

!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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !8, i64 0}
!14 = !{!"", !8, i64 0, !10, i64 4}
!15 = !{!14, !10, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass