#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 */

/* Variables and functions */
int pythagorean(int, int);
unsigned long long product_pythagorean_triplet(int limit) {
  for (int a = 3; a < (limit - 3) / 3; a++) {
    for (int b = a + 1; b < (limit - a - 1) / 2; b++) {
      int c = limit - a - b;
      if (c * c == pythagorean(a, b)) {
        return (unsigned long long)a * b * c;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<product_pythagorean_triplet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x3,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x3,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11e1 <product_pythagorean_triplet+0xd1>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11ce <product_pythagorean_triplet+0xbe>
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <pythagorean@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jne    11bb <product_pythagorean_triplet+0xab>
movslq -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   %rcx,%rax
movslq -0x18(%rbp),%rcx
imul   %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11e9 <product_pythagorean_triplet+0xd9>
jmp    11c0 <product_pythagorean_triplet+0xb0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <product_pythagorean_triplet+0x3c>
jmp    11d3 <product_pythagorean_triplet+0xc3>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1122 <product_pythagorean_triplet+0x12>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<product_pythagorean_triplet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
cmp    $0xf,%edi
jl     120a <product_pythagorean_triplet+0xfa>
lea    -0x3(%rdi),%eax
mov    $0xaaaaaaab,%ecx
imul   %rax,%rcx
shr    $0x21,%rcx
mov    %rcx,0x28(%rsp)
lea    -0x7(%rdi),%ecx
mov    %ecx,0xc(%rsp)
mov    $0x8,%ecx
mov    $0xc,%edx
mov    %rdx,0x18(%rsp)
mov    $0x3,%r12d
mov    $0x4,%edx
mov    %rdx,0x10(%rsp)
mov    %rdi,0x30(%rsp)
jmp    11a2 <product_pythagorean_triplet+0x92>
nopl   0x0(%rax)
mov    0x40(%rsp),%rcx
add    %rcx,0x18(%rsp)
add    $0x2,%rcx
addq   $0x1,0x10(%rsp)
mov    0x20(%rsp),%rax
add    $0xffffffff,%eax
addl   $0xfffffffe,0xc(%rsp)
mov    0x38(%rsp),%r12
cmp    0x28(%rsp),%r12d
mov    0x30(%rsp),%rdi
je     120a <product_pythagorean_triplet+0xfa>
mov    %rcx,0x40(%rsp)
mov    %rax,0x20(%rsp)
lea    0x1(%r12),%rdx
mov    %r12d,%ecx
not    %ecx
add    %edi,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
add    %ecx,%eax
sar    %eax
mov    %rdx,0x38(%rsp)
cmp    %eax,%edx
jge    1170 <product_pythagorean_triplet+0x60>
mov    %eax,%r14d
mov    0xc(%rsp),%ebp
mov    0x10(%rsp),%rbx
mov    0x18(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %ebp,%r13d
imul   %ebp,%r13d
mov    %r12d,%edi
mov    %ebx,%esi
call   1030 <pythagorean@plt>
cmp    %eax,%r13d
je     120e <product_pythagorean_triplet+0xfe>
add    %r12,%r15
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    %ebx,%r14d
jne    11e0 <product_pythagorean_triplet+0xd0>
jmp    1170 <product_pythagorean_triplet+0x60>
xor    %eax,%eax
jmp    121d <product_pythagorean_triplet+0x10d>
movslq 0x20(%rsp),%rax
sub    %rbx,%rax
imul   %rax,%r15
mov    %r15,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @product_pythagorean_triplet(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 3, i32* %4
br label %7
7: ; preds = %51, %1
%8 = load i32, i32* %4
%9 = load i32, i32* %3
%10 = sub nsw i32 %9, 3
%11 = sdiv i32 %10, 3
%12 = icmp slt i32 %8, %11
br i1 %12, label %13, label %54
13: ; preds = %7
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
br label %16
16: ; preds = %47, %13
%17 = load i32, i32* %5
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = sub nsw i32 %18, %19
%21 = sub nsw i32 %20, 1
%22 = sdiv i32 %21, 2
%23 = icmp slt i32 %17, %22
br i1 %23, label %24, label %50
24: ; preds = %16
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = sub nsw i32 %25, %26
%28 = load i32, i32* %5
%29 = sub nsw i32 %27, %28
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = load i32, i32* %6
%32 = mul nsw i32 %30, %31
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = call i32 @pythagorean(i32 %33, i32 %34)
%36 = icmp eq i32 %32, %35
br i1 %36, label %37, label %46
37: ; preds = %24
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = mul i64 %39, %41
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = mul i64 %42, %44
store i64 %45, i64* %2
br label %55
46: ; preds = %24
br label %47
47: ; preds = %46
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %16
50: ; preds = %16
br label %51
51: ; preds = %50
%52 = load i32, i32* %4
%53 = add nsw i32 %52, 1
store i32 %53, i32* %4
br label %7
54: ; preds = %7
store i64 0, i64* %2
br label %55
55: ; preds = %54, %37
%56 = load i64, i64* %2
ret i64 %56
}

LLVM IR (-O2):
define i64 @product_pythagorean_triplet(i32 %0) {
%2 = icmp sgt i32 %0, 14
br i1 %2, label %3, label %30
3: ; preds = %1
%4 = add nsw i32 %0, -3
%5 = udiv i32 %4, 3
br label %8
6: ; preds = %21, %8
%7 = icmp eq i32 %10, %5
br i1 %7, label %30, label %8
8: ; preds = %3, %6
%9 = phi i32 [ %10, %6 ], [ 3, %3 ]
%10 = add nuw nsw i32 %9, 1
%11 = sub nsw i32 %0, %9
%12 = add nsw i32 %11, -1
%13 = sdiv i32 %12, 2
%14 = icmp slt i32 %10, %13
br i1 %14, label %15, label %6
15: ; preds = %8, %21
%16 = phi i32 [ %22, %21 ], [ %10, %8 ]
%17 = sub nsw i32 %11, %16
%18 = mul nsw i32 %17, %17
%19 = tail call i32 @pythagorean(i32 %9, i32 %16)
%20 = icmp eq i32 %18, %19
br i1 %20, label %24, label %21
21: ; preds = %15
%22 = add nuw nsw i32 %16, 1
%23 = icmp eq i32 %22, %13
br i1 %23, label %6, label %15
24: ; preds = %15
%25 = zext i32 %9 to i64
%26 = zext i32 %16 to i64
%27 = mul nuw nsw i64 %26, %25
%28 = sext i32 %17 to i64
%29 = mul i64 %27, %28
br label %30
30: ; preds = %6, %1, %24
%31 = phi i64 [ %29, %24 ], [ 0, %1 ], [ 0, %6 ]
ret i64 %31
}