#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
scalar_t__ atoi(char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_fac_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_get_str(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int mpz_sizeinbase(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int Problem020(void) {
  mpz_t fac;
  int sum, i, size;
  char *buf;
  char ish[2];
  ish[1] = '\0';
  mpz_init(fac);
  mpz_fac_ui(fac, 100);
  size = mpz_sizeinbase(fac, 10) + 1;
  buf = malloc(sizeof(char) * (size));
  mpz_get_str(buf, 10, fac);
  for (i = 0, sum = 0; i < size; i++) {
    ish[0] = *(buf + i);
    sum += atoi(ish);
  }
  printf("%30d", sum);
  free(buf);
  mpz_clear(fac);
  return 0;
}


x86 assembly (clang, -O0):
<Problem020>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movb   $0x0,-0x19(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x4(%rbp),%edi
mov    $0x64,%esi
call   1080 <mpz_fac_ui@plt>
mov    -0x4(%rbp),%edi
mov    $0xa,%esi
call   1070 <mpz_sizeinbase@plt>
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    $0xa,%esi
call   1060 <mpz_get_str@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1234 <Problem020+0xa4>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1a(%rbp)
lea    -0x1a(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11f6 <Problem020+0x66>
mov    -0x8(%rbp),%esi
lea    0xdc2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
call   10a0 <mpz_clear@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Problem020>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0xf(%rsp)
call   1050 <mpz_init@plt>
mov    $0x64,%esi
call   1080 <mpz_fac_ui@plt>
mov    $0xa,%esi
call   1070 <mpz_sizeinbase@plt>
mov    %eax,%ebp
lea    0x1(%rbp),%r14d
mov    %r14d,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0xa,%esi
call   1060 <mpz_get_str@plt>
test   %ebp,%ebp
js     120e <Problem020+0x7e>
mov    %r14d,%r12d
xor    %ebx,%ebx
lea    0xe(%rsp),%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
mov    %al,0xe(%rsp)
mov    %r14,%rdi
call   10b0 <atoi@plt>
add    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11f0 <Problem020+0x60>
jmp    1210 <Problem020+0x80>
xor    %ebp,%ebp
lea    0xde9(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
call   10a0 <mpz_clear@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%30d\00"
define i32 @Problem020() {
%1 = alloca [2 x i8]
%2 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 1
store i8 0, i8* %3
%4 = tail call i32 @mpz_init(i32 undef)
%5 = tail call i32 @mpz_fac_ui(i32 undef, i32 100)
%6 = tail call i32 @mpz_sizeinbase(i32 undef, i32 10)
%7 = add i32 %6, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = tail call i32 @mpz_get_str(i8* %8, i32 10, i32 undef)
%10 = icmp slt i32 %6, 0
br i1 %10, label %23, label %11
11: ; preds = %0
%12 = zext i32 %7 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %21, %13 ]
%15 = phi i32 [ 0, %11 ], [ %20, %13 ]
%16 = getelementptr inbounds i8, i8* %8, i64 %14
%17 = load i8, i8* %16
store i8 %17, i8* %2
%18 = call i64 @atoi(i8* %2)
%19 = trunc i64 %18 to i32
%20 = add i32 %15, %19
%21 = add nuw nsw i64 %14, 1
%22 = icmp eq i64 %21, %12
br i1 %22, label %23, label %13
23: ; preds = %13, %0
%24 = phi i32 [ 0, %0 ], [ %20, %13 ]
%25 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = tail call i32 @free(i8* %8)
%27 = tail call i32 @mpz_clear(i32 undef)
ret i32 0
}