; LLVM IR from kokobd/leetcode-hs :: csrc/src (p13)

; 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"

@romanTable = external hidden global [4 x [10 x ptr]], align 16

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

7:                                                ; preds = %40, %1
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = icmp sge i32 %8, 0
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %43

11:                                               ; preds = %7
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = mul nsw i32 %12, 10
  store i32 %13, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  store i8 0, ptr %5, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 9, ptr %6, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %29, %11
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp sge i32 %15, 0
  br i1 %16, label %17, label %32

17:                                               ; preds = %14
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [4 x [10 x ptr]], ptr @romanTable, i64 0, i64 %19
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [10 x ptr], ptr %20, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = call zeroext i1 @matchPrefix(ptr noundef %2, ptr noundef %24)
  %26 = zext i1 %25 to i8
  store i8 %26, ptr %5, align 1, !tbaa !11
  br i1 %25, label %27, label %28

27:                                               ; preds = %17
  br label %32

28:                                               ; preds = %17
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %6, align 4, !tbaa !9
  br label %14, !llvm.loop !13

32:                                               ; preds = %27, %14
  %33 = load i8, ptr %5, align 1, !tbaa !11, !range !15, !noundef !16
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %39

35:                                               ; preds = %32
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = add nsw i32 %37, %36
  store i32 %38, ptr %3, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %35, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = add nsw i32 %41, -1
  store i32 %42, ptr %4, align 4, !tbaa !9
  br label %7, !llvm.loop !17

43:                                               ; preds = %10
  %44 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %44
}

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @matchPrefix(ptr noundef, ptr noundef) #0

; 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 = { 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 = !{!"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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !14}


; 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"

@romanTable = external hidden local_unnamed_addr global [4 x [10 x ptr]], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @p13_romanToInt(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 312), align 8, !tbaa !5
  %4 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %3)
  br i1 %4, label %32, label %5

5:                                                ; preds = %1
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 304), align 16, !tbaa !5
  %7 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %6)
  br i1 %7, label %32, label %8

8:                                                ; preds = %5
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 296), align 8, !tbaa !5
  %10 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %9)
  br i1 %10, label %32, label %11

11:                                               ; preds = %8
  %12 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 288), align 16, !tbaa !5
  %13 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %12)
  br i1 %13, label %32, label %14

14:                                               ; preds = %11
  %15 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 280), align 8, !tbaa !5
  %16 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %15)
  br i1 %16, label %32, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 272), align 16, !tbaa !5
  %19 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %18)
  br i1 %19, label %32, label %20

20:                                               ; preds = %17
  %21 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 264), align 8, !tbaa !5
  %22 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %21)
  br i1 %22, label %32, label %23

23:                                               ; preds = %20
  %24 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 256), align 16, !tbaa !5
  %25 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %24)
  br i1 %25, label %32, label %26

26:                                               ; preds = %23
  %27 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 248), align 8, !tbaa !5
  %28 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %27)
  br i1 %28, label %32, label %29

29:                                               ; preds = %26
  %30 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 240), align 16, !tbaa !5
  %31 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %30)
  br label %32

32:                                               ; preds = %29, %26, %23, %20, %17, %14, %11, %8, %5, %1
  %33 = phi i32 [ 90, %1 ], [ 80, %5 ], [ 70, %8 ], [ 60, %11 ], [ 50, %14 ], [ 40, %17 ], [ 30, %20 ], [ 20, %23 ], [ 10, %26 ], [ 0, %29 ]
  %34 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 232), align 8, !tbaa !5
  %35 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %34)
  br i1 %35, label %63, label %36

36:                                               ; preds = %32
  %37 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 224), align 16, !tbaa !5
  %38 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %37)
  br i1 %38, label %63, label %39

39:                                               ; preds = %36
  %40 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 216), align 8, !tbaa !5
  %41 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %40)
  br i1 %41, label %63, label %42

42:                                               ; preds = %39
  %43 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 208), align 16, !tbaa !5
  %44 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %43)
  br i1 %44, label %63, label %45

45:                                               ; preds = %42
  %46 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 200), align 8, !tbaa !5
  %47 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %46)
  br i1 %47, label %63, label %48

48:                                               ; preds = %45
  %49 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 192), align 16, !tbaa !5
  %50 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %49)
  br i1 %50, label %63, label %51

51:                                               ; preds = %48
  %52 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 184), align 8, !tbaa !5
  %53 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %52)
  br i1 %53, label %63, label %54

54:                                               ; preds = %51
  %55 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 176), align 16, !tbaa !5
  %56 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %55)
  br i1 %56, label %63, label %57

57:                                               ; preds = %54
  %58 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 168), align 8, !tbaa !5
  %59 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %58)
  br i1 %59, label %63, label %60

60:                                               ; preds = %57
  %61 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 160), align 16, !tbaa !5
  %62 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %61)
  br label %63

63:                                               ; preds = %60, %57, %54, %51, %48, %45, %42, %39, %36, %32
  %64 = phi i32 [ 9, %32 ], [ 8, %36 ], [ 7, %39 ], [ 6, %42 ], [ 5, %45 ], [ 4, %48 ], [ 3, %51 ], [ 2, %54 ], [ 1, %57 ], [ 0, %60 ]
  %65 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 152), align 8, !tbaa !5
  %66 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %65)
  br i1 %66, label %94, label %67

67:                                               ; preds = %63
  %68 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 144), align 16, !tbaa !5
  %69 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %68)
  br i1 %69, label %94, label %70

70:                                               ; preds = %67
  %71 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 136), align 8, !tbaa !5
  %72 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %71)
  br i1 %72, label %94, label %73

73:                                               ; preds = %70
  %74 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 128), align 16, !tbaa !5
  %75 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %74)
  br i1 %75, label %94, label %76

76:                                               ; preds = %73
  %77 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 120), align 8, !tbaa !5
  %78 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %77)
  br i1 %78, label %94, label %79

79:                                               ; preds = %76
  %80 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 112), align 16, !tbaa !5
  %81 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %80)
  br i1 %81, label %94, label %82

82:                                               ; preds = %79
  %83 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 104), align 8, !tbaa !5
  %84 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %83)
  br i1 %84, label %94, label %85

85:                                               ; preds = %82
  %86 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 96), align 16, !tbaa !5
  %87 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %86)
  br i1 %87, label %94, label %88

88:                                               ; preds = %85
  %89 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 88), align 8, !tbaa !5
  %90 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %89)
  br i1 %90, label %94, label %91

91:                                               ; preds = %88
  %92 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 80), align 16, !tbaa !5
  %93 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %92)
  br label %94

94:                                               ; preds = %91, %88, %85, %82, %79, %76, %73, %70, %67, %63
  %95 = phi i32 [ 9, %63 ], [ 8, %67 ], [ 7, %70 ], [ 6, %73 ], [ 5, %76 ], [ 4, %79 ], [ 3, %82 ], [ 2, %85 ], [ 1, %88 ], [ 0, %91 ]
  %96 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 72), align 8, !tbaa !5
  %97 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %96)
  br i1 %97, label %125, label %98

98:                                               ; preds = %94
  %99 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 64), align 16, !tbaa !5
  %100 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %99)
  br i1 %100, label %125, label %101

101:                                              ; preds = %98
  %102 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 56), align 8, !tbaa !5
  %103 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %102)
  br i1 %103, label %125, label %104

104:                                              ; preds = %101
  %105 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 48), align 16, !tbaa !5
  %106 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %105)
  br i1 %106, label %125, label %107

107:                                              ; preds = %104
  %108 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 40), align 8, !tbaa !5
  %109 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %108)
  br i1 %109, label %125, label %110

110:                                              ; preds = %107
  %111 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 32), align 16, !tbaa !5
  %112 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %111)
  br i1 %112, label %125, label %113

113:                                              ; preds = %110
  %114 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 24), align 8, !tbaa !5
  %115 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %114)
  br i1 %115, label %125, label %116

116:                                              ; preds = %113
  %117 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 16), align 16, !tbaa !5
  %118 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %117)
  br i1 %118, label %125, label %119

119:                                              ; preds = %116
  %120 = load ptr, ptr getelementptr inbounds (i8, ptr @romanTable, i64 8), align 8, !tbaa !5
  %121 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %120)
  br i1 %121, label %125, label %122

122:                                              ; preds = %119
  %123 = load ptr, ptr @romanTable, align 16, !tbaa !5
  %124 = call zeroext i1 @matchPrefix(ptr noundef nonnull %2, ptr noundef %123)
  br label %125

125:                                              ; preds = %122, %119, %116, %113, %110, %107, %104, %101, %98, %94
  %126 = phi i32 [ 9, %94 ], [ 8, %98 ], [ 7, %101 ], [ 6, %104 ], [ 5, %107 ], [ 4, %110 ], [ 3, %113 ], [ 2, %116 ], [ 1, %119 ], [ 0, %122 ]
  %spec.select.1 = add nuw nsw i32 %64, %33
  %127 = mul nuw nsw i32 %spec.select.1, 10
  %spec.select.2 = add nuw nsw i32 %95, %127
  %128 = mul nuw nsw i32 %spec.select.2, 10
  %spec.select.3 = add nuw nsw i32 %126, %128
  ret i32 %spec.select.3
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @matchPrefix(ptr noundef, ptr noundef) local_unnamed_addr #0

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

!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"}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass