#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__ mpz_cmp_ui(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
scalar_t__ mpz_mod_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_pow_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_tdiv_q(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned int);
int main() {
  unsigned int sum;
  mpz_t n, x;
  mpz_init(n);
  mpz_init_set_ui(x, 2);
  mpz_pow_ui(n, x, 1000);
  while (mpz_cmp_ui(n, 0)) {
    sum += (unsigned int)mpz_mod_ui(x, n, 10);
    mpz_init_set_ui(x, 10);
    mpz_tdiv_q(n, n, x);
  }
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x10(%rbp),%edi
mov    $0x2,%esi
call   1070 <mpz_init_set_ui@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x3e8,%edx
call   1080 <mpz_pow_ui@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1060 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
je     11ee <main+0x7e>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0xa,%edx
call   1040 <mpz_mod_ui@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%edi
mov    $0xa,%esi
call   1070 <mpz_init_set_ui@plt>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1090 <mpz_tdiv_q@plt>
jmp    11a4 <main+0x34>
mov    -0x8(%rbp),%esi
lea    0xe08(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
call   1050 <mpz_init@plt>
mov    $0x2,%esi
call   1070 <mpz_init_set_ui@plt>
mov    $0x3e8,%edx
call   1080 <mpz_pow_ui@plt>
xor    %esi,%esi
call   1060 <mpz_cmp_ui@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edx
call   1040 <mpz_mod_ui@plt>
add    %eax,%ebx
mov    $0xa,%esi
call   1070 <mpz_init_set_ui@plt>
call   1090 <mpz_tdiv_q@plt>
xor    %esi,%esi
call   1060 <mpz_cmp_ui@plt>
test   %rax,%rax
jne    11a0 <main+0x30>
lea    0xe32(%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() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* %3
%6 = call i32 @mpz_init(i32 %5)
%7 = load i32, i32* %4
%8 = call i32 @mpz_init_set_ui(i32 %7, i32 2)
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = call i32 @mpz_pow_ui(i32 %9, i32 %10, i32 1000)
br label %12
12: ; preds = %16, %0
%13 = load i32, i32* %3
%14 = call i64 @mpz_cmp_ui(i32 %13, i32 0)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %12
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = call i64 @mpz_mod_ui(i32 %17, i32 %18, i32 10)
%20 = trunc i64 %19 to i32
%21 = load i32, i32* %2
%22 = add i32 %21, %20
store i32 %22, i32* %2
%23 = load i32, i32* %4
%24 = call i32 @mpz_init_set_ui(i32 %23, i32 10)
%25 = load i32, i32* %3
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = call i32 @mpz_tdiv_q(i32 %25, i32 %26, i32 %27)
br label %12
29: ; preds = %12
%30 = load i32, i32* %2
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i32 @mpz_init(i32 undef)
%2 = tail call i32 @mpz_init_set_ui(i32 undef, i32 2)
%3 = tail call i32 @mpz_pow_ui(i32 undef, i32 undef, i32 1000)
%4 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%5 = icmp ne i64 %4, 0
br label %6
6: ; preds = %0, %6
%7 = phi i32 [ %10, %6 ], [ undef, %0 ]
%8 = tail call i64 @mpz_mod_ui(i32 undef, i32 undef, i32 10)
%9 = trunc i64 %8 to i32
%10 = add i32 %7, %9
%11 = tail call i32 @mpz_init_set_ui(i32 undef, i32 10)
%12 = tail call i32 @mpz_tdiv_q(i32 undef, i32 undef, i32 undef)
%13 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
ret i32 0
}