; LLVM IR from JessonYue/LeetCodeLearning :: Array/luobiao/BaseDataStructure (Hash)

; 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.HashNode = type { i32, i32 }

@hashTable = external dso_local global [10 x %struct.HashNode], align 16
@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1

; 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
declare dso_local i32 @getHashAddress(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @insert(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = call i32 @getHashAddress(i32 noundef %6)
  store i32 %7, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [10 x %struct.HashNode], ptr @hashTable, i64 0, i64 %9
  %11 = getelementptr inbounds %struct.HashNode, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %22, label %14

14:                                               ; preds = %1
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [10 x %struct.HashNode], ptr @hashTable, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.HashNode, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = icmp eq i32 %19, %20
  br i1 %21, label %22, label %35

22:                                               ; preds = %14, %1
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10 x %struct.HashNode], ptr @hashTable, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.HashNode, ptr %26, i32 0, i32 0
  store i32 %23, ptr %27, align 8, !tbaa !11
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [10 x %struct.HashNode], ptr @hashTable, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.HashNode, ptr %30, i32 0, i32 1
  store i32 0, ptr %31, align 4, !tbaa !9
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %32, i32 noundef %33)
  br label %68

35:                                               ; preds = %14
  br label %36

36:                                               ; preds = %48, %35
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [10 x %struct.HashNode], ptr @hashTable, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.HashNode, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %46

43:                                               ; preds = %36
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = icmp slt i32 %44, 10
  br label %46

46:                                               ; preds = %43, %36
  %47 = phi i1 [ false, %36 ], [ %45, %43 ]
  br i1 %47, label %48, label %51

48:                                               ; preds = %46
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %4, align 4, !tbaa !5
  br label %36, !llvm.loop !12

51:                                               ; preds = %46
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = icmp eq i32 %52, 10
  br i1 %53, label %54, label %55

54:                                               ; preds = %51
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %69

55:                                               ; preds = %51
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [10 x %struct.HashNode], ptr @hashTable, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.HashNode, ptr %59, i32 0, i32 0
  store i32 %56, ptr %60, align 8, !tbaa !11
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [10 x %struct.HashNode], ptr @hashTable, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.HashNode, ptr %63, i32 0, i32 1
  store i32 0, ptr %64, align 4, !tbaa !9
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %65, i32 noundef %66)
  br label %68

68:                                               ; preds = %55, %22
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %69

69:                                               ; preds = %68, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %70 = load i32, ptr %2, align 4
  ret i32 %70
}

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

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 = { "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 }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 4}
!10 = !{!"HashNode", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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.HashNode = type { i32, i32 }

@hashTable = external dso_local local_unnamed_addr global [10 x %struct.HashNode], align 16
@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @insert(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @getHashAddress(i32 noundef %0)
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [10 x %struct.HashNode], ptr @hashTable, i64 0, i64 %3
  %5 = getelementptr inbounds i8, ptr %4, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %11, label %8

8:                                                ; preds = %1
  %9 = load i32, ptr %4, align 8, !tbaa !10
  %10 = icmp eq i32 %9, %0
  br i1 %10, label %11, label %.preheader

11:                                               ; preds = %8, %1
  store i32 %0, ptr %4, align 8, !tbaa !10
  store i32 0, ptr %5, align 4, !tbaa !5
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %0, i32 noundef %2)
  br label %25

.preheader:                                       ; preds = %8, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader ], [ %3, %8 ]
  %13 = getelementptr inbounds [10 x %struct.HashNode], ptr @hashTable, i64 0, i64 %indvars.iv
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  %17 = icmp slt i64 %indvars.iv, 10
  %18 = and i1 %17, %16
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  br i1 %18, label %.preheader, label %19, !llvm.loop !11

19:                                               ; preds = %.preheader
  %20 = icmp eq i64 %indvars.iv, 10
  br i1 %20, label %25, label %21

21:                                               ; preds = %19
  %22 = getelementptr inbounds i8, ptr %13, i64 4
  %23 = trunc nsw i64 %indvars.iv to i32
  store i32 %0, ptr %13, align 8, !tbaa !10
  store i32 0, ptr %22, align 4, !tbaa !5
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %0, i32 noundef %23)
  br label %25

25:                                               ; preds = %11, %21, %19
  %.019 = phi i32 [ -1, %19 ], [ 0, %21 ], [ 0, %11 ]
  ret i32 %.019
}

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

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 = { 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" }

!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 4}
!6 = !{!"HashNode", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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