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

; 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: inlinehint nounwind uwtable
declare dso_local i32 @hash_int(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @resizeSetStorage(ptr noundef) #2

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

18:                                               ; preds = %68, %2
  br label %19

19:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = call i32 @hash_int(i32 noundef %20)
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = add i32 %22, 1
  store i32 %23, ptr %6, align 4, !tbaa !9
  %24 = add i32 %21, %22
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = urem i32 %24, %25
  store i32 %26, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds %struct.slot, ptr %27, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %30, i64 8, i1 false), !tbaa.struct !14
  %31 = getelementptr inbounds %struct.slot, ptr %9, i32 0, i32 0
  %32 = load i8, ptr %31, align 4, !tbaa !16
  %33 = zext i8 %32 to i32
  switch i32 %33, label %65 [
    i32 102, label %34
    i32 100, label %34
    i32 111, label %58
  ]

34:                                               ; preds = %19, %19
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds %struct.slot, ptr %35, i64 %37
  %39 = getelementptr inbounds %struct.slot, ptr %10, i32 0, i32 0
  store i8 111, ptr %39, align 4, !tbaa !16
  %40 = getelementptr inbounds %struct.slot, ptr %10, i32 0, i32 1
  %41 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %41, ptr %40, align 4, !tbaa !18
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %38, ptr align 4 %10, i64 8, i1 false), !tbaa.struct !14
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.MyHashSet, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 4, !tbaa !19
  %45 = add i32 %44, 1
  store i32 %45, ptr %43, align 4, !tbaa !19
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.MyHashSet, ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 4, !tbaa !19
  %49 = uitofp i32 %48 to float
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = uitofp i32 %50 to float
  %52 = fdiv float %49, %51
  %53 = fpext float %52 to double
  %54 = fcmp oge double %53, 7.300000e-01
  br i1 %54, label %55, label %57

55:                                               ; preds = %34
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  call void @resizeSetStorage(ptr noundef %56)
  br label %57

57:                                               ; preds = %55, %34
  store i32 1, ptr %11, align 4
  br label %66

58:                                               ; preds = %19
  %59 = getelementptr inbounds %struct.slot, ptr %9, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !18
  %61 = load i32, ptr %4, align 4, !tbaa !9
  %62 = icmp eq i32 %60, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %58
  store i32 1, ptr %11, align 4
  br label %66

64:                                               ; preds = %58
  br label %65

65:                                               ; preds = %64, %19
  store i32 0, ptr %11, align 4
  br label %66

66:                                               ; preds = %65, %63, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %67 = load i32, ptr %11, align 4
  switch i32 %67, label %69 [
    i32 0, label %68
  ]

68:                                               ; preds = %66
  br label %18

69:                                               ; preds = %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"", !6, i64 0, !10, i64 8, !10, i64 12}
!13 = !{!12, !6, i64 0}
!14 = !{i64 0, i64 1, !15, i64 4, i64 4, !9}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !7, i64 0}
!17 = !{!"", !7, i64 0, !10, i64 4}
!18 = !{!17, !10, i64 4}
!19 = !{!12, !10, 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: inlinehint nounwind uwtable
declare dso_local i32 @hash_int(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @myHashSetAdd(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %0, align 8, !tbaa !11
  br label %.critedge

.critedge:                                        ; preds = %.critedge.backedge, %2
  %.018 = phi i32 [ 0, %2 ], [ %7, %.critedge.backedge ]
  %6 = tail call i32 @hash_int(i32 noundef %1)
  %7 = add i32 %.018, 1
  %8 = add i32 %6, %.018
  %9 = urem i32 %8, %4
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds %struct.slot, ptr %5, i64 %10
  %.sroa.02.0.copyload = load i8, ptr %11, align 4, !tbaa !12
  %.sroa.43.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 4
  switch i8 %.sroa.02.0.copyload, label %.critedge.backedge [
    i8 102, label %12
    i8 100, label %12
    i8 111, label %22
  ]

12:                                               ; preds = %.critedge, %.critedge
  store i8 111, ptr %11, align 4, !tbaa !12
  store i32 %1, ptr %.sroa.43.0..sroa_idx, align 4, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %0, i64 12
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %15 = add i32 %14, 1
  store i32 %15, ptr %13, align 4, !tbaa !14
  %16 = uitofp i32 %15 to float
  %17 = uitofp i32 %4 to float
  %18 = fdiv float %16, %17
  %19 = fpext float %18 to double
  %20 = fcmp ult double %19, 7.300000e-01
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %12
  tail call void @resizeSetStorage(ptr noundef nonnull %0)
  br label %.loopexit

22:                                               ; preds = %.critedge
  %.sroa.43.0.copyload = load i32, ptr %.sroa.43.0..sroa_idx, align 4, !tbaa !13
  %23 = icmp eq i32 %.sroa.43.0.copyload, %1
  br i1 %23, label %.loopexit, label %.critedge.backedge

.critedge.backedge:                               ; preds = %22, %.critedge
  br label %.critedge

.loopexit:                                        ; preds = %22, %21, %12
  ret void
}

attributes #0 = { inlinehint 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 = { 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 = !{!8, !8, i64 0}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !10, i64 12}


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