; LLVM IR from ahampriyanshu/algo-ds-101 :: Data-Structures/HashSet (Hash-Set)

; 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.Hashset = type { i32, i32, ptr, ptr }
%struct.hashpair = type { i64, ptr }

; 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 @hs_delete_key(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Hashset, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Hashset, ptr %15, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call i64 %17(ptr noundef %18)
  store i64 %19, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %20 = load i64, ptr %7, align 8, !tbaa !13
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Hashset, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !15
  %24 = sext i32 %23 to i64
  %25 = srem i64 %20, %24
  %26 = trunc i64 %25 to i32
  store i32 %26, ptr %8, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !16
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds %struct.hashpair, ptr %27, i64 %29
  store ptr %30, ptr %9, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %71, %2
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.hashpair, ptr %32, i32 0, i32 0
  %34 = load i64, ptr %33, align 8, !tbaa !17
  %35 = icmp sge i64 %34, 0
  br i1 %35, label %36, label %50

36:                                               ; preds = %31
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.hashpair, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !19
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %50

41:                                               ; preds = %36
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Hashset, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !15
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.hashpair, ptr %43, i64 %47
  %49 = icmp ult ptr %42, %48
  br label %50

50:                                               ; preds = %41, %36, %31
  %51 = phi i1 [ false, %36 ], [ false, %31 ], [ %49, %41 ]
  br i1 %51, label %52, label %74

52:                                               ; preds = %50
  %53 = load i64, ptr %7, align 8, !tbaa !13
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.hashpair, ptr %54, i32 0, i32 0
  %56 = load i64, ptr %55, align 8, !tbaa !17
  %57 = icmp eq i64 %53, %56
  br i1 %57, label %58, label %71

58:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.hashpair, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !19
  store ptr %61, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.hashpair, ptr %62, i32 0, i32 0
  store i64 -1, ptr %63, align 8, !tbaa !17
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.hashpair, ptr %64, i32 0, i32 1
  store ptr null, ptr %65, align 8, !tbaa !19
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.Hashset, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !20
  %69 = add nsw i32 %68, -1
  store i32 %69, ptr %67, align 4, !tbaa !20
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %70, ptr %3, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %75

71:                                               ; preds = %52
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.hashpair, ptr %72, i32 1
  store ptr %73, ptr %9, align 8, !tbaa !5
  br label %31, !llvm.loop !21

74:                                               ; preds = %50
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %75

75:                                               ; preds = %74, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %76 = load ptr, ptr %3, align 8
  ret ptr %76
}

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, !6, i64 8}
!10 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !11, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !14, i64 0}
!18 = !{!"", !14, i64 0, !6, i64 8}
!19 = !{!18, !6, i64 8}
!20 = !{!10, !11, i64 4}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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.hashpair = type { i64, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @hs_delete_key(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = tail call i64 %6(ptr noundef %1) #1
  %8 = load i32, ptr %0, align 8, !tbaa !12
  %9 = sext i32 %8 to i64
  %10 = srem i64 %7, %9
  %11 = shl nsw i64 %10, 4
  %12 = getelementptr inbounds i8, ptr %4, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = icmp sgt i64 %13, -1
  br i1 %14, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %2
  %15 = getelementptr inbounds %struct.hashpair, ptr %4, i64 %9
  br label %16

16:                                               ; preds = %.lr.ph, %28
  %17 = phi i64 [ %13, %.lr.ph ], [ %30, %28 ]
  %.02026 = phi ptr [ %12, %.lr.ph ], [ %29, %28 ]
  %18 = getelementptr inbounds i8, ptr %.02026, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !16
  %.not = icmp ne ptr %19, null
  %20 = icmp ult ptr %.02026, %15
  %or.cond = select i1 %.not, i1 %20, i1 false
  br i1 %or.cond, label %21, label %.critedge

21:                                               ; preds = %16
  %22 = icmp eq i64 %7, %17
  br i1 %22, label %23, label %28

23:                                               ; preds = %21
  %24 = getelementptr inbounds i8, ptr %.02026, i64 8
  store i64 -1, ptr %.02026, align 8, !tbaa !13
  store ptr null, ptr %24, align 8, !tbaa !16
  %25 = getelementptr inbounds i8, ptr %0, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !17
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %25, align 4, !tbaa !17
  br label %.critedge

28:                                               ; preds = %21
  %29 = getelementptr inbounds i8, ptr %.02026, i64 16
  %30 = load i64, ptr %29, align 8, !tbaa !13
  %31 = icmp sgt i64 %30, -1
  br i1 %31, label %16, label %.critedge, !llvm.loop !18

.critedge:                                        ; preds = %16, %28, %2, %23
  %.0 = phi ptr [ %19, %23 ], [ null, %2 ], [ null, %28 ], [ null, %16 ]
  ret ptr %.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 = { 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"", !15, i64 0, !10, i64 8}
!15 = !{!"long", !8, i64 0}
!16 = !{!14, !10, i64 8}
!17 = !{!6, !7, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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