; LLVM IR from JessonYue/LeetCodeLearning :: Array/zhangjunwei/basedatastruct/hash.ll (Z16hashtable_inserti)

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

@hashTable = external dso_local global [10 x %struct.hashNode], align 16

; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z16hashtable_inserti(i32 noundef %0) #1 {
  %2 = alloca i1, align 1
  %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 noundef i32 @_ZL16get_hash_addressi(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 0
  %12 = load i8, ptr %11, align 8, !tbaa !9, !range !12, !noundef !13
  %13 = trunc i8 %12 to i1
  %14 = zext i1 %13 to i32
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %26

16:                                               ; preds = %1
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10 x %struct.hashNode], ptr @hashTable, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.hashNode, ptr %19, i32 0, i32 0
  store i8 1, ptr %20, align 8, !tbaa !9
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10 x %struct.hashNode], ptr @hashTable, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.hashNode, ptr %24, i32 0, i32 1
  store i32 %21, ptr %25, align 4, !tbaa !14
  br label %56

26:                                               ; preds = %1
  br label %27

27:                                               ; preds = %39, %26
  %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 0
  %32 = load i8, ptr %31, align 8, !tbaa !9, !range !12, !noundef !13
  %33 = trunc i8 %32 to i1
  br i1 %33, label %34, label %37

34:                                               ; preds = %27
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = icmp slt i32 %35, 10
  br label %37

37:                                               ; preds = %34, %27
  %38 = phi i1 [ false, %27 ], [ %36, %34 ]
  br i1 %38, label %39, label %42

39:                                               ; preds = %37
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %4, align 4, !tbaa !5
  br label %27, !llvm.loop !15

42:                                               ; preds = %37
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = icmp eq i32 %43, 10
  br i1 %44, label %45, label %46

45:                                               ; preds = %42
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %57

46:                                               ; preds = %42
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [10 x %struct.hashNode], ptr @hashTable, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.hashNode, ptr %49, i32 0, i32 0
  store i8 1, ptr %50, align 8, !tbaa !9
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [10 x %struct.hashNode], ptr @hashTable, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.hashNode, ptr %54, i32 0, i32 1
  store i32 %51, ptr %55, align 4, !tbaa !14
  br label %56

56:                                               ; preds = %46, %16
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %57

57:                                               ; preds = %56, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %58 = load i1, ptr %2, align 1
  ret i1 %58
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL16get_hash_addressi(i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { mustprogress 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 #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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS8hashNode", !11, i64 0, !6, i64 4}
!11 = !{!"bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!10, !6, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"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 { i8, i32 }

@hashTable = external dso_local local_unnamed_addr global [10 x %struct.hashNode], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z16hashtable_inserti(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef i32 @_ZL16get_hash_addressi(i32 noundef %0)
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [10 x %struct.hashNode], ptr @hashTable, i64 0, i64 %3
  %5 = load i8, ptr %4, align 8, !tbaa !5, !range !11, !noundef !12
  %6 = icmp eq i8 %5, 0
  br i1 %6, label %.sink.split, label %.preheader

.preheader:                                       ; preds = %1, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader ], [ %3, %1 ]
  %7 = getelementptr inbounds [10 x %struct.hashNode], ptr @hashTable, i64 0, i64 %indvars.iv
  %8 = load i8, ptr %7, align 8, !tbaa !5, !range !11, !noundef !12
  %9 = trunc nuw i8 %8 to i1
  %10 = icmp slt i64 %indvars.iv, 10
  %11 = and i1 %10, %9
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  br i1 %11, label %.preheader, label %12, !llvm.loop !13

12:                                               ; preds = %.preheader
  %13 = getelementptr inbounds [10 x %struct.hashNode], ptr @hashTable, i64 0, i64 %indvars.iv
  %14 = icmp eq i64 %indvars.iv, 10
  br i1 %14, label %16, label %.sink.split

.sink.split:                                      ; preds = %12, %1
  %.sink = phi ptr [ %4, %1 ], [ %13, %12 ]
  store i8 1, ptr %.sink, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.sink, i64 4
  store i32 %0, ptr %15, align 4, !tbaa !15
  br label %16

16:                                               ; preds = %.sink.split, %12
  %.012 = phi i1 [ false, %12 ], [ true, %.sink.split ]
  ret i1 %.012
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL16get_hash_addressi(i32 noundef) local_unnamed_addr #0

attributes #0 = { mustprogress 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, !7, i64 0}
!6 = !{!"_ZTS8hashNode", !7, i64 0, !10, i64 4}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 4}


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