; LLVM IR from lolosssss/leetcode :: c (43_multiply_strings)

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

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @multiply(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %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
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call i64 @strlen(ptr noundef %14) #6
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call i64 @strlen(ptr noundef %17) #6
  %19 = trunc i64 %18 to i32
  store i32 %19, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = add nsw i32 %20, %21
  %23 = add nsw i32 %22, 2
  %24 = sext i32 %23 to i64
  %25 = mul i64 1, %24
  %26 = call noalias ptr @malloc(i64 noundef %25) #7
  store ptr %26, ptr %12, align 8, !tbaa !5
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = add nsw i32 %28, %29
  %31 = sext i32 %30 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %27, i8 48, i64 %31, i1 false)
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = add nsw i32 %33, %34
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %32, i64 %36
  store i8 0, ptr %37, align 1, !tbaa !11
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = sub nsw i32 %38, 1
  store i32 %39, ptr %10, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %104, %2
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = icmp sge i32 %41, 0
  br i1 %42, label %43, label %107

43:                                               ; preds = %40
  store i32 0, ptr %8, align 4, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = sub nsw i32 %44, 1
  store i32 %45, ptr %11, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %91, %43
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = icmp sge i32 %47, 0
  br i1 %48, label %49, label %94

49:                                               ; preds = %46
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = add nsw i32 %51, %52
  %54 = add nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %50, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !11
  %58 = sext i8 %57 to i32
  %59 = sub nsw i32 %58, 48
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %60, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !11
  %65 = sext i8 %64 to i32
  %66 = sub nsw i32 %65, 48
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load i32, ptr %11, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %67, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !11
  %72 = sext i8 %71 to i32
  %73 = sub nsw i32 %72, 48
  %74 = mul nsw i32 %66, %73
  %75 = add nsw i32 %59, %74
  %76 = load i32, ptr %8, align 4, !tbaa !9
  %77 = add nsw i32 %75, %76
  store i32 %77, ptr %9, align 4, !tbaa !9
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = srem i32 %78, 10
  %80 = add nsw i32 %79, 48
  %81 = trunc i32 %80 to i8
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  %83 = load i32, ptr %10, align 4, !tbaa !9
  %84 = load i32, ptr %11, align 4, !tbaa !9
  %85 = add nsw i32 %83, %84
  %86 = add nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i8, ptr %82, i64 %87
  store i8 %81, ptr %88, align 1, !tbaa !11
  %89 = load i32, ptr %9, align 4, !tbaa !9
  %90 = sdiv i32 %89, 10
  store i32 %90, ptr %8, align 4, !tbaa !9
  br label %91

91:                                               ; preds = %49
  %92 = load i32, ptr %11, align 4, !tbaa !9
  %93 = add nsw i32 %92, -1
  store i32 %93, ptr %11, align 4, !tbaa !9
  br label %46, !llvm.loop !12

94:                                               ; preds = %46
  %95 = load i32, ptr %8, align 4, !tbaa !9
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = load i32, ptr %10, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds i8, ptr %96, i64 %98
  %100 = load i8, ptr %99, align 1, !tbaa !11
  %101 = sext i8 %100 to i32
  %102 = add nsw i32 %101, %95
  %103 = trunc i32 %102 to i8
  store i8 %103, ptr %99, align 1, !tbaa !11
  br label %104

104:                                              ; preds = %94
  %105 = load i32, ptr %10, align 4, !tbaa !9
  %106 = add nsw i32 %105, -1
  store i32 %106, ptr %10, align 4, !tbaa !9
  br label %40, !llvm.loop !14

107:                                              ; preds = %40
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %108

108:                                              ; preds = %128, %107
  %109 = load i32, ptr %10, align 4, !tbaa !9
  %110 = load i32, ptr %6, align 4, !tbaa !9
  %111 = load i32, ptr %7, align 4, !tbaa !9
  %112 = add nsw i32 %110, %111
  %113 = icmp slt i32 %109, %112
  br i1 %113, label %114, label %131

114:                                              ; preds = %108
  %115 = load ptr, ptr %12, align 8, !tbaa !5
  %116 = load i32, ptr %10, align 4, !tbaa !9
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds i8, ptr %115, i64 %117
  %119 = load i8, ptr %118, align 1, !tbaa !11
  %120 = sext i8 %119 to i32
  %121 = icmp ne i32 %120, 48
  br i1 %121, label %122, label %127

122:                                              ; preds = %114
  %123 = load ptr, ptr %12, align 8, !tbaa !5
  %124 = load i32, ptr %10, align 4, !tbaa !9
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds i8, ptr %123, i64 %125
  store ptr %126, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %132

127:                                              ; preds = %114
  br label %128

128:                                              ; preds = %127
  %129 = load i32, ptr %10, align 4, !tbaa !9
  %130 = add nsw i32 %129, 1
  store i32 %130, ptr %10, align 4, !tbaa !9
  br label %108, !llvm.loop !15

131:                                              ; preds = %108
  store ptr @.str, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %132

132:                                              ; preds = %131, %122
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  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 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %133 = load ptr, ptr %3, align 8
  ret ptr %133
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #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: 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 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 #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 }
attributes #6 = { nounwind willreturn memory(read) }
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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !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"

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nofree nounwind memory(readwrite, argmem: read) uwtable
define dso_local ptr @multiply(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %4 = trunc i64 %3 to i32
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #4
  %6 = trunc i64 %5 to i32
  %7 = add nsw i32 %6, %4
  %8 = add nsw i32 %7, 2
  %9 = sext i32 %8 to i64
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #5
  %11 = sext i32 %7 to i64
  tail call void @llvm.memset.p0.i64(ptr align 1 %10, i8 48, i64 %11, i1 false)
  %12 = getelementptr inbounds i8, ptr %10, i64 %11
  store i8 0, ptr %12, align 1, !tbaa !5
  %13 = icmp sgt i32 %4, 0
  %14 = icmp sgt i32 %6, 0
  %or.cond = and i1 %13, %14
  br i1 %or.cond, label %.preheader43.us.preheader, label %.preheader

.preheader43.us.preheader:                        ; preds = %2
  %.04146 = add i64 %3, 4294967295
  %15 = and i64 %5, 2147483647
  %16 = and i64 %.04146, 4294967295
  br label %.preheader43.us

.preheader43.us:                                  ; preds = %.preheader43.us.preheader, %._crit_edge.us
  %indvars.iv55 = phi i64 [ %16, %.preheader43.us.preheader ], [ %indvars.iv.next56, %._crit_edge.us ]
  %17 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv55
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = sext i8 %18 to i32
  %20 = add nsw i32 %19, -48
  %invariant.gep = getelementptr i8, ptr %10, i64 %indvars.iv55
  br label %21

21:                                               ; preds = %.preheader43.us, %21
  %indvars.iv = phi i64 [ %15, %.preheader43.us ], [ %indvars.iv.next, %21 ]
  %.04244.us = phi i32 [ 0, %.preheader43.us ], [ %35, %21 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %gep = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv
  %22 = load i8, ptr %gep, align 1, !tbaa !5
  %23 = sext i8 %22 to i32
  %24 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = sext i8 %25 to i32
  %27 = add nsw i32 %26, -48
  %28 = mul nsw i32 %27, %20
  %29 = add nsw i32 %.04244.us, -48
  %30 = add nsw i32 %29, %23
  %31 = add nsw i32 %30, %28
  %32 = srem i32 %31, 10
  %33 = trunc nsw i32 %32 to i8
  %34 = add nsw i8 %33, 48
  store i8 %34, ptr %gep, align 1, !tbaa !5
  %35 = sdiv i32 %31, 10
  %36 = icmp sgt i64 %indvars.iv, 1
  br i1 %36, label %21, label %._crit_edge.us, !llvm.loop !8

._crit_edge.us:                                   ; preds = %21
  %37 = getelementptr inbounds i8, ptr %10, i64 %indvars.iv55
  %38 = load i8, ptr %37, align 1, !tbaa !5
  %39 = trunc i32 %35 to i8
  %40 = add i8 %38, %39
  store i8 %40, ptr %37, align 1, !tbaa !5
  %indvars.iv.next56 = add nsw i64 %indvars.iv55, -1
  %41 = icmp sgt i64 %indvars.iv55, 0
  br i1 %41, label %.preheader43.us, label %.preheader, !llvm.loop !10

.preheader:                                       ; preds = %._crit_edge.us, %2
  %42 = icmp sgt i32 %7, 0
  br i1 %42, label %.lr.ph.preheader, label %.split.loop.exit

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %7 to i64
  br label %.lr.ph

43:                                               ; preds = %.lr.ph
  %indvars.iv.next59 = add nuw nsw i64 %indvars.iv58, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next59, %wide.trip.count
  br i1 %exitcond.not, label %.split.loop.exit, label %.lr.ph, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph.preheader, %43
  %indvars.iv58 = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next59, %43 ]
  %44 = getelementptr inbounds i8, ptr %10, i64 %indvars.iv58
  %45 = load i8, ptr %44, align 1, !tbaa !5
  %.not = icmp eq i8 %45, 48
  br i1 %.not, label %43, label %.split.loop.exit.loopexit.split.loop.exit

.split.loop.exit.loopexit.split.loop.exit:        ; preds = %.lr.ph
  %46 = getelementptr inbounds i8, ptr %10, i64 %indvars.iv58
  br label %.split.loop.exit

.split.loop.exit:                                 ; preds = %43, %.split.loop.exit.loopexit.split.loop.exit, %.preheader
  %.0 = phi ptr [ @.str, %.preheader ], [ %46, %.split.loop.exit.loopexit.split.loop.exit ], [ @.str, %43 ]
  ret ptr %.0
}

; 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 allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

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

attributes #0 = { nofree nounwind memory(readwrite, argmem: read) 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 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind willreturn memory(read) }
attributes #5 = { 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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = distinct !{!11, !9}


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