; LLVM IR from lolosssss/leetcode :: c (12_integer_to_roman)

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

@__const.intToRoman.values = external hidden unnamed_addr constant [13 x i32], align 16
@__const.intToRoman.symbols = external hidden unnamed_addr constant [13 x [13 x i8]], align 16

; Function Attrs: nounwind uwtable
define dso_local ptr @intToRoman(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca [13 x i32], align 16
  %4 = alloca [13 x [13 x i8]], align 16
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 52, ptr %3) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.intToRoman.values, i64 52, i1 false)
  call void @llvm.lifetime.start.p0(i64 169, ptr %4) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const.intToRoman.symbols, i64 169, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %11 = call noalias ptr @malloc(i64 noundef 32) #8
  store ptr %11, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  store i32 0, ptr %9, align 4, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %12, i8 0, i64 32, i1 false)
  br label %13

13:                                               ; preds = %57, %1
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %16, label %60

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [13 x i32], ptr %3, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sdiv i32 %17, %21
  store i32 %22, ptr %10, align 4, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %54, %16
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %57

27:                                               ; preds = %23
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [13 x [13 x i8]], ptr %4, i64 0, i64 %29
  %31 = getelementptr inbounds [13 x i8], ptr %30, i64 0, i64 0
  %32 = call i64 @strlen(ptr noundef %31) #9
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %9, align 4, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %34, i64 %36
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [13 x [13 x i8]], ptr %4, i64 0, i64 %39
  %41 = getelementptr inbounds [13 x i8], ptr %40, i64 0, i64 0
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = call ptr @strncat(ptr noundef %37, ptr noundef %41, i64 noundef %43) #7
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = add nsw i32 %46, %45
  store i32 %47, ptr %8, align 4, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [13 x i32], ptr %3, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = sub nsw i32 %52, %51
  store i32 %53, ptr %2, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %27
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %7, align 4, !tbaa !5
  br label %23, !llvm.loop !11

57:                                               ; preds = %23
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %13, !llvm.loop !13

60:                                               ; preds = %13
  %61 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 169, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 52, ptr %3) #7
  ret ptr %61
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #5

; Function Attrs: nounwind
declare ptr @strncat(ptr noundef, ptr noundef, i64 noundef) #6

; 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind willreturn memory(read) "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 "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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { nounwind willreturn memory(read) }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@__const.intToRoman.values = external hidden unnamed_addr constant [13 x i32], align 16
@__const.intToRoman.symbols = external hidden unnamed_addr constant [13 x [13 x i8]], align 16

; Function Attrs: nofree nounwind memory(readwrite, argmem: none) uwtable
define dso_local noundef ptr @intToRoman(i32 noundef %0) local_unnamed_addr #0 {
  %calloc = tail call dereferenceable_or_null(32) ptr @calloc(i64 1, i64 32)
  %2 = icmp sgt i32 %0, 0
  br i1 %2, label %.lr.ph29, label %._crit_edge30

.lr.ph29:                                         ; preds = %1, %._crit_edge
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %._crit_edge ], [ 0, %1 ]
  %.027 = phi i32 [ %.1.lcssa, %._crit_edge ], [ %0, %1 ]
  %.01726 = phi i32 [ %.118.lcssa, %._crit_edge ], [ 0, %1 ]
  %3 = getelementptr inbounds [13 x i32], ptr @__const.intToRoman.values, i64 0, i64 %indvars.iv33
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = sdiv i32 %.027, %4
  %.recomposed = srem i32 %.027, %4
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph29
  %7 = getelementptr inbounds [13 x [13 x i8]], ptr @__const.intToRoman.symbols, i64 0, i64 %indvars.iv33
  %8 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %7) #4
  %sext = shl i64 %8, 32
  %9 = ashr exact i64 %sext, 32
  %10 = sext i32 %.01726 to i64
  %sext36 = shl i64 %8, 32
  %11 = ashr exact i64 %sext36, 32
  %12 = mul i32 %4, %5
  br label %13

13:                                               ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ %10, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %.01921 = phi i32 [ 0, %.lr.ph ], [ %16, %13 ]
  %14 = getelementptr inbounds i8, ptr %calloc, i64 %indvars.iv
  %15 = tail call ptr @strncat(ptr noundef nonnull dereferenceable(1) %14, ptr noundef nonnull %7, i64 noundef %9) #5
  %indvars.iv.next = add nsw i64 %indvars.iv, %11
  %16 = add nuw nsw i32 %.01921, 1
  %exitcond.not = icmp eq i32 %16, %5
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %13, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %13
  %17 = trunc nsw i64 %indvars.iv.next to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph29
  %.118.lcssa = phi i32 [ %.01726, %.lr.ph29 ], [ %17, %._crit_edge.loopexit ]
  %.1.lcssa = phi i32 [ %.027, %.lr.ph29 ], [ %.recomposed, %._crit_edge.loopexit ]
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %18 = icmp sgt i32 %.1.lcssa, 0
  br i1 %18, label %.lr.ph29, label %._crit_edge30, !llvm.loop !11

._crit_edge30:                                    ; preds = %._crit_edge, %1
  ret ptr %calloc
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { nofree nounwind memory(readwrite, argmem: none) 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 nofree nounwind willreturn memory(argmem: read) "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 nofree nounwind willreturn memory(argmem: readwrite) "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 willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #4 = { nounwind willreturn memory(read) }
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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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