#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 gmp_asprintf(char **, char *, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_ui_pow_ui(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  int i;
  char *s = NULL;
  mpz_t n, temp;
  mpz_init(n);
  mpz_init(temp);
  for (i = 1; i <= 1000; i++) {
    mpz_ui_pow_ui(temp, i, i);
    mpz_add(n, n, temp);
  }
  i = gmp_asprintf(&s, "%Zd", n);
  printf("%s\n", s + i - 10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x18(%rbp),%edi
call   1040 <mpz_init@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jg     11b5 <main+0x65>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1070 <mpz_ui_pow_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <mpz_add@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117e <main+0x2e>
mov    -0x14(%rbp),%edx
lea    -0x10(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1060 <gmp_asprintf@plt>
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rsi
movslq -0x8(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffff6,%rsi
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
call   1040 <mpz_init@plt>
call   1040 <mpz_init@plt>
mov    $0x1,%ebx
nopl   (%rax)
mov    %ebx,%esi
mov    %ebx,%edx
call   1070 <mpz_ui_pow_ui@plt>
call   1050 <mpz_add@plt>
add    $0x1,%ebx
cmp    $0x3e9,%ebx
jne    1170 <main+0x20>
lea    0xe70(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1060 <gmp_asprintf@plt>
mov    0x8(%rsp),%rcx
cltq
lea    (%rcx,%rax,1),%rsi
add    $0xfffffffffffffff6,%rsi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%Zd\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32 @mpz_init(i32 undef)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 1, %0 ], [ %9, %5 ]
%7 = tail call i32 @mpz_ui_pow_ui(i32 undef, i32 %6, i32 %6)
%8 = tail call i32 @mpz_add(i32 undef, i32 undef, i32 undef)
%9 = add nuw nsw i32 %6, 1
%10 = icmp eq i32 %9, 1001
br i1 %10, label %11, label %5
11: ; preds = %5
%12 = call i32 @gmp_asprintf(i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 undef)
%13 = load i8*, i8** %1
%14 = sext i32 %12 to i64
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -10
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %16)
ret i32 0
}