#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int arrToInt(int *, int);
int /*<<< orphan*/ free(int *);
int pow(int, int);
int *splitIntArray(int *, int, int);
int multiply(int *n1, int len1, int *n2, int len2) {
  int n, term1, term2, term3;
  int *a, *b, *c, *d;
  if (len1 == 1 || len2 == 1) {
    return arrToInt(n1, len1) * arrToInt(n2, len2);
  } else {
    n = len1 > len2 ? len1 : len2;
    a = splitIntArray(n1, len1, 0);
    b = splitIntArray(n1, len1, 1);
    c = splitIntArray(n2, len2, 0);
    d = splitIntArray(n2, len2, 1);
    term1 = pow(10, n) * multiply(a, len1 / 2, c, len2 / 2);
    term2 = pow(10, n / 2) * (multiply(a, len1 / 2, d, len2 / 2) +
                              multiply(b, len1 / 2, c, len2 / 2));
    term3 = multiply(b, len1 / 2, d, len2 / 2);
    free(d);
    free(c);
    free(b);
    free(a);
    return term1 + term2 + term3;
  }
}


x86 assembly (clang, -O0):
<multiply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpl   $0x1,-0x14(%rbp)
je     117d <multiply+0x2d>
cmpl   $0x1,-0x24(%rbp)
jne    11a8 <multiply+0x58>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <arrToInt@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <arrToInt@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    135c <multiply+0x20c>
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    11bf <multiply+0x6f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x60(%rbp)
jmp    11c5 <multiply+0x75>
mov    -0x24(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
xor    %edx,%edx
call   1040 <splitIntArray@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1040 <splitIntArray@plt>
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
xor    %edx,%edx
call   1040 <splitIntArray@plt>
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    $0x1,%edx
call   1040 <splitIntArray@plt>
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%esi
mov    $0xa,%edi
call   1070 <pow@plt>
mov    %eax,-0x84(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x50(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x90(%rbp),%rdx
mov    %eax,%ecx
call   1050 <multiply@plt>
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    $0xa,%edi
call   1070 <pow@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x58(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x80(%rbp),%rdx
mov    %eax,%ecx
call   1050 <multiply@plt>
mov    %eax,-0x70(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x50(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x78(%rbp),%rdx
mov    %eax,%ecx
call   1050 <multiply@plt>
mov    -0x70(%rbp),%ecx
mov    %eax,%edx
mov    -0x6c(%rbp),%eax
add    %edx,%ecx
imul   %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x58(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x68(%rbp),%rdx
mov    %eax,%ecx
call   1050 <multiply@plt>
mov    %eax,-0x34(%rbp)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiply>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbp
cmp    $0x1,%esi
je     12a7 <multiply+0x157>
cmp    $0x1,%ebx
je     12a7 <multiply+0x157>
cmp    %ebx,%r15d
mov    %ebx,%r12d
cmovg  %r15d,%r12d
mov    %rbp,%rdi
mov    %r15d,%esi
xor    %edx,%edx
call   1040 <splitIntArray@plt>
mov    %rax,0x18(%rsp)
mov    %rbp,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
call   1040 <splitIntArray@plt>
mov    %rax,0x30(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1040 <splitIntArray@plt>
mov    %rax,0x20(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
call   1040 <splitIntArray@plt>
mov    %rax,0x28(%rsp)
mov    $0xa,%edi
mov    %r12d,%esi
call   1070 <pow@plt>
mov    %eax,%r13d
mov    %r15d,%r14d
shr    $0x1f,%r14d
add    %r15d,%r14d
sar    %r14d
mov    %ebx,%ebp
shr    $0x1f,%ebp
add    %ebx,%ebp
sar    %ebp
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    0x20(%rsp),%r15
mov    %r15,%rdx
mov    %ebp,%ecx
call   1050 <multiply@plt>
imul   %r13d,%eax
mov    %eax,0x14(%rsp)
mov    %r12d,%esi
shr    $0x1f,%esi
add    %r12d,%esi
sar    %esi
mov    $0xa,%edi
call   1070 <pow@plt>
mov    %eax,0x10(%rsp)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    0x28(%rsp),%r13
mov    %r13,%rdx
mov    %ebp,%ecx
call   1050 <multiply@plt>
mov    %eax,0xc(%rsp)
mov    0x30(%rsp),%r12
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
mov    %ebp,%ecx
call   1050 <multiply@plt>
mov    %eax,%ebx
add    0xc(%rsp),%ebx
imul   0x10(%rsp),%ebx
mov    %r12,%rdi
mov    %r14d,%esi
mov    %r13,%rdx
mov    %ebp,%ecx
call   1050 <multiply@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
add    0x14(%rsp),%ebp
add    %ebx,%ebp
jmp    12c5 <multiply+0x175>
mov    %rbp,%rdi
mov    %r15d,%esi
call   1060 <arrToInt@plt>
mov    %eax,%r15d
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <arrToInt@plt>
mov    %eax,%ebp
imul   %r15d,%ebp
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @multiply(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 1
br i1 %19, label %23, label %20
20: ; preds = %4
%21 = load i32, i32* %9
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %31
23: ; preds = %20, %4
%24 = load i32*, i32** %6
%25 = load i32, i32* %7
%26 = call i32 @arrToInt(i32* %24, i32 %25)
%27 = load i32*, i32** %8
%28 = load i32, i32* %9
%29 = call i32 @arrToInt(i32* %27, i32 %28)
%30 = mul nsw i32 %26, %29
store i32 %30, i32* %5
br label %102
31: ; preds = %20
%32 = load i32, i32* %7
%33 = load i32, i32* %9
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = load i32, i32* %7
br label %39
37: ; preds = %31
%38 = load i32, i32* %9
br label %39
39: ; preds = %37, %35
%40 = phi i32 [ %36, %35 ], [ %38, %37 ]
store i32 %40, i32* %10
%41 = load i32*, i32** %6
%42 = load i32, i32* %7
%43 = call i32* @splitIntArray(i32* %41, i32 %42, i32 0)
store i32* %43, i32** %14
%44 = load i32*, i32** %6
%45 = load i32, i32* %7
%46 = call i32* @splitIntArray(i32* %44, i32 %45, i32 1)
store i32* %46, i32** %15
%47 = load i32*, i32** %8
%48 = load i32, i32* %9
%49 = call i32* @splitIntArray(i32* %47, i32 %48, i32 0)
store i32* %49, i32** %16
%50 = load i32*, i32** %8
%51 = load i32, i32* %9
%52 = call i32* @splitIntArray(i32* %50, i32 %51, i32 1)
store i32* %52, i32** %17
%53 = load i32, i32* %10
%54 = call i32 @pow(i32 10, i32 %53)
%55 = load i32*, i32** %14
%56 = load i32, i32* %7
%57 = sdiv i32 %56, 2
%58 = load i32*, i32** %16
%59 = load i32, i32* %9
%60 = sdiv i32 %59, 2
%61 = call i32 @multiply(i32* %55, i32 %57, i32* %58, i32 %60)
%62 = mul nsw i32 %54, %61
store i32 %62, i32* %11
%63 = load i32, i32* %10
%64 = sdiv i32 %63, 2
%65 = call i32 @pow(i32 10, i32 %64)
%66 = load i32*, i32** %14
%67 = load i32, i32* %7
%68 = sdiv i32 %67, 2
%69 = load i32*, i32** %17
%70 = load i32, i32* %9
%71 = sdiv i32 %70, 2
%72 = call i32 @multiply(i32* %66, i32 %68, i32* %69, i32 %71)
%73 = load i32*, i32** %15
%74 = load i32, i32* %7
%75 = sdiv i32 %74, 2
%76 = load i32*, i32** %16
%77 = load i32, i32* %9
%78 = sdiv i32 %77, 2
%79 = call i32 @multiply(i32* %73, i32 %75, i32* %76, i32 %78)
%80 = add nsw i32 %72, %79
%81 = mul nsw i32 %65, %80
store i32 %81, i32* %12
%82 = load i32*, i32** %15
%83 = load i32, i32* %7
%84 = sdiv i32 %83, 2
%85 = load i32*, i32** %17
%86 = load i32, i32* %9
%87 = sdiv i32 %86, 2
%88 = call i32 @multiply(i32* %82, i32 %84, i32* %85, i32 %87)
store i32 %88, i32* %13
%89 = load i32*, i32** %17
%90 = call i32 @free(i32* %89)
%91 = load i32*, i32** %16
%92 = call i32 @free(i32* %91)
%93 = load i32*, i32** %15
%94 = call i32 @free(i32* %93)
%95 = load i32*, i32** %14
%96 = call i32 @free(i32* %95)
%97 = load i32, i32* %11
%98 = load i32, i32* %12
%99 = add nsw i32 %97, %98
%100 = load i32, i32* %13
%101 = add nsw i32 %99, %100
store i32 %101, i32* %5
br label %102
102: ; preds = %39, %23
%103 = load i32, i32* %5
ret i32 %103
}

LLVM IR (-O2):
define i32 @multiply(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = icmp eq i32 %1, 1
%6 = icmp eq i32 %3, 1
%7 = or i1 %5, %6
br i1 %7, label %8, label %14
8: ; preds = %4
%9 = tail call i32 @arrToInt(i32* %0, i32 %1)
%10 = tail call i32 @arrToInt(i32* %2, i32 %3)
%11 = mul nsw i32 %10, %9
br label %12
12: ; preds = %8, %14
%13 = phi i32 [ %38, %14 ], [ %11, %8 ]
ret i32 %13
14: ; preds = %4
%15 = icmp sgt i32 %1, %3
%16 = select i1 %15, i32 %1, i32 %3
%17 = tail call i32* @splitIntArray(i32* %0, i32 %1, i32 0)
%18 = tail call i32* @splitIntArray(i32* %0, i32 %1, i32 1)
%19 = tail call i32* @splitIntArray(i32* %2, i32 %3, i32 0)
%20 = tail call i32* @splitIntArray(i32* %2, i32 %3, i32 1)
%21 = tail call i32 @pow(i32 10, i32 %16)
%22 = sdiv i32 %1, 2
%23 = sdiv i32 %3, 2
%24 = tail call i32 @multiply(i32* %17, i32 %22, i32* %19, i32 %23)
%25 = mul nsw i32 %24, %21
%26 = sdiv i32 %16, 2
%27 = tail call i32 @pow(i32 10, i32 %26)
%28 = tail call i32 @multiply(i32* %17, i32 %22, i32* %20, i32 %23)
%29 = tail call i32 @multiply(i32* %18, i32 %22, i32* %19, i32 %23)
%30 = add nsw i32 %29, %28
%31 = mul nsw i32 %30, %27
%32 = tail call i32 @multiply(i32* %18, i32 %22, i32* %20, i32 %23)
%33 = tail call i32 @free(i32* %20)
%34 = tail call i32 @free(i32* %19)
%35 = tail call i32 @free(i32* %18)
%36 = tail call i32 @free(i32* %17)
%37 = add i32 %32, %25
%38 = add i32 %37, %31
br label %12
}