#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 /*<<< orphan*/ add(char *, char *, char *);
int /*<<< orphan*/ reverse(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ subtract(char *, char *, char *);
void mult(const char *b1, const char *b2, char *out) {
  char r[16] = "0";
  char t[16];
  char c1[16];
  char c2[16];
  char *ptr = c2;
  strcpy(c1, b1);
  strcpy(c2, b2);
  reverse(c2);
  while (*ptr != '\0') {
    if (*ptr == '+') {
      add(r, c1, t);
      strcpy(r, t);
    }
    if (*ptr == '-') {
      subtract(r, c1, t);
      strcpy(r, t);
    }
    strcat(c1, "0");
    ptr++;
  }
  ptr = r;
  while (*ptr == '0') {
    ptr++;
  }
  strcpy(out, ptr);
}


x86 assembly (clang, -O0):
<mult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0xe95(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe92(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
lea    -0x60(%rbp),%rdi
call   1030 <reverse@plt>
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1232 <mult+0xe2>
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11e3 <mult+0x93>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1040 <add@plt>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1211 <mult+0xc1>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <subtract@plt>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <strcpy@plt>
lea    -0x50(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    11a5 <mult+0x55>
lea    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    125b <mult+0x10b>
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    123a <mult+0xea>
mov    -0x18(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   1050 <strcpy@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mult>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rsi
movaps 0xe92(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%rbx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <reverse@plt>
mov    %rsp,%r12
lea    0x30(%rsp),%r13
lea    0xe6a(%rip),%rbp
jmp    11bf <mult+0x6f>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbp,%rsi
call   1070 <strcat@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2b,%al
je     11d0 <mult+0x80>
test   %al,%al
je     120b <mult+0xbb>
cmp    $0x2d,%al
jne    11b0 <mult+0x60>
jmp    11f0 <mult+0xa0>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <add@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <strcpy@plt>
movzbl (%rbx),%eax
cmp    $0x2d,%al
jne    11b0 <mult+0x60>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1060 <subtract@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <strcpy@plt>
jmp    11b0 <mult+0x60>
lea    -0x1(%rsp),%rsi
cmpb   $0x30,0x1(%rsi)
lea    0x1(%rsi),%rsi
je     1210 <mult+0xc0>
mov    %r14,%rdi
call   1050 <strcpy@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.mult.r = [16 x i8] c"0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [2 x i8] c"0\00"
define void @mult(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [16 x i8]
%8 = alloca [16 x i8]
%9 = alloca [16 x i8]
%10 = alloca [16 x i8]
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = bitcast [16 x i8]* %7 to i8*
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
store i8* %13, i8** %11
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = call i32 @strcpy(i8* %14, i8* %15)
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%18 = load i8*, i8** %5
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%21 = call i32 @reverse(i8* %20)
br label %22
22: ; preds = %53, %3
%23 = load i8*, i8** %11
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %58
27: ; preds = %22
%28 = load i8*, i8** %11
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 43
br i1 %31, label %32, label %40
32: ; preds = %27
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%36 = call i32 @add(i8* %33, i8* %34, i8* %35)
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%39 = call i32 @strcpy(i8* %37, i8* %38)
br label %40
40: ; preds = %32, %27
%41 = load i8*, i8** %11
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 45
br i1 %44, label %45, label %53
45: ; preds = %40
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%49 = call i32 @subtract(i8* %46, i8* %47, i8* %48)
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%52 = call i32 @strcpy(i8* %50, i8* %51)
br label %53
53: ; preds = %45, %40
%54 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%55 = call i32 @strcat(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%56 = load i8*, i8** %11
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %11
br label %22
58: ; preds = %22
%59 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
store i8* %59, i8** %11
br label %60
60: ; preds = %65, %58
%61 = load i8*, i8** %11
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 48
br i1 %64, label %65, label %68
65: ; preds = %60
%66 = load i8*, i8** %11
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %11
br label %60
68: ; preds = %60
%69 = load i8*, i8** %6
%70 = load i8*, i8** %11
%71 = call i32 @strcpy(i8* %69, i8* %70)
ret void
}

LLVM IR (-O2):
@__const.mult.r = [16 x i8] c"0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [2 x i8] c"0\00"
define void @mult(i8* %0, i8* %1, i8* %2) {
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%12 = call i32 @strcpy(i8* %10, i8* %0)
%13 = call i32 @strcpy(i8* %11, i8* %1)
%14 = call i32 @reverse(i8* %11)
br label %15
15: ; preds = %28, %3
%16 = phi i8* [ %11, %3 ], [ %30, %28 ]
%17 = load i8, i8* %16
switch i8 %17, label %22 [
i8 0, label %31
i8 43, label %18
]
18: ; preds = %15
%19 = call i32 @add(i8* %8, i8* %10, i8* %9)
%20 = call i32 @strcpy(i8* %8, i8* %9)
%21 = load i8, i8* %16
br label %22
22: ; preds = %15, %18
%23 = phi i8 [ %17, %15 ], [ %21, %18 ]
%24 = icmp eq i8 %23, 45
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = call i32 @subtract(i8* %8, i8* %10, i8* %9)
%27 = call i32 @strcpy(i8* %8, i8* %9)
br label %28
28: ; preds = %25, %22
%29 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = getelementptr inbounds i8, i8* %16, i64 1
br label %15
31: ; preds = %15, %31
%32 = phi i8* [ %35, %31 ], [ %8, %15 ]
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 48
%35 = getelementptr inbounds i8, i8* %32, i64 1
br i1 %34, label %31, label %36
36: ; preds = %31
%37 = call i32 @strcpy(i8* %2, i8* %32)
ret void
}