#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 /*<<< orphan*/ printf(char *, int, int, int, ...);
double sqrt(int);
void p009() {
  int target = 1000;
  int a = 1;
  int b = 1;
  int c, t1;
  double t2;
  do {
    t1 = a * a + b * b;
    t2 = sqrt(t1);
    if (t2 > target) {
      a++;
      b = a;
      continue;
    }
    c = (int)t2;
    if (t2 != c) {
      b++;
      continue;
    }
    if (a + b + c == target) {
      break;
    }
    b++;
  } while (1);
  printf(
      "The pythagorean triplet %d^2 + %d^2 = %d^2 satisfies the equation:\n\n",
      a, b, c);
  printf("  %d + %d + %d = %d\n\n", a, b, c, target);
  printf("The resulting product is %d * %d * %d = %d", a, b, c, a * b * c);
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x3e8,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1185 <p009+0x65>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11da <p009+0xba>
cvttsd2si -0x20(%rbp),%eax
mov    %eax,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jne    11ac <p009+0x8c>
jp     11ac <p009+0x8c>
jmp    11ba <p009+0x9a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11da <p009+0xba>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11d1 <p009+0xb1>
jmp    11e9 <p009+0xc9>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    113d <p009+0x1d>
jmp    11e9 <p009+0xc9>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x4(%rbp),%r8d
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%r8d
imul   -0xc(%rbp),%r8d
imul   -0x10(%rbp),%r8d
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x3,0xc(%rsp)
mov    $0x1,%r15d
movl   $0x3e6,0x10(%rsp)
mov    $0x1,%r14d
jmp    116c <p009+0x4c>
nopl   0x0(%rax)
add    $0x1,%r14d
mov    0xc(%rsp),%eax
mov    0x14(%rsp),%r15d
add    %eax,%r15d
add    $0x2,%eax
mov    %eax,0xc(%rsp)
addl   $0xfffffffe,0x10(%rsp)
mov    %r14d,%r13d
imul   %r14d,%r13d
xor    %r12d,%r12d
mov    %r15d,0x14(%rsp)
jmp    1187 <p009+0x67>
nopl   (%rax)
add    %r14d,%r15d
add    $0x1,%r12d
lea    (%r14,%r12,1),%ebx
mov    %ebx,%edi
imul   %ebx,%edi
add    %r13d,%edi
call   1040 <sqrt@plt>
ucomisd 0xe60(%rip),%xmm0
ja     1150 <p009+0x30>
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1180 <p009+0x60>
jp     1180 <p009+0x60>
cvttsd2si %xmm0,%ebp
mov    0x10(%rsp),%eax
sub    %ebp,%eax
cmp    %r12d,%eax
jne    1180 <p009+0x60>
lea    0xe40(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe70(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    $0x3e8,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
imul   %ebp,%r15d
lea    0xe67(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [69 x i8] c"The pythagorean triplet %d^2 + %d^2 = %d^2 satisfies the equation:\0A\0A\00"
@.str.1 = [22 x i8] c" %d + %d + %d = %d\0A\0A\00"
@.str.2 = [43 x i8] c"The resulting product is %d * %d * %d = %d\00"
define void @p009() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store i32 1000, i32* %1
store i32 1, i32* %2
store i32 1, i32* %3
br label %7
7: ; preds = %47, %0
%8 = load i32, i32* %2
%9 = load i32, i32* %2
%10 = mul nsw i32 %8, %9
%11 = load i32, i32* %3
%12 = load i32, i32* %3
%13 = mul nsw i32 %11, %12
%14 = add nsw i32 %10, %13
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = call double @sqrt(i32 %15)
store double %16, double* %6
%17 = load double, double* %6
%18 = load i32, i32* %1
%19 = sitofp i32 %18 to double
%20 = fcmp ogt double %17, %19
br i1 %20, label %21, label %25
21: ; preds = %7
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
%24 = load i32, i32* %2
store i32 %24, i32* %3
br label %47
25: ; preds = %7
%26 = load double, double* %6
%27 = fptosi double %26 to i32
store i32 %27, i32* %4
%28 = load double, double* %6
%29 = load i32, i32* %4
%30 = sitofp i32 %29 to double
%31 = fcmp une double %28, %30
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %47
35: ; preds = %25
%36 = load i32, i32* %2
%37 = load i32, i32* %3
%38 = add nsw i32 %36, %37
%39 = load i32, i32* %4
%40 = add nsw i32 %38, %39
%41 = load i32, i32* %1
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %35
br label %48
44: ; preds = %35
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %47
47: ; preds = %44, %32, %21
br i1 true, label %7, label %48
48: ; preds = %47, %43
%49 = load i32, i32* %2
%50 = load i32, i32* %3
%51 = load i32, i32* %4
%52 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i32 %49, i32 %50, i32 %51)
%53 = load i32, i32* %2
%54 = load i32, i32* %3
%55 = load i32, i32* %4
%56 = load i32, i32* %1
%57 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %53, i32 %54, i32 %55, i32 %56)
%58 = load i32, i32* %2
%59 = load i32, i32* %3
%60 = load i32, i32* %4
%61 = load i32, i32* %2
%62 = load i32, i32* %3
%63 = mul nsw i32 %61, %62
%64 = load i32, i32* %4
%65 = mul nsw i32 %63, %64
%66 = call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %58, i32 %59, i32 %60, i32 %65)
ret void
}

LLVM IR (-O2):
@.str = [69 x i8] c"The pythagorean triplet %d^2 + %d^2 = %d^2 satisfies the equation:\0A\0A\00"
@.str.1 = [22 x i8] c" %d + %d + %d = %d\0A\0A\00"
@.str.2 = [43 x i8] c"The resulting product is %d * %d * %d = %d\00"
define void @p009() {
br label %1
1: ; preds = %10, %0
%2 = phi i32 [ %11, %10 ], [ 1, %0 ]
%3 = mul nsw i32 %2, %2
br label %4
4: ; preds = %20, %1
%5 = phi i32 [ %2, %1 ], [ %21, %20 ]
%6 = mul nsw i32 %5, %5
%7 = add nuw nsw i32 %3, %6
%8 = tail call double @sqrt(i32 %7)
%9 = fcmp ogt double %8, 1.000000e+03
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = add nuw nsw i32 %2, 1
br label %1
12: ; preds = %4
%13 = fptosi double %8 to i32
%14 = sitofp i32 %13 to double
%15 = fcmp une double %8, %14
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = add nuw nsw i32 %2, %5
%18 = add nsw i32 %17, %13
%19 = icmp eq i32 %18, 1000
br i1 %19, label %22, label %20
20: ; preds = %16, %12
%21 = add nuw nsw i32 %5, 1
br label %4
22: ; preds = %16
%23 = tail call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %5, i32 %13)
%24 = tail call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %5, i32 %13, i32 1000)
%25 = mul nsw i32 %2, %5
%26 = mul nsw i32 %25, %13
%27 = tail call i32 (i8*, i32, i32, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %2, i32 %5, i32 %13, i32 %26)
ret void
}