; LLVM IR from VAR-solutions/Algorithms :: Mathematics/Karatsuba/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 @size(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
declare dso_local i32 @max(i32 noundef, i32 noundef) #0

; 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 = icmp slt i32 %15, 10
  br i1 %16, label %17, label %24

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

20:                                               ; preds = %17
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = mul nsw i32 %21, %22
  store i32 %23, ptr %3, align 4
  br label %89

24:                                               ; preds = %17, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = call i32 @size(i32 noundef %25)
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = call i32 @size(i32 noundef %27)
  %29 = call i32 @max(i32 noundef %26, i32 noundef %28)
  store i32 %29, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = sdiv i32 %30, 2
  store i32 %31, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = sitofp i32 %33 to double
  %35 = call double @pow(double noundef 1.000000e+01, double noundef %34) #3
  %36 = fptosi double %35 to i32
  %37 = sdiv i32 %32, %36
  store i32 %37, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = sitofp i32 %39 to double
  %41 = call double @pow(double noundef 1.000000e+01, double noundef %40) #3
  %42 = fptosi double %41 to i32
  %43 = srem i32 %38, %42
  store i32 %43, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = sitofp i32 %45 to double
  %47 = call double @pow(double noundef 1.000000e+01, double noundef %46) #3
  %48 = fptosi double %47 to i32
  %49 = sdiv i32 %44, %48
  store i32 %49, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sitofp i32 %51 to double
  %53 = call double @pow(double noundef 1.000000e+01, double noundef %52) #3
  %54 = fptosi double %53 to i32
  %55 = srem i32 %50, %54
  store i32 %55, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = load i32, ptr %11, align 4, !tbaa !5
  %58 = call i32 @karatsuba(i32 noundef %56, i32 noundef %57)
  store i32 %58, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = add nsw i32 %59, %60
  %62 = load i32, ptr %11, align 4, !tbaa !5
  %63 = load i32, ptr %10, align 4, !tbaa !5
  %64 = add nsw i32 %62, %63
  %65 = call i32 @karatsuba(i32 noundef %61, i32 noundef %64)
  store i32 %65, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %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 %14, align 4, !tbaa !5
  %69 = load i32, ptr %14, align 4, !tbaa !5
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = mul nsw i32 %70, 2
  %72 = sitofp i32 %71 to double
  %73 = call double @pow(double noundef 1.000000e+01, double noundef %72) #3
  %74 = fptosi double %73 to i32
  %75 = mul nsw i32 %69, %74
  %76 = load i32, ptr %13, align 4, !tbaa !5
  %77 = load i32, ptr %14, align 4, !tbaa !5
  %78 = sub nsw i32 %76, %77
  %79 = load i32, ptr %12, align 4, !tbaa !5
  %80 = sub nsw i32 %78, %79
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = sitofp i32 %81 to double
  %83 = call double @pow(double noundef 1.000000e+01, double noundef %82) #3
  %84 = fptosi double %83 to i32
  %85 = mul nsw i32 %80, %84
  %86 = add nsw i32 %75, %85
  %87 = load i32, ptr %12, align 4, !tbaa !5
  %88 = add nsw i32 %86, %87
  store i32 %88, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %89

89:                                               ; preds = %24, %20
  %90 = load i32, ptr %3, align 4
  ret i32 %90
}

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #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 = { 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 = { 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 @size(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @max(i32 noundef, 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 = icmp slt i32 %0, 10
  %4 = icmp slt i32 %1, 10
  %or.cond = and i1 %3, %4
  br i1 %or.cond, label %common.ret, label %6

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

common.ret36:                                     ; preds = %6, %common.ret
  %common.ret36.op = phi i32 [ %5, %common.ret ], [ %40, %6 ]
  ret i32 %common.ret36.op

6:                                                ; preds = %2
  %7 = tail call i32 @size(i32 noundef %0)
  %8 = tail call i32 @size(i32 noundef %1)
  %9 = tail call i32 @max(i32 noundef %7, i32 noundef %8)
  %10 = sdiv i32 %9, 2
  %11 = sitofp i32 %10 to double
  %12 = tail call double @pow(double noundef 1.000000e+01, double noundef %11) #2
  %13 = fptosi double %12 to i32
  %14 = sdiv i32 %0, %13
  %15 = tail call double @pow(double noundef 1.000000e+01, double noundef %11) #2
  %16 = fptosi double %15 to i32
  %17 = srem i32 %0, %16
  %18 = tail call double @pow(double noundef 1.000000e+01, double noundef %11) #2
  %19 = fptosi double %18 to i32
  %20 = sdiv i32 %1, %19
  %21 = tail call double @pow(double noundef 1.000000e+01, double noundef %11) #2
  %22 = fptosi double %21 to i32
  %23 = srem i32 %1, %22
  %24 = tail call i32 @karatsuba(i32 noundef %17, i32 noundef %23)
  %25 = add nsw i32 %17, %14
  %26 = add nsw i32 %23, %20
  %27 = tail call i32 @karatsuba(i32 noundef %25, i32 noundef %26)
  %28 = tail call i32 @karatsuba(i32 noundef %14, i32 noundef %20)
  %29 = shl nsw i32 %10, 1
  %30 = sitofp i32 %29 to double
  %31 = tail call double @pow(double noundef 1.000000e+01, double noundef %30) #2
  %32 = fptosi double %31 to i32
  %33 = mul nsw i32 %28, %32
  %34 = add i32 %24, %28
  %35 = sub i32 %27, %34
  %36 = tail call double @pow(double noundef 1.000000e+01, double noundef %11) #2
  %37 = fptosi double %36 to i32
  %38 = mul nsw i32 %35, %37
  %39 = add i32 %33, %24
  %40 = add i32 %39, %38
  br label %common.ret36
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #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 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 = { 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