; LLVM IR from manishbisht/Competitive-Programming :: Data Structures/09 Hash Table (hashtable)

; 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.HashTable = type { ptr }
%struct.node = type { ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local i64 @hash(ptr 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 willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @delete_HT(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call i64 @hash(ptr noundef %10)
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.HashTable, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds ptr, ptr %15, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %19, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %2
  store i32 1, ptr %7, align 4
  br label %109

23:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %100, %23
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %107

27:                                               ; preds = %24
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.node, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call i32 @strcmp(ptr noundef %30, ptr noundef %31) #5
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %100

34:                                               ; preds = %27
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %49

39:                                               ; preds = %34
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %49

42:                                               ; preds = %39
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.HashTable, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds ptr, ptr %45, i64 %47
  store ptr null, ptr %48, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %42, %39, %34
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.node, ptr %50, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %67

54:                                               ; preds = %49
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %67

57:                                               ; preds = %54
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.HashTable, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !11
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds ptr, ptr %63, i64 %65
  store ptr %60, ptr %66, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %57, %54, %49
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.node, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  %71 = icmp eq ptr %70, null
  br i1 %71, label %72, label %78

72:                                               ; preds = %67
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %78

75:                                               ; preds = %72
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.node, ptr %76, i32 0, i32 2
  store ptr null, ptr %77, align 8, !tbaa !15
  br label %78

78:                                               ; preds = %75, %72, %67
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.node, ptr %79, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !15
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %92

83:                                               ; preds = %78
  %84 = load i32, ptr %9, align 4, !tbaa !9
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %92

86:                                               ; preds = %83
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.node, ptr %87, i32 0, i32 2
  %89 = load ptr, ptr %88, align 8, !tbaa !15
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.node, ptr %90, i32 0, i32 2
  store ptr %89, ptr %91, align 8, !tbaa !15
  br label %92

92:                                               ; preds = %86, %83, %78
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.node, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !13
  call void @free(ptr noundef %95) #4
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.node, ptr %96, i32 0, i32 1
  %98 = load ptr, ptr %97, align 8, !tbaa !16
  call void @free(ptr noundef %98) #4
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %99) #4
  store i32 1, ptr %7, align 4
  br label %108

100:                                              ; preds = %27
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %101, ptr %8, align 8, !tbaa !5
  %102 = load ptr, ptr %8, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.node, ptr %102, i32 0, i32 2
  %104 = load ptr, ptr %103, align 8, !tbaa !15
  store ptr %104, ptr %6, align 8, !tbaa !5
  %105 = load i32, ptr %9, align 4, !tbaa !9
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %9, align 4, !tbaa !9
  br label %24, !llvm.loop !17

107:                                              ; preds = %24
  store i32 0, ptr %7, align 4
  br label %108

108:                                              ; preds = %107, %92
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %109

109:                                              ; preds = %108, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %110 = load i32, ptr %7, align 4
  switch i32 %110, label %112 [
    i32 0, label %111
    i32 1, label %111
  ]

111:                                              ; preds = %109, %109
  ret void

112:                                              ; preds = %109
  unreachable
}

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 willreturn memory(read) "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 = { nounwind "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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, !6, i64 0}
!12 = !{!"HashTable", !6, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"node", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 16}
!16 = !{!14, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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"

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @delete_HT(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i64 @hash(ptr noundef %1)
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = and i64 %3, 4294967295
  %6 = getelementptr inbounds ptr, ptr %4, i64 %5
  %7 = load ptr, ptr %6, align 8, !tbaa !10
  %8 = icmp eq ptr %7, null
  br i1 %8, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %9 = load ptr, ptr %7, align 8, !tbaa !11
  %10 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %9, ptr noundef nonnull dereferenceable(1) %1) #3
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.preheader._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %12 = load ptr, ptr %40, align 8, !tbaa !11
  %13 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) %1) #3
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.preheader._crit_edge, label %.lr.ph, !llvm.loop !13

.preheader._crit_edge:                            ; preds = %.preheader, %.preheader.preheader
  %.03545.lcssa = phi ptr [ undef, %.preheader.preheader ], [ %.0364459, %.preheader ]
  %.03644.lcssa = phi ptr [ %7, %.preheader.preheader ], [ %40, %.preheader ]
  %15 = xor i1 %11, true
  %16 = getelementptr inbounds i8, ptr %.03644.lcssa, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = icmp eq ptr %17, null
  %or.cond = and i1 %18, %11
  br i1 %or.cond, label %19, label %20

19:                                               ; preds = %.preheader._crit_edge
  store ptr null, ptr %6, align 8, !tbaa !10
  %.pre = load ptr, ptr %16, align 8, !tbaa !15
  br label %20

20:                                               ; preds = %19, %.preheader._crit_edge
  %21 = phi ptr [ %.pre, %19 ], [ %17, %.preheader._crit_edge ]
  %22 = icmp ne ptr %21, null
  %or.cond3 = and i1 %22, %11
  br i1 %or.cond3, label %.thread50, label %25

.thread50:                                        ; preds = %20
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = getelementptr inbounds ptr, ptr %23, i64 %5
  store ptr %21, ptr %24, align 8, !tbaa !10
  br label %35

25:                                               ; preds = %20
  %26 = icmp ne ptr %21, null
  %or.cond5.not = or i1 %26, %11
  br i1 %or.cond5.not, label %29, label %27

27:                                               ; preds = %25
  %28 = getelementptr inbounds i8, ptr %.03545.lcssa, i64 16
  store ptr null, ptr %28, align 8, !tbaa !15
  br label %29

29:                                               ; preds = %27, %25
  %30 = phi i1 [ true, %27 ], [ %15, %25 ]
  %31 = load ptr, ptr %16, align 8, !tbaa !15
  %32 = icmp ne ptr %31, null
  %or.cond7 = and i1 %32, %30
  br i1 %or.cond7, label %33, label %35

33:                                               ; preds = %29
  %34 = getelementptr inbounds i8, ptr %.03545.lcssa, i64 16
  store ptr %31, ptr %34, align 8, !tbaa !15
  br label %35

35:                                               ; preds = %.thread50, %33, %29
  %36 = load ptr, ptr %.03644.lcssa, align 8, !tbaa !11
  tail call void @free(ptr noundef %36) #4
  %37 = getelementptr inbounds i8, ptr %.03644.lcssa, i64 8
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  tail call void @free(ptr noundef %38) #4
  tail call void @free(ptr noundef nonnull %.03644.lcssa) #4
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader.preheader, %.preheader
  %.0364459 = phi ptr [ %40, %.preheader ], [ %7, %.preheader.preheader ]
  %39 = getelementptr inbounds i8, ptr %.0364459, i64 16
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %.not = icmp eq ptr %40, null
  br i1 %.not, label %.loopexit, label %.preheader, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %35, %2
  ret void
}

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind willreturn memory(read) }
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, !7, i64 0}
!6 = !{!"HashTable", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"node", !7, i64 0, !7, i64 8, !7, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !7, i64 16}
!16 = !{!12, !7, i64 8}


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