; LLVM IR from evanxg852000/rockstartdev :: mastering-ds-in-c/practice/examples (ohtbl)

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

@stdout = external global ptr, align 8
@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct.OHTbl_, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %13 = call i32 @ohtbl_init(ptr noundef %6, i32 noundef 11, ptr noundef @h1_char, ptr noundef @h2_char, ptr noundef @match_char, ptr noundef @free)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %66

16:                                               ; preds = %2
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %62, %16
  %18 = load i32, ptr %10, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 5
  br i1 %19, label %20, label %65

20:                                               ; preds = %17
  %21 = call noalias ptr @malloc(i64 noundef 1) #6
  store ptr %21, ptr %7, align 8, !tbaa !9
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i32 1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %66

24:                                               ; preds = %20
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = mul nsw i32 %25, 9
  %27 = add nsw i32 8, %26
  %28 = srem i32 %27, 23
  %29 = add nsw i32 %28, 65
  %30 = trunc i32 %29 to i8
  %31 = load ptr, ptr %7, align 8, !tbaa !9
  store i8 %30, ptr %31, align 1, !tbaa !11
  %32 = load ptr, ptr @stdout, align 8, !tbaa !9
  %33 = load ptr, ptr %7, align 8, !tbaa !9
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = sext i8 %34 to i32
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str, i32 noundef %35) #5
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %51, %24
  %38 = load i32, ptr %11, align 4, !tbaa !5
  %39 = icmp slt i32 %38, 11
  br i1 %39, label %40, label %54

40:                                               ; preds = %37
  %41 = load ptr, ptr @stdout, align 8, !tbaa !9
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  %43 = call i32 @h1_char(ptr noundef %42)
  %44 = load i32, ptr %11, align 4, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !9
  %46 = call i32 @h2_char(ptr noundef %45)
  %47 = mul nsw i32 %44, %46
  %48 = add nsw i32 %43, %47
  %49 = srem i32 %48, 11
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef @.str.1, i32 noundef %49) #5
  br label %51

51:                                               ; preds = %40
  %52 = load i32, ptr %11, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %11, align 4, !tbaa !5
  br label %37, !llvm.loop !12

54:                                               ; preds = %37
  %55 = load ptr, ptr @stdout, align 8, !tbaa !9
  %56 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef @.str.2) #5
  %57 = load ptr, ptr %7, align 8, !tbaa !9
  %58 = call i32 @ohtbl_insert(ptr noundef %6, ptr noundef %57)
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %54
  store i32 1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %66

61:                                               ; preds = %54
  call void @print_table(ptr noundef %6)
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %10, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %10, align 4, !tbaa !5
  br label %17, !llvm.loop !14

65:                                               ; preds = %17
  call void @ohtbl_destroy(ptr noundef %6)
  store i32 0, ptr %12, align 4
  br label %66

66:                                               ; preds = %65, %60, %23, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %6) #5
  %67 = load i32, ptr %12, align 4
  switch i32 %67, label %70 [
    i32 0, label %68
    i32 1, label %68
  ]

68:                                               ; preds = %66, %66
  %69 = load i32, ptr %3, align 4
  ret i32 %69

70:                                               ; preds = %66
  unreachable
}

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

declare i32 @ohtbl_init(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @h1_char(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @h2_char(ptr noundef) #0

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare i32 @ohtbl_insert(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @print_table(ptr noundef) #0

declare void @ohtbl_destroy(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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) "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 #5 = { nounwind }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@stdout = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca %struct.OHTbl_, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #6
  %4 = call i32 @ohtbl_init(ptr noundef nonnull %3, i32 noundef 11, ptr noundef nonnull @h1_char, ptr noundef nonnull @h2_char, ptr noundef nonnull @match_char, ptr noundef nonnull @free) #6
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %2, %92
  %.01116 = phi i32 [ %93, %92 ], [ 0, %2 ]
  %5 = call noalias dereferenceable_or_null(1) ptr @malloc(i64 noundef 1) #7
  %6 = icmp eq ptr %5, null
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %.preheader
  %8 = mul nuw nsw i32 %.01116, 9
  %.cmp = icmp ult i32 %.01116, 2
  %.v = select i1 %.cmp, i32 8, i32 241
  %9 = add nuw nsw i32 %.v, %8
  %10 = trunc i32 %9 to i8
  %11 = add nuw nsw i8 %10, 65
  store i8 %11, ptr %5, align 1, !tbaa !5
  %12 = load ptr, ptr @stdout, align 8, !tbaa !8
  %13 = zext nneg i8 %11 to i32
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str, i32 noundef %13) #6
  %15 = load ptr, ptr @stdout, align 8, !tbaa !8
  %16 = call i32 @h1_char(ptr noundef nonnull %5)
  %17 = call i32 @h2_char(ptr noundef nonnull %5)
  %18 = srem i32 %16, 11
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.1, i32 noundef %18) #6
  %20 = load ptr, ptr @stdout, align 8, !tbaa !8
  %21 = call i32 @h1_char(ptr noundef nonnull %5)
  %22 = call i32 @h2_char(ptr noundef nonnull %5)
  %23 = add nsw i32 %22, %21
  %24 = srem i32 %23, 11
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str.1, i32 noundef %24) #6
  %26 = load ptr, ptr @stdout, align 8, !tbaa !8
  %27 = call i32 @h1_char(ptr noundef nonnull %5)
  %28 = call i32 @h2_char(ptr noundef nonnull %5)
  %29 = shl nsw i32 %28, 1
  %30 = add nsw i32 %29, %27
  %31 = srem i32 %30, 11
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str.1, i32 noundef %31) #6
  %33 = load ptr, ptr @stdout, align 8, !tbaa !8
  %34 = call i32 @h1_char(ptr noundef nonnull %5)
  %35 = call i32 @h2_char(ptr noundef nonnull %5)
  %36 = mul nsw i32 %35, 3
  %37 = add nsw i32 %36, %34
  %38 = srem i32 %37, 11
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef nonnull @.str.1, i32 noundef %38) #6
  %40 = load ptr, ptr @stdout, align 8, !tbaa !8
  %41 = call i32 @h1_char(ptr noundef nonnull %5)
  %42 = call i32 @h2_char(ptr noundef nonnull %5)
  %43 = shl nsw i32 %42, 2
  %44 = add nsw i32 %43, %41
  %45 = srem i32 %44, 11
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str.1, i32 noundef %45) #6
  %47 = load ptr, ptr @stdout, align 8, !tbaa !8
  %48 = call i32 @h1_char(ptr noundef nonnull %5)
  %49 = call i32 @h2_char(ptr noundef nonnull %5)
  %50 = mul nsw i32 %49, 5
  %51 = add nsw i32 %50, %48
  %52 = srem i32 %51, 11
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef nonnull @.str.1, i32 noundef %52) #6
  %54 = load ptr, ptr @stdout, align 8, !tbaa !8
  %55 = call i32 @h1_char(ptr noundef nonnull %5)
  %56 = call i32 @h2_char(ptr noundef nonnull %5)
  %57 = mul nsw i32 %56, 6
  %58 = add nsw i32 %57, %55
  %59 = srem i32 %58, 11
  %60 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %54, ptr noundef nonnull @.str.1, i32 noundef %59) #6
  %61 = load ptr, ptr @stdout, align 8, !tbaa !8
  %62 = call i32 @h1_char(ptr noundef nonnull %5)
  %63 = call i32 @h2_char(ptr noundef nonnull %5)
  %64 = mul nsw i32 %63, 7
  %65 = add nsw i32 %64, %62
  %66 = srem i32 %65, 11
  %67 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef nonnull @.str.1, i32 noundef %66) #6
  %68 = load ptr, ptr @stdout, align 8, !tbaa !8
  %69 = call i32 @h1_char(ptr noundef nonnull %5)
  %70 = call i32 @h2_char(ptr noundef nonnull %5)
  %71 = shl nsw i32 %70, 3
  %72 = add nsw i32 %71, %69
  %73 = srem i32 %72, 11
  %74 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef nonnull @.str.1, i32 noundef %73) #6
  %75 = load ptr, ptr @stdout, align 8, !tbaa !8
  %76 = call i32 @h1_char(ptr noundef nonnull %5)
  %77 = call i32 @h2_char(ptr noundef nonnull %5)
  %78 = mul nsw i32 %77, 9
  %79 = add nsw i32 %78, %76
  %80 = srem i32 %79, 11
  %81 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %75, ptr noundef nonnull @.str.1, i32 noundef %80) #6
  %82 = load ptr, ptr @stdout, align 8, !tbaa !8
  %83 = call i32 @h1_char(ptr noundef nonnull %5)
  %84 = call i32 @h2_char(ptr noundef nonnull %5)
  %85 = mul nsw i32 %84, 10
  %86 = add nsw i32 %85, %83
  %87 = srem i32 %86, 11
  %88 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %82, ptr noundef nonnull @.str.1, i32 noundef %87) #6
  %89 = load ptr, ptr @stdout, align 8, !tbaa !8
  %90 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %89, ptr noundef nonnull @.str.2) #6
  %91 = call i32 @ohtbl_insert(ptr noundef nonnull %3, ptr noundef nonnull %5) #6
  %.not14 = icmp eq i32 %91, 0
  br i1 %.not14, label %92, label %.loopexit

92:                                               ; preds = %7
  call void @print_table(ptr noundef nonnull %3)
  %93 = add nuw nsw i32 %.01116, 1
  %exitcond.not = icmp eq i32 %93, 5
  br i1 %exitcond.not, label %94, label %.preheader, !llvm.loop !10

94:                                               ; preds = %92
  call void @ohtbl_destroy(ptr noundef nonnull %3) #6
  br label %.loopexit

.loopexit:                                        ; preds = %7, %.preheader, %2, %94
  %.012 = phi i32 [ 0, %94 ], [ 1, %2 ], [ 1, %.preheader ], [ 1, %7 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #6
  ret i32 %.012
}

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

declare i32 @ohtbl_init(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @h1_char(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @h2_char(ptr noundef) #0

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

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

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

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

declare i32 @ohtbl_insert(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @print_table(ptr noundef) local_unnamed_addr #0

declare void @ohtbl_destroy(ptr 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

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 = { "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 = { 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 #4 = { 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass