; LLVM IR from HarshCasper/NeoAlgo :: C/ds (Hashtable_chaining)

; 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 { i32, ptr }

@.str.3 = external hidden unnamed_addr constant [116 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [44 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @Chaining(ptr noundef, 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; 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 void @print_table(ptr noundef) #0

declare i32 @printf(ptr noundef, ...) #3

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %9 = call noalias ptr @malloc(i64 noundef 176) #5
  store ptr %9, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %20, %0
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 10
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %23

14:                                               ; preds = %10
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds %struct.HashTable, ptr %15, i64 %17
  %19 = getelementptr inbounds %struct.HashTable, ptr %18, i32 0, i32 1
  store ptr null, ptr %19, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %14
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %3, align 4, !tbaa !9
  br label %10, !llvm.loop !13

23:                                               ; preds = %13
  br label %24

24:                                               ; preds = %53, %23
  br label %25

25:                                               ; preds = %24
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %4)
  %28 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %28, label %50 [
    i32 1, label %29
    i32 2, label %34
    i32 3, label %47
    i32 4, label %49
  ]

29:                                               ; preds = %25
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %5)
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !9
  call void @Chaining(ptr noundef %32, i32 noundef %33)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %50

34:                                               ; preds = %25
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = call i32 @does_exist(ptr noundef %37, i32 noundef %38)
  store i32 %39, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %44

42:                                               ; preds = %34
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %46

44:                                               ; preds = %34
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  br label %46

46:                                               ; preds = %44, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %50

47:                                               ; preds = %25
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  call void @print_table(ptr noundef %48)
  br label %50

49:                                               ; preds = %25
  store i32 0, ptr %1, align 4
  store i32 1, ptr %8, align 4
  br label %51

50:                                               ; preds = %47, %46, %29, %25
  store i32 0, ptr %8, align 4
  br label %51

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

53:                                               ; preds = %51
  br label %24

54:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %55 = load i32, ptr %1, align 4
  ret i32 %55
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

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 allocsize(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 = { "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 allocsize(0) }

!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 8}
!12 = !{!"HashTable", !10, i64 0, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@.str.3 = external hidden unnamed_addr constant [116 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [44 x i8], align 1

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 void @print_table(ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.preheader.preheader:
  %0 = alloca i32, align 4
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call noalias dereferenceable_or_null(176) ptr @malloc(i64 noundef 176) #4
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr null, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr null, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 40
  store ptr null, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %3, i64 56
  store ptr null, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %3, i64 72
  store ptr null, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %3, i64 88
  store ptr null, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %3, i64 104
  store ptr null, ptr %10, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %3, i64 120
  store ptr null, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %3, i64 136
  store ptr null, ptr %12, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %3, i64 152
  store ptr null, ptr %13, align 8, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.critedge
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %0) #5
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull %0)
  %16 = load i32, ptr %0, align 4, !tbaa !11
  switch i32 %16, label %.critedge [
    i32 1, label %17
    i32 2, label %21
    i32 3, label %27
    i32 4, label %28
  ]

17:                                               ; preds = %.preheader
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull %1)
  %20 = load i32, ptr %1, align 4, !tbaa !11
  call void @Chaining(ptr noundef %3, i32 noundef %20)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  br label %.critedge

21:                                               ; preds = %.preheader
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull %2)
  %24 = load i32, ptr %2, align 4, !tbaa !11
  %25 = call i32 @does_exist(ptr noundef %3, i32 noundef %24)
  %.not = icmp eq i32 %25, 0
  %.str.8..str.7 = select i1 %.not, ptr @.str.8, ptr @.str.7
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.8..str.7)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  br label %.critedge

27:                                               ; preds = %.preheader
  call void @print_table(ptr noundef %3)
  br label %.critedge

.critedge:                                        ; preds = %27, %21, %17, %.preheader
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %0) #5
  br label %.preheader

28:                                               ; preds = %.preheader
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %0) #5
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 = { nofree 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 allocsize(0) }
attributes #5 = { 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 = !{!"HashTable", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass