#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 */
int /*<<< orphan*/ free(char *);
char *mpz_get_str(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_ui_pow_ui(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
int main(int argc, char **argv) {
  char *str;
  int i, s = 0;
  mpz_t p;
  mpz_init(p);
  mpz_ui_pow_ui(p, 2, 1000);
  str = mpz_get_str(NULL, 10, p);
  for (i = 0; i < strlen(str); i++)
    s += str[i] - '0';
  free(str);
  printf("%d\n", s);
  return 0;
}


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

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
call   1060 <mpz_init@plt>
mov    $0x2,%esi
mov    $0x3e8,%edx
call   1080 <mpz_ui_pow_ui@plt>
xor    %r15d,%r15d
xor    %edi,%edi
mov    $0xa,%esi
call   1070 <mpz_get_str@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11bf <main+0x5f>
xor    %ebx,%ebx
xor    %r15d,%r15d
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%eax
add    %eax,%r15d
add    $0xffffffd0,%r15d
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11a0 <main+0x40>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe32(%rip),%rdi
mov    %r15d,%esi
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32 @mpz_ui_pow_ui(i32 undef, i32 2, i32 1000)
%5 = tail call i8* @mpz_get_str(i32* null, i32 10, i32 undef)
%6 = tail call i32 @strlen(i8* %5)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %2, %8
%9 = phi i64 [ %16, %8 ], [ 0, %2 ]
%10 = phi i32 [ %15, %8 ], [ 0, %2 ]
%11 = getelementptr inbounds i8, i8* %5, i64 %9
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = add i32 %10, -48
%15 = add i32 %14, %13
%16 = add nuw nsw i64 %9, 1
%17 = tail call i32 @strlen(i8* %5)
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %8, label %20
20: ; preds = %8, %2
%21 = phi i32 [ 0, %2 ], [ %15, %8 ]
%22 = tail call i32 @free(i8* %5)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
ret i32 0
}