#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*/ factorial(int, char **);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main() {
  int maxa = 100;
  char *b = (char *)calloc(2, sizeof(char));
  strcpy(b, "1");
  factorial(maxa, &b);
  int sum = 0;
  int i;
  for (i = 0; i < strlen(b); ++i)
    sum += *(b + i) - '0';
  printf("%d\n", sum);
  free(b);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <factorial@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11f2 <main+0x92>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x30,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b3 <main+0x53>
mov    -0x14(%rbp),%esi
lea    0xe06(%rip),%rdi
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x2,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,(%rsp)
lea    0xe82(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %rsp,%rsi
mov    $0x64,%edi
call   1050 <factorial@plt>
mov    (%rsp),%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    11d1 <main+0x71>
xor    %ebx,%ebx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%rdi
movsbl (%rdi,%rbx,1),%eax
add    %eax,%r14d
add    $0xffffffd0,%r14d
add    $0x1,%rbx
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11b0 <main+0x50>
jmp    11d4 <main+0x74>
xor    %r14d,%r14d
lea    0xe27(%rip),%rdi
mov    %r14d,%esi
call   1070 <printf@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"1\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 100, i32* %2
%6 = call i64 @calloc(i32 2, i32 1)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %2
%11 = call i32 @factorial(i32 %10, i8** %3)
store i32 0, i32* %4
store i32 0, i32* %5
br label %12
12: ; preds = %27, %0
%13 = load i32, i32* %5
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %30
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = sub nsw i32 %23, 48
%25 = load i32, i32* %4
%26 = add nsw i32 %25, %24
store i32 %26, i32* %4
br label %27
27: ; preds = %17
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %12
30: ; preds = %12
%31 = load i32, i32* %4
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i8*, i8** %3
%34 = call i32 @free(i8* %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i64 @calloc(i32 2, i32 1)
%4 = inttoptr i64 %3 to i8*
store i8* %4, i8** %1
%5 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @factorial(i32 100, i8** %1)
%7 = load i8*, i8** %1
%8 = call i32 @strlen(i8* %7)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %0, %10
%11 = phi i64 [ %19, %10 ], [ 0, %0 ]
%12 = phi i32 [ %18, %10 ], [ 0, %0 ]
%13 = load i8*, i8** %1
%14 = getelementptr inbounds i8, i8* %13, i64 %11
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = add i32 %12, -48
%18 = add i32 %17, %16
%19 = add nuw nsw i64 %11, 1
%20 = call i32 @strlen(i8* %13)
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %10, label %23
23: ; preds = %10, %0
%24 = phi i32 [ 0, %0 ], [ %18, %10 ]
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i8*, i8** %1
%27 = call i32 @free(i8* %26)
ret i32 0
}