; LLVM IR from bhrigukansra/algorithms-in-C-Cplusplus-Java-Python-JavaScript :: Algorithms/Mathematics/C (karatsuba)

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @intlen(i32 noundef) #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @karatsuba(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %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 i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = call i32 @intlen(i32 noundef %15)
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %22, label %18

18:                                               ; preds = %2
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = call i32 @intlen(i32 noundef %19)
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %22, label %26

22:                                               ; preds = %18, %2
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = mul nsw i32 %23, %24
  store i32 %25, ptr %3, align 4
  br label %100

26:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = call i32 @intlen(i32 noundef %27)
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = call i32 @intlen(i32 noundef %29)
  %31 = icmp sge i32 %28, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %26
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = call i32 @intlen(i32 noundef %33)
  br label %38

35:                                               ; preds = %26
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = call i32 @intlen(i32 noundef %36)
  br label %38

38:                                               ; preds = %35, %32
  %39 = phi i32 [ %34, %32 ], [ %37, %35 ]
  store i32 %39, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = sdiv i32 %40, 2
  store i32 %41, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sitofp i32 %43 to double
  %45 = call double @pow(double noundef 1.000000e+01, double noundef %44) #4
  %46 = fptosi double %45 to i32
  %47 = sdiv i32 %42, %46
  store i32 %47, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = sitofp i32 %49 to double
  %51 = call double @pow(double noundef 1.000000e+01, double noundef %50) #4
  %52 = fptosi double %51 to i32
  %53 = srem i32 %48, %52
  store i32 %53, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sitofp i32 %55 to double
  %57 = call double @pow(double noundef 1.000000e+01, double noundef %56) #4
  %58 = fptosi double %57 to i32
  %59 = sdiv i32 %54, %58
  store i32 %59, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = sitofp i32 %61 to double
  %63 = call double @pow(double noundef 1.000000e+01, double noundef %62) #4
  %64 = fptosi double %63 to i32
  %65 = srem i32 %60, %64
  store i32 %65, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = call i32 @karatsuba(i32 noundef %66, i32 noundef %67)
  store i32 %68, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %69 = load i32, ptr %9, align 4, !tbaa !5
  %70 = load i32, ptr %11, align 4, !tbaa !5
  %71 = call i32 @karatsuba(i32 noundef %69, i32 noundef %70)
  store i32 %71, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = load i32, ptr %9, align 4, !tbaa !5
  %74 = add nsw i32 %72, %73
  %75 = load i32, ptr %10, align 4, !tbaa !5
  %76 = load i32, ptr %11, align 4, !tbaa !5
  %77 = add nsw i32 %75, %76
  %78 = call i32 @karatsuba(i32 noundef %74, i32 noundef %77)
  %79 = load i32, ptr %12, align 4, !tbaa !5
  %80 = sub nsw i32 %78, %79
  %81 = load i32, ptr %13, align 4, !tbaa !5
  %82 = sub nsw i32 %80, %81
  store i32 %82, ptr %14, align 4, !tbaa !5
  %83 = load i32, ptr %12, align 4, !tbaa !5
  %84 = sitofp i32 %83 to double
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = mul nsw i32 2, %85
  %87 = sitofp i32 %86 to double
  %88 = call double @pow(double noundef 1.000000e+01, double noundef %87) #4
  %89 = load i32, ptr %14, align 4, !tbaa !5
  %90 = sitofp i32 %89 to double
  %91 = load i32, ptr %7, align 4, !tbaa !5
  %92 = sitofp i32 %91 to double
  %93 = call double @pow(double noundef 1.000000e+01, double noundef %92) #4
  %94 = fmul double %90, %93
  %95 = call double @llvm.fmuladd.f64(double %84, double %88, double %94)
  %96 = load i32, ptr %13, align 4, !tbaa !5
  %97 = sitofp i32 %96 to double
  %98 = fadd double %95, %97
  %99 = fptosi double %98 to i32
  store i32 %99, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %100

100:                                              ; preds = %38, %22
  %101 = load i32, ptr %3, align 4
  ret i32 %101
}

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

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 "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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"}


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @intlen(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @karatsuba(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @intlen(i32 noundef %0)
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %common.ret, label %5

5:                                                ; preds = %2
  %6 = tail call i32 @intlen(i32 noundef %1)
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %common.ret, label %9

common.ret:                                       ; preds = %5, %2
  %8 = mul nsw i32 %1, %0
  br label %common.ret35

common.ret35:                                     ; preds = %common.ret, %9
  %common.ret35.op = phi i32 [ %44, %9 ], [ %8, %common.ret ]
  ret i32 %common.ret35.op

9:                                                ; preds = %5
  %10 = tail call i32 @intlen(i32 noundef %0)
  %11 = tail call i32 @intlen(i32 noundef %1)
  %.not = icmp slt i32 %10, %11
  %. = select i1 %.not, i32 %1, i32 %0
  %12 = tail call i32 @intlen(i32 noundef %.)
  %13 = sdiv i32 %12, 2
  %14 = sitofp i32 %13 to double
  %15 = tail call double @pow(double noundef 1.000000e+01, double noundef %14) #3
  %16 = fptosi double %15 to i32
  %17 = sdiv i32 %0, %16
  %18 = tail call double @pow(double noundef 1.000000e+01, double noundef %14) #3
  %19 = fptosi double %18 to i32
  %20 = srem i32 %0, %19
  %21 = tail call double @pow(double noundef 1.000000e+01, double noundef %14) #3
  %22 = fptosi double %21 to i32
  %23 = sdiv i32 %1, %22
  %24 = tail call double @pow(double noundef 1.000000e+01, double noundef %14) #3
  %25 = fptosi double %24 to i32
  %26 = srem i32 %1, %25
  %27 = tail call i32 @karatsuba(i32 noundef %17, i32 noundef %23)
  %28 = tail call i32 @karatsuba(i32 noundef %20, i32 noundef %26)
  %29 = add nsw i32 %20, %17
  %30 = add nsw i32 %26, %23
  %31 = tail call i32 @karatsuba(i32 noundef %29, i32 noundef %30)
  %32 = add i32 %28, %27
  %33 = sub i32 %31, %32
  %34 = sitofp i32 %27 to double
  %35 = shl nsw i32 %13, 1
  %36 = sitofp i32 %35 to double
  %37 = tail call double @pow(double noundef 1.000000e+01, double noundef %36) #3
  %38 = sitofp i32 %33 to double
  %39 = tail call double @pow(double noundef 1.000000e+01, double noundef %14) #3
  %40 = fmul double %39, %38
  %41 = tail call double @llvm.fmuladd.f64(double %34, double %37, double %40)
  %42 = sitofp i32 %28 to double
  %43 = fadd double %41, %42
  %44 = fptosi double %43 to i32
  br label %common.ret35
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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 nofree nounwind willreturn memory(write) "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass