#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 *);
int /*<<< orphan*/ mpz_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
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 *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  mpz_t sum;
  mpz_init(sum);
  for (int i = 1; i <= 1000; i++) {
    mpz_t p;
    mpz_init(p);
    mpz_ui_pow_ui(p, i, i);
    mpz_add(sum, sum, p);
  }
  char *value = mpz_get_str(NULL, 10, sum);
  int len = strlen(value);
  char *start = value + (len - 10);
  printf("%s", start);
  free(value);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <mpz_init@plt>
movl   $0x1,-0x18(%rbp)
cmpl   $0x3e8,-0x18(%rbp)
jg     11d4 <main+0x64>
mov    -0x1c(%rbp),%edi
call   1060 <mpz_init@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1090 <mpz_ui_pow_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1080 <mpz_add@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1195 <main+0x25>
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa,%esi
call   1070 <mpz_get_str@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0xa,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
call   1060 <mpz_init@plt>
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
call   1060 <mpz_init@plt>
mov    %ebx,%esi
mov    %ebx,%edx
call   1090 <mpz_ui_pow_ui@plt>
call   1080 <mpz_add@plt>
add    $0x1,%ebx
cmp    $0x3e9,%ebx
jne    1180 <main+0x10>
xor    %edi,%edi
mov    $0xa,%esi
call   1070 <mpz_get_str@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rsi
add    $0xfffffffffffffff6,%rsi
lea    0xe3a(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\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 i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %6
%13 = call i32 @mpz_init(i32 %12)
store i32 1, i32* %7
br label %14
14: ; preds = %28, %2
%15 = load i32, i32* %7
%16 = icmp sle i32 %15, 1000
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i32, i32* %8
%19 = call i32 @mpz_init(i32 %18)
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = load i32, i32* %7
%23 = call i32 @mpz_ui_pow_ui(i32 %20, i32 %21, i32 %22)
%24 = load i32, i32* %6
%25 = load i32, i32* %6
%26 = load i32, i32* %8
%27 = call i32 @mpz_add(i32 %24, i32 %25, i32 %26)
br label %28
28: ; preds = %17
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %14
31: ; preds = %14
%32 = load i32, i32* %6
%33 = call i8* @mpz_get_str(i32* null, i32 10, i32 %32)
store i8* %33, i8** %9
%34 = load i8*, i8** %9
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %10
%36 = load i8*, i8** %9
%37 = load i32, i32* %10
%38 = sub nsw i32 %37, 10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8* %40, i8** %11
%41 = load i8*, i8** %11
%42 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %41)
%43 = load i8*, i8** %9
%44 = call i32 @free(i8* %43)
ret i32 0
}

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