#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int multiply(char ch, int times) {
  int num = 0;
  char *str = (char *)calloc(times + 1, sizeof(char));
  if (ch == '0') {
    times += 1;
  }
  for (int i = 0; i < times; ++i) {
    str[i] = ch;
  }
  if (ch == '0') {
    str[0] = '1';
  }
  sscanf(str, "%d", &num);
  free(str);
  return num;
}


x86 assembly (clang, -O0):
<multiply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x30,%eax
jne    1172 <multiply+0x42>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a1 <multiply+0x71>
mov    -0x1(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1179 <multiply+0x49>
movsbl -0x1(%rbp),%eax
cmp    $0x30,%eax
jne    11b5 <multiply+0x85>
mov    -0x18(%rbp),%rax
movb   $0x31,(%rax)
mov    -0x18(%rbp),%rdi
lea    0xe40(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiply>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%r14d
movl   $0x0,0x4(%rsp)
lea    0x1(%rbp),%ebx
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
cmp    $0x30,%r14b
cmove  %ebx,%ebp
test   %ebp,%ebp
jle    117f <multiply+0x3f>
mov    %ebp,%edx
movzbl %r14b,%esi
mov    %r15,%rdi
call   1040 <memset@plt>
cmp    $0x30,%r14b
jne    1189 <multiply+0x49>
movb   $0x31,(%r15)
lea    0xe70(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r15,%rdi
call   1060 <sscanf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @multiply(i8 signext %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8 %0, i8* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
%10 = call i64 @calloc(i32 %9, i32 1)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 48
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %18
18: ; preds = %15, %2
store i32 0, i32* %7
br label %19
19: ; preds = %29, %18
%20 = load i32, i32* %7
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i8, i8* %3
%25 = load i8*, i8** %6
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
br label %29
29: ; preds = %23
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %19
32: ; preds = %19
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 48
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 0
store i8 49, i8* %38
br label %39
39: ; preds = %36, %32
%40 = load i8*, i8** %6
%41 = call i32 @sscanf(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%42 = load i8*, i8** %6
%43 = call i32 @free(i8* %42)
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @multiply(i8 signext %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = add nsw i32 %1, 1
%6 = tail call i64 @calloc(i32 %5, i32 1)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i8 %0, 48
%9 = select i1 %8, i32 %5, i32 %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = zext i32 %9 to i64
br label %13
13: ; preds = %11, %2
br i1 %8, label %14, label %15
14: ; preds = %13
store i8 49, i8* %7
br label %15
15: ; preds = %14, %13
%16 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%17 = call i32 @free(i8* %7)
%18 = load i32, i32* %3
ret i32 %18
}