#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_digit_strings(char *, char *, char **);
int /*<<< orphan*/ assert(int);
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int mul_digit_string(int, char *, char **);
char *realloc(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int mul_int_string(int alpha, const char *in_string, char **out_string_ptr) {
  int in_length = strlen(in_string);
  char *in_copy = calloc(in_length + 1, sizeof(char));
  strncpy(in_copy, in_string, in_length);
  strncpy(*out_string_ptr, "0", 2);
  do {
    int modulo = alpha % 10;
    int in_copy_len = strlen(in_copy);
    if (modulo) {
      if (modulo == 1) {
        char *out_current =
            (char *)calloc(strlen(*out_string_ptr) + 1, sizeof(char));
        strncpy(out_current, *out_string_ptr, strlen(*out_string_ptr) + 1);
        add_digit_strings(out_current, in_copy, out_string_ptr);
        free(out_current);
      } else {
        char *row = (char *)calloc(in_copy_len + 2, sizeof(char));
        int mds_ret = mul_digit_string(modulo, in_copy, &row);
        assert(mds_ret == 0);
        char *out_current =
            (char *)calloc(strlen(*out_string_ptr) + 1, sizeof(char));
        strncpy(out_current, *out_string_ptr, strlen(*out_string_ptr) + 1);
        add_digit_strings(out_current, row, out_string_ptr);
        free(out_current);
        free(row);
      }
    }
    in_copy = realloc(in_copy, strlen(in_copy) + 2);
    strcat(in_copy, "0");
  } while ((alpha = alpha / 10));
  free(in_copy);
  return 0;
}


x86 assembly (clang, -O0):
<mul_int_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe1c(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncpy@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     133b <mul_int_string+0x1ab>
cmpl   $0x1,-0x2c(%rbp)
jne    128b <mul_int_string+0xfb>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <strncpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   10b0 <add_digit_strings@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    1336 <mul_int_string+0x1a6>
mov    -0x30(%rbp),%edi
add    $0x2,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <mul_digit_string@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <strncpy@plt>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   10b0 <add_digit_strings@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    133b <mul_int_string+0x1ab>
mov    -0x28(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
add    $0x2,%esi
call   1090 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xc97(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jne    11ee <mul_int_string+0x5e>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mul_int_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %edi,%r15d
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0x1(%rbp),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
mov    %rbx,0x10(%rsp)
mov    (%rbx),%rdi
lea    0xe23(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncpy@plt>
jmp    12ab <mul_int_string+0x11b>
nopl   0x0(%rax)
add    $0x2,%eax
mov    %eax,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,0x8(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
lea    0x8(%rsp),%rdx
call   1060 <mul_digit_string@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
mov    0x10(%rsp),%rbx
mov    (%rbx),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r13
mov    (%rbx),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r13,%rdi
mov    %rbp,%rsi
call   1040 <strncpy@plt>
mov    0x8(%rsp),%rsi
mov    %r13,%rdi
mov    %rbx,%rdx
call   10b0 <add_digit_strings@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%esi
mov    %r14,%rdi
call   1090 <realloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
lea    0xd68(%rip),%rsi
call   10a0 <strcat@plt>
add    $0x9,%r12d
cmp    $0x12,%r12d
jbe    132e <mul_int_string+0x19e>
mov    %r15d,%r12d
movslq %r15d,%rbp
imul   $0x66666667,%rbp,%r15
mov    %r15,%rax
shr    $0x3f,%rax
sar    $0x22,%r15
add    %eax,%r15d
lea    (%r15,%r15,1),%eax
lea    (%rax,%rax,4),%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
sub    %ebx,%ebp
je     1278 <mul_int_string+0xe8>
cmp    $0x1,%ebp
jne    11f0 <mul_int_string+0x60>
mov    0x10(%rsp),%rbx
mov    (%rbx),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbp
mov    (%rbx),%r13
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbp,%rdi
mov    %r13,%rsi
call   1040 <strncpy@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10b0 <add_digit_strings@plt>
mov    %rbp,%rdi
jmp    1273 <mul_int_string+0xe3>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
define i32 @mul_int_string(i32 %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, 1
%7 = tail call i8* @calloc(i32 %6, i32 1)
%8 = tail call i32 @strncpy(i8* %7, i8* %1, i32 %5)
%9 = load i8*, i8** %2
%10 = tail call i32 @strncpy(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 2)
%11 = bitcast i8** %4 to i8*
br label %12
12: ; preds = %49, %3
%13 = phi i8* [ %7, %3 ], [ %52, %49 ]
%14 = phi i32 [ %0, %3 ], [ %16, %49 ]
%15 = srem i32 %14, 10
%16 = sdiv i32 %14, 10
%17 = call i32 @strlen(i8* %13)
switch i32 %15, label %29 [
i32 0, label %49
i32 1, label %18
]
18: ; preds = %12
%19 = load i8*, i8** %2
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, 1
%22 = call i8* @calloc(i32 %21, i32 1)
%23 = load i8*, i8** %2
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %24, 1
%26 = call i32 @strncpy(i8* %22, i8* %23, i32 %25)
%27 = call i32 @add_digit_strings(i8* %22, i8* %13, i8** %2)
%28 = call i32 @free(i8* %22)
br label %49
29: ; preds = %12
%30 = add nsw i32 %17, 2
%31 = call i8* @calloc(i32 %30, i32 1)
store i8* %31, i8** %4
%32 = call i32 @mul_digit_string(i32 %15, i8* %13, i8** %4)
%33 = icmp eq i32 %32, 0
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i8*, i8** %2
%37 = call i32 @strlen(i8* %36)
%38 = add nsw i32 %37, 1
%39 = call i8* @calloc(i32 %38, i32 1)
%40 = load i8*, i8** %2
%41 = call i32 @strlen(i8* %40)
%42 = add nsw i32 %41, 1
%43 = call i32 @strncpy(i8* %39, i8* %40, i32 %42)
%44 = load i8*, i8** %4
%45 = call i32 @add_digit_strings(i8* %39, i8* %44, i8** %2)
%46 = call i32 @free(i8* %39)
%47 = load i8*, i8** %4
%48 = call i32 @free(i8* %47)
br label %49
49: ; preds = %12, %18, %29
%50 = call i32 @strlen(i8* %13)
%51 = add nsw i32 %50, 2
%52 = call i8* @realloc(i8* %13, i32 %51)
%53 = call i32 @strcat(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%54 = add i32 %14, 9
%55 = icmp ult i32 %54, 19
br i1 %55, label %56, label %12
56: ; preds = %49
%57 = call i32 @free(i8* %52)
ret i32 0
}