#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 *);
char *malloc(size_t);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_get_str(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int mpz_sizeinbase(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_ui_pow_ui(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, unsigned int);
int Problem016() {
  unsigned int i, sum;
  size_t size;
  char *buf;
  char ish[2];
  mpz_t a;
  mpz_init(a);
  ish[1] = '\0';
  mpz_ui_pow_ui(a, 2, 1000);
  size = mpz_sizeinbase(a, 10) + 1;
  buf = malloc(size);
  mpz_get_str(buf, 10, a);
  for (i = 0, sum = 0; i < size; i++) {
    ish[0] = buf[i];
    sum += atoi(ish);
  }
  printf("%30d", sum);
  mpz_clear(a);
  return 0;
}


x86 assembly (clang, -O0):
<Problem016>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    -0x20(%rbp),%edi
call   1040 <mpz_init@plt>
movb   $0x0,-0x19(%rbp)
mov    -0x20(%rbp),%edi
mov    $0x2,%esi
mov    $0x3e8,%edx
call   10a0 <mpz_ui_pow_ui@plt>
mov    -0x20(%rbp),%edi
mov    $0xa,%esi
call   1060 <mpz_sizeinbase@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    $0xa,%esi
call   1050 <mpz_get_str@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    1225 <Problem016+0xa5>
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1a(%rbp)
lea    -0x1a(%rbp),%rdi
call   1090 <atoi@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <Problem016+0x68>
mov    -0x8(%rbp),%esi
lea    0xdd1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%edi
call   1080 <mpz_clear@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Problem016>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
call   1040 <mpz_init@plt>
movb   $0x0,0xf(%rsp)
mov    $0x2,%esi
mov    $0x3e8,%edx
call   10a0 <mpz_ui_pow_ui@plt>
mov    $0xa,%esi
call   1060 <mpz_sizeinbase@plt>
mov    %eax,%r15d
lea    0x1(%r15),%eax
movslq %eax,%r14
mov    %r14,%rdi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0xa,%esi
call   1050 <mpz_get_str@plt>
xor    %ebp,%ebp
inc    %r15d
je     120b <Problem016+0x8b>
xor    %ebx,%ebx
lea    0xe(%rsp),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%eax
mov    %al,0xe(%rsp)
mov    %r15,%rdi
call   1090 <atoi@plt>
add    %eax,%ebp
add    $0x1,%ebx
cmp    %r14,%rbx
jb     11f0 <Problem016+0x70>
lea    0xdee(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
call   1080 <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 @Problem016() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i8*
%5 = alloca [2 x i8]
%6 = alloca i32
%7 = load i32, i32* %6
%8 = call i32 @mpz_init(i32 %7)
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 0, i8* %9
%10 = load i32, i32* %6
%11 = call i32 @mpz_ui_pow_ui(i32 %10, i32 2, i32 1000)
%12 = load i32, i32* %6
%13 = call i32 @mpz_sizeinbase(i32 %12, i32 10)
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
store i64 %15, i64* %3
%16 = load i64, i64* %3
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = load i32, i32* %6
%20 = call i32 @mpz_get_str(i8* %18, i32 10, i32 %19)
store i32 0, i32* %1
store i32 0, i32* %2
br label %21
21: ; preds = %39, %0
%22 = load i32, i32* %1
%23 = zext i32 %22 to i64
%24 = load i64, i64* %3
%25 = icmp ult i64 %23, %24
br i1 %25, label %26, label %42
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = load i32, i32* %1
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
store i8 %31, i8* %32
%33 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%34 = call i64 @atoi(i8* %33)
%35 = load i32, i32* %2
%36 = zext i32 %35 to i64
%37 = add nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %2
br label %39
39: ; preds = %26
%40 = load i32, i32* %1
%41 = add i32 %40, 1
store i32 %41, i32* %1
br label %21
42: ; preds = %21
%43 = load i32, i32* %2
%44 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %6
%46 = call i32 @mpz_clear(i32 %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%30d\00"
define i32 @Problem016() {
%1 = alloca [2 x i8]
%2 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @mpz_init(i32 undef)
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 1
store i8 0, i8* %4
%5 = tail call i32 @mpz_ui_pow_ui(i32 undef, i32 2, i32 1000)
%6 = tail call i32 @mpz_sizeinbase(i32 undef, i32 10)
%7 = add nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = tail call i8* @malloc(i64 %8)
%10 = tail call i32 @mpz_get_str(i8* %9, i32 10, i32 undef)
%11 = icmp eq i32 %7, 0
br i1 %11, label %23, label %12
12: ; preds = %0, %12
%13 = phi i64 [ %21, %12 ], [ 0, %0 ]
%14 = phi i32 [ %19, %12 ], [ 0, %0 ]
%15 = getelementptr inbounds i8, i8* %9, i64 %13
%16 = load i8, i8* %15
store i8 %16, i8* %2
%17 = call i64 @atoi(i8* %2)
%18 = trunc i64 %17 to i32
%19 = add i32 %14, %18
%20 = add nuw nsw i64 %13, 1
%21 = and i64 %20, 4294967295
%22 = icmp ult i64 %21, %8
br i1 %22, label %12, label %23
23: ; preds = %12, %0
%24 = phi i32 [ 0, %0 ], [ %19, %12 ]
%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 @mpz_clear(i32 undef)
ret i32 0
}