#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*/);
scalar_t__ mpz_get_ui(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul_2exp(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_tdiv_qr_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                                  int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  mpz_t a, r;
  mpz_init(a);
  mpz_init(r);
  int digsum = 0;
  mpz_set_ui(a, 1);
  mpz_mul_2exp(a, a, 1000);
  while (mpz_cmp_ui(a, 0)) {
    mpz_tdiv_qr_ui(a, r, a, 10);
    digsum += mpz_get_ui(r);
  }
  printf("%d\n", digsum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0xc(%rbp),%edi
call   1040 <mpz_init@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1090 <mpz_set_ui@plt>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x3e8,%edx
call   1050 <mpz_mul_2exp@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1080 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
je     11f4 <main+0x84>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    $0xa,%ecx
call   1060 <mpz_tdiv_qr_ui@plt>
mov    -0xc(%rbp),%edi
call   1070 <mpz_get_ui@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
jmp    11b3 <main+0x43>
mov    -0x10(%rbp),%esi
lea    0xe02(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
call   1040 <mpz_init@plt>
call   1040 <mpz_init@plt>
mov    $0x1,%esi
call   1090 <mpz_set_ui@plt>
mov    $0x3e8,%edx
call   1050 <mpz_mul_2exp@plt>
xor    %ebx,%ebx
xor    %esi,%esi
call   1080 <mpz_cmp_ui@plt>
test   %rax,%rax
je     11bd <main+0x4d>
xor    %ebx,%ebx
nop
mov    $0xa,%ecx
call   1060 <mpz_tdiv_qr_ui@plt>
call   1070 <mpz_get_ui@plt>
add    %eax,%ebx
xor    %esi,%esi
call   1080 <mpz_cmp_ui@plt>
test   %rax,%rax
jne    11a0 <main+0x30>
lea    0xe3c(%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* %2
%6 = call i32 @mpz_init(i32 %5)
%7 = load i32, i32* %3
%8 = call i32 @mpz_init(i32 %7)
store i32 0, i32* %4
%9 = load i32, i32* %2
%10 = call i32 @mpz_set_ui(i32 %9, i32 1)
%11 = load i32, i32* %2
%12 = load i32, i32* %2
%13 = call i32 @mpz_mul_2exp(i32 %11, i32 %12, i32 1000)
br label %14
14: ; preds = %18, %0
%15 = load i32, i32* %2
%16 = call i64 @mpz_cmp_ui(i32 %15, i32 0)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = load i32, i32* %2
%22 = call i32 @mpz_tdiv_qr_ui(i32 %19, i32 %20, i32 %21, i32 10)
%23 = load i32, i32* %3
%24 = call i64 @mpz_get_ui(i32 %23)
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = add nsw i64 %26, %24
%28 = trunc i64 %27 to i32
store i32 %28, i32* %4
br label %14
29: ; preds = %14
%30 = load i32, i32* %4
%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(i32 undef)
%3 = tail call i32 @mpz_set_ui(i32 undef, i32 1)
%4 = tail call i32 @mpz_mul_2exp(i32 undef, i32 undef, i32 1000)
%5 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %12, %7 ], [ 0, %0 ]
%9 = tail call i32 @mpz_tdiv_qr_ui(i32 undef, i32 undef, i32 undef, i32 10)
%10 = tail call i64 @mpz_get_ui(i32 undef)
%11 = trunc i64 %10 to i32
%12 = add i32 %8, %11
%13 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %7
15: ; preds = %7, %0
%16 = phi i32 [ 0, %0 ], [ %12, %7 ]
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
ret i32 0
}