; 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: 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) #2

; Function Attrs: nounwind uwtable
define dso_local void @myHashSetRemove(ptr noundef %0, i32 noundef %1) #3 {
  %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 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
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.MyHashSet, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !11
  store i32 %13, 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
  %14 = load ptr, ptr %3, 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 %7, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %53, %51, %2
  br label %18

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

33:                                               ; preds = %18
  store i32 1, ptr %10, align 4
  br label %51

34:                                               ; preds = %18
  %35 = getelementptr inbounds %struct.slot, ptr %9, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !18
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = icmp eq i32 %36, %37
  br i1 %38, label %39, label %49

39:                                               ; preds = %34
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds %struct.slot, ptr %40, i64 %42
  %44 = getelementptr inbounds %struct.slot, ptr %43, i32 0, i32 0
  store i8 100, ptr %44, align 4, !tbaa !16
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.MyHashSet, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 4, !tbaa !19
  %48 = add i32 %47, -1
  store i32 %48, ptr %46, align 4, !tbaa !19
  store i32 1, ptr %10, align 4
  br label %51

49:                                               ; preds = %34
  store i32 2, ptr %10, align 4
  br label %51

50:                                               ; preds = %18
  store i32 0, ptr %10, align 4
  br label %51

51:                                               ; preds = %50, %49, %39, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %52 = load i32, ptr %10, align 4
  switch i32 %52, label %54 [
    i32 0, label %53
    i32 2, label %17
  ]

53:                                               ; preds = %51
  br label %17

54:                                               ; preds = %51
  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
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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
define dso_local void @myHashSetRemove(ptr nocapture 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 %6

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

.backedge:                                        ; preds = %6, %13
  br label %6

13:                                               ; preds = %6
  %.sroa.41.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 4
  %.sroa.41.0.copyload = load i32, ptr %.sroa.41.0..sroa_idx, align 4, !tbaa !13
  %14 = icmp eq i32 %.sroa.41.0.copyload, %1
  br i1 %14, label %15, label %.backedge

15:                                               ; preds = %13
  store i8 100, ptr %12, align 4, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %0, i64 12
  %17 = load i32, ptr %16, align 4, !tbaa !16
  %18 = add i32 %17, -1
  store i32 %18, ptr %16, align 4, !tbaa !16
  br label %.loopexit

.loopexit:                                        ; preds = %6, %15
  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 = !{!15, !8, i64 0}
!15 = !{!"", !8, i64 0, !10, i64 4}
!16 = !{!6, !10, i64 12}


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