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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
mov    $0x3e8,%edx
call   1060 <mpz_ui_pow_ui@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa,%esi
call   1050 <mpz_get_str@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ba <main+0x7a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    118c <main+0x4c>
mov    -0x18(%rbp),%esi
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
call   1040 <mpz_init@plt>
mov    $0x2,%esi
mov    $0x3e8,%edx
call   1060 <mpz_ui_pow_ui@plt>
xor    %ebx,%ebx
xor    %edi,%edi
mov    $0xa,%esi
call   1050 <mpz_get_str@plt>
mov    (%rax),%cl
test   %cl,%cl
je     1183 <main+0x43>
add    $0x1,%rax
xor    %ebx,%ebx
nop
movsbl %cl,%ecx
add    %ecx,%ebx
add    $0xffffffd0,%ebx
movzbl (%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    1170 <main+0x30>
lea    0xe76(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
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 i32
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %6
%10 = call i32 @mpz_init(i32 %9)
%11 = load i32, i32* %6
%12 = call i32 @mpz_ui_pow_ui(i32 %11, i32 2, i32 1000)
store i32 0, i32* %7
%13 = load i32, i32* %6
%14 = call i8* @mpz_get_str(i32* null, i32 10, i32 %13)
store i8* %14, i8** %8
br label %15
15: ; preds = %26, %2
%16 = load i8*, i8** %8
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = sub nsw i32 %22, 48
%24 = load i32, i32* %7
%25 = add nsw i32 %24, %23
store i32 %25, i32* %7
br label %26
26: ; preds = %19
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %8
br label %15
29: ; preds = %15
%30 = load i32, i32* %7
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %3
ret i32 %32
}

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 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %11, %2
%9 = phi i32 [ 0, %2 ], [ %17, %11 ]
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
ret i32 0
11: ; preds = %2, %11
%12 = phi i8 [ %19, %11 ], [ %6, %2 ]
%13 = phi i8* [ %18, %11 ], [ %5, %2 ]
%14 = phi i32 [ %17, %11 ], [ 0, %2 ]
%15 = sext i8 %12 to i32
%16 = add i32 %14, -48
%17 = add i32 %16, %15
%18 = getelementptr inbounds i8, i8* %13, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %8, label %11
}