#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*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              int const);
scalar_t__ mpz_cdiv_q_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_inits(int /*<<< orphan*/, int /*<<< orphan*/,
                             int /*<<< orphan*/, int /*<<< orphan*/,
                             int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
scalar_t__ mpz_perfect_square_p(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_sub_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              int const);
int /*<<< orphan*/ printf(char *, unsigned long long);
int main(int argc, char **argv) {
  mpz_t s, sa, sb, sc;
  mpz_inits(s, sa, sb, sc, 0);
  const long max = 1000000000;
  unsigned long long sum = 0;
  for (int a = 2; a < max / 3; ++a) {
    for (int j = -1; j <= 1; j += 2) {
      const int b = a;
      const int c = a + j;
      mpz_set_ui(s, 0);
      mpz_add_ui(s, s, a);
      mpz_add_ui(s, s, b);
      mpz_add_ui(s, s, c);
      if (mpz_cdiv_q_ui(s, s, 2) == 0) {
        mpz_set(sa, s);
        mpz_sub_ui(sa, sa, a);
        mpz_set(sb, s);
        mpz_sub_ui(sb, sb, b);
        mpz_set(sc, s);
        mpz_sub_ui(sc, sc, c);
        mpz_mul(s, s, sa);
        mpz_mul(s, s, sb);
        mpz_mul(s, s, sc);
        if (mpz_perfect_square_p(s)) {
          sum += a + b + c;
        }
      }
    }
  }
  printf("%llu\n", sum);
  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
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
xor    %r8d,%r8d
call   1080 <mpz_inits@plt>
movq   $0x3b9aca00,-0x28(%rbp)
3b
movq   $0x0,-0x30(%rbp)
movl   $0x2,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    $0x13de4355,%rax
jge    1314 <main+0x184>
movl   $0xffffffff,-0x38(%rbp)
cmpl   $0x1,-0x38(%rbp)
jg     1301 <main+0x171>
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   10b0 <mpz_set_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1050 <mpz_add_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x3c(%rbp),%edx
call   1050 <mpz_add_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x40(%rbp),%edx
call   1050 <mpz_add_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x2,%edx
call   10a0 <mpz_cdiv_q_ui@plt>
cmp    $0x0,%rax
jne    12ee <main+0x15e>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1090 <mpz_sub_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x3c(%rbp),%edx
call   1090 <mpz_sub_ui@plt>
mov    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x20(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x40(%rbp),%edx
call   1090 <mpz_sub_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1070 <mpz_mul@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <mpz_mul@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1070 <mpz_mul@plt>
mov    -0x14(%rbp),%edi
call   1030 <mpz_perfect_square_p@plt>
cmp    $0x0,%rax
je     12e9 <main+0x159>
mov    -0x34(%rbp),%eax
add    -0x3c(%rbp),%eax
add    -0x40(%rbp),%eax
cltq
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    12ee <main+0x15e>
jmp    12f3 <main+0x163>
mov    -0x38(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x38(%rbp)
jmp    11e8 <main+0x58>
jmp    1306 <main+0x176>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d1 <main+0x41>
mov    -0x30(%rbp),%rsi
lea    0xce1(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %r8d,%r8d
call   1080 <mpz_inits@plt>
mov    $0x1,%ebp
mov    $0x7,%r15d
jmp    11c1 <main+0x31>
nop
add    $0x3,%r15
cmp    $0x3b9aca00,%r15
je     12b0 <main+0x120>
mov    %ebp,%ebx
xor    %esi,%esi
call   10b0 <mpz_set_ui@plt>
lea    0x1(%rbx),%ebp
mov    %ebp,%edx
call   1050 <mpz_add_ui@plt>
mov    %ebp,%edx
call   1050 <mpz_add_ui@plt>
mov    %ebx,%edx
call   1050 <mpz_add_ui@plt>
mov    $0x2,%edx
call   10a0 <mpz_cdiv_q_ui@plt>
test   %rax,%rax
jne    1235 <main+0xa5>
call   1040 <mpz_set@plt>
mov    %ebp,%edx
call   1090 <mpz_sub_ui@plt>
call   1040 <mpz_set@plt>
mov    %ebp,%edx
call   1090 <mpz_sub_ui@plt>
call   1040 <mpz_set@plt>
mov    %ebx,%edx
call   1090 <mpz_sub_ui@plt>
call   1070 <mpz_mul@plt>
call   1070 <mpz_mul@plt>
call   1070 <mpz_mul@plt>
call   1030 <mpz_perfect_square_p@plt>
test   %rax,%rax
je     1235 <main+0xa5>
add    %r15,%r14
add    $0xfffffffffffffffe,%r14
xor    %esi,%esi
call   10b0 <mpz_set_ui@plt>
mov    %ebp,%edx
call   1050 <mpz_add_ui@plt>
mov    %ebp,%edx
call   1050 <mpz_add_ui@plt>
add    $0x2,%ebx
mov    %ebx,%edx
call   1050 <mpz_add_ui@plt>
mov    $0x2,%edx
call   10a0 <mpz_cdiv_q_ui@plt>
test   %rax,%rax
jne    11b0 <main+0x20>
call   1040 <mpz_set@plt>
mov    %ebp,%edx
call   1090 <mpz_sub_ui@plt>
call   1040 <mpz_set@plt>
mov    %ebp,%edx
call   1090 <mpz_sub_ui@plt>
call   1040 <mpz_set@plt>
mov    %ebx,%edx
call   1090 <mpz_sub_ui@plt>
call   1070 <mpz_mul@plt>
call   1070 <mpz_mul@plt>
call   1070 <mpz_mul@plt>
call   1030 <mpz_perfect_square_p@plt>
test   %rax,%rax
je     11b0 <main+0x20>
add    %r15,%r14
jmp    11b0 <main+0x20>
lea    0xd49(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%llu\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 i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = load i32, i32* %9
%20 = call i32 @mpz_inits(i32 %16, i32 %17, i32 %18, i32 %19, i32 0)
store i64 1000000000, i64* %10
store i64 0, i64* %11
store i32 2, i32* %12
br label %21
21: ; preds = %104, %2
%22 = load i32, i32* %12
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %23, 333333333
br i1 %24, label %25, label %107
25: ; preds = %21
store i32 -1, i32* %13
br label %26
26: ; preds = %100, %25
%27 = load i32, i32* %13
%28 = icmp sle i32 %27, 1
br i1 %28, label %29, label %103
29: ; preds = %26
%30 = load i32, i32* %12
store i32 %30, i32* %14
%31 = load i32, i32* %12
%32 = load i32, i32* %13
%33 = add nsw i32 %31, %32
store i32 %33, i32* %15
%34 = load i32, i32* %6
%35 = call i32 @mpz_set_ui(i32 %34, i32 0)
%36 = load i32, i32* %6
%37 = load i32, i32* %6
%38 = load i32, i32* %12
%39 = call i32 @mpz_add_ui(i32 %36, i32 %37, i32 %38)
%40 = load i32, i32* %6
%41 = load i32, i32* %6
%42 = load i32, i32* %14
%43 = call i32 @mpz_add_ui(i32 %40, i32 %41, i32 %42)
%44 = load i32, i32* %6
%45 = load i32, i32* %6
%46 = load i32, i32* %15
%47 = call i32 @mpz_add_ui(i32 %44, i32 %45, i32 %46)
%48 = load i32, i32* %6
%49 = load i32, i32* %6
%50 = call i64 @mpz_cdiv_q_ui(i32 %48, i32 %49, i32 2)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %99
52: ; preds = %29
%53 = load i32, i32* %7
%54 = load i32, i32* %6
%55 = call i32 @mpz_set(i32 %53, i32 %54)
%56 = load i32, i32* %7
%57 = load i32, i32* %7
%58 = load i32, i32* %12
%59 = call i32 @mpz_sub_ui(i32 %56, i32 %57, i32 %58)
%60 = load i32, i32* %8
%61 = load i32, i32* %6
%62 = call i32 @mpz_set(i32 %60, i32 %61)
%63 = load i32, i32* %8
%64 = load i32, i32* %8
%65 = load i32, i32* %14
%66 = call i32 @mpz_sub_ui(i32 %63, i32 %64, i32 %65)
%67 = load i32, i32* %9
%68 = load i32, i32* %6
%69 = call i32 @mpz_set(i32 %67, i32 %68)
%70 = load i32, i32* %9
%71 = load i32, i32* %9
%72 = load i32, i32* %15
%73 = call i32 @mpz_sub_ui(i32 %70, i32 %71, i32 %72)
%74 = load i32, i32* %6
%75 = load i32, i32* %6
%76 = load i32, i32* %7
%77 = call i32 @mpz_mul(i32 %74, i32 %75, i32 %76)
%78 = load i32, i32* %6
%79 = load i32, i32* %6
%80 = load i32, i32* %8
%81 = call i32 @mpz_mul(i32 %78, i32 %79, i32 %80)
%82 = load i32, i32* %6
%83 = load i32, i32* %6
%84 = load i32, i32* %9
%85 = call i32 @mpz_mul(i32 %82, i32 %83, i32 %84)
%86 = load i32, i32* %6
%87 = call i64 @mpz_perfect_square_p(i32 %86)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %98
89: ; preds = %52
%90 = load i32, i32* %12
%91 = load i32, i32* %14
%92 = add nsw i32 %90, %91
%93 = load i32, i32* %15
%94 = add nsw i32 %92, %93
%95 = sext i32 %94 to i64
%96 = load i64, i64* %11
%97 = add i64 %96, %95
store i64 %97, i64* %11
br label %98
98: ; preds = %89, %52
br label %99
99: ; preds = %98, %29
br label %100
100: ; preds = %99
%101 = load i32, i32* %13
%102 = add nsw i32 %101, 2
store i32 %102, i32* %13
br label %26
103: ; preds = %26
br label %104
104: ; preds = %103
%105 = load i32, i32* %12
%106 = add nsw i32 %105, 1
store i32 %106, i32* %12
br label %21
107: ; preds = %21
%108 = load i64, i64* %11
%109 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %108)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%llu\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @mpz_inits(i32 undef, i32 undef, i32 undef, i32 undef, i32 0)
br label %4
4: ; preds = %2, %59
%5 = phi i64 [ 2, %2 ], [ %36, %59 ]
%6 = phi i64 [ 0, %2 ], [ %60, %59 ]
%7 = shl nuw nsw i64 %5, 1
%8 = add nsw i64 %5, -1
%9 = tail call i32 @mpz_set_ui(i32 undef, i32 0)
%10 = trunc i64 %5 to i32
%11 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 %10)
%12 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 %10)
%13 = trunc i64 %8 to i32
%14 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 %13)
%15 = tail call i64 @mpz_cdiv_q_ui(i32 undef, i32 undef, i32 2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %34
17: ; preds = %59
%18 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %60)
ret i32 0
19: ; preds = %4
%20 = tail call i32 @mpz_set(i32 undef, i32 undef)
%21 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 %10)
%22 = tail call i32 @mpz_set(i32 undef, i32 undef)
%23 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 %10)
%24 = tail call i32 @mpz_set(i32 undef, i32 undef)
%25 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 %13)
%26 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%27 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%28 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%29 = tail call i64 @mpz_perfect_square_p(i32 undef)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %19
%32 = add nuw nsw i64 %8, %7
%33 = add i64 %6, %32
br label %34
34: ; preds = %19, %31, %4
%35 = phi i64 [ %33, %31 ], [ %6, %19 ], [ %6, %4 ]
%36 = add nuw nsw i64 %5, 1
%37 = tail call i32 @mpz_set_ui(i32 undef, i32 0)
%38 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 %10)
%39 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 %10)
%40 = trunc i64 %36 to i32
%41 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 %40)
%42 = tail call i64 @mpz_cdiv_q_ui(i32 undef, i32 undef, i32 2)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %59
44: ; preds = %34
%45 = tail call i32 @mpz_set(i32 undef, i32 undef)
%46 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 %10)
%47 = tail call i32 @mpz_set(i32 undef, i32 undef)
%48 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 %10)
%49 = tail call i32 @mpz_set(i32 undef, i32 undef)
%50 = tail call i32 @mpz_sub_ui(i32 undef, i32 undef, i32 %40)
%51 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%52 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%53 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%54 = tail call i64 @mpz_perfect_square_p(i32 undef)
%55 = icmp eq i64 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %44
%57 = add nuw nsw i64 %36, %7
%58 = add i64 %35, %57
br label %59
59: ; preds = %56, %44, %34
%60 = phi i64 [ %58, %56 ], [ %35, %44 ], [ %35, %34 ]
%61 = icmp eq i64 %36, 333333333
br i1 %61, label %17, label %4
}