#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 */
double calculate_c(int, int);
int /*<<< orphan*/ printf(char *, ...);
void main() {
  int a = 0, b = 0, c = 0;
  double tmp_c, sum;
  printf("Problem #9 Solution\n-------------------\n");
  a = 100;
  while (a <= 500 && c == 0) {
    b = 1;
    while (b <= a && c == 0) {
      tmp_c = calculate_c(a, b);
      sum = (double)a + (double)b + tmp_c;
      if (sum == 1000.0) {
        c = (int)tmp_c;
      }
      if (!c)
        ++b;
    }
    if (!c)
      ++a;
  }
  printf("a = %d; b = %d; c = %d; product = %d\n", a, b, c, (a * b * c));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x64,-0x4(%rbp)
xor    %eax,%eax
cmpl   $0x1f4,-0x4(%rbp)
mov    %al,-0x21(%rbp)
jg     116e <main+0x4e>
cmpl   $0x0,-0xc(%rbp)
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117e <main+0x5e>
jmp    122d <main+0x10d>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
xor    %eax,%eax
cmp    -0x4(%rbp),%ecx
mov    %al,-0x22(%rbp)
jg     11a0 <main+0x80>
cmpl   $0x0,-0xc(%rbp)
sete   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11b0 <main+0x90>
jmp    1215 <main+0xf5>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <calculate_c@plt>
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
addsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe1b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11fd <main+0xdd>
jp     11fd <main+0xdd>
cvttsd2si -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1210 <main+0xf0>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1185 <main+0x65>
cmpl   $0x0,-0xc(%rbp)
jne    1228 <main+0x108>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1152 <main+0x32>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x4(%rbp),%r8d
imul   -0x8(%rbp),%r8d
imul   -0xc(%rbp),%r8d
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
mov    $0x64,%ebx
xor    %r14d,%r14d
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <calculate_c@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
addsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xe6e(%rip),%xmm1
cvttsd2si %xmm0,%ecx
cmovne %r14d,%ecx
cmovp  %r14d,%ecx
cmp    $0x1,%ecx
adc    $0x0,%ebp
cmp    %ebx,%ebp
ja     11ac <main+0x7c>
test   %ecx,%ecx
je     1170 <main+0x40>
cmp    $0x1,%ecx
adc    $0x0,%ebx
cmp    $0x1f4,%ebx
ja     11be <main+0x8e>
test   %ecx,%ecx
je     1150 <main+0x20>
mov    %ebp,%r8d
imul   %ecx,%r8d
imul   %ebx,%r8d
lea    0xe38(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"Problem Solution\0A-------------------\0A\00"
@.str.1 = [38 x i8] c"a = %d; b = %d; c = %d; product = %d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 100, i32* %1
br label %7
7: ; preds = %54, %0
%8 = load i32, i32* %1
%9 = icmp sle i32 %8, 500
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br label %13
13: ; preds = %10, %7
%14 = phi i1 [ false, %7 ], [ %12, %10 ]
br i1 %14, label %15, label %55
15: ; preds = %13
store i32 1, i32* %2
br label %16
16: ; preds = %47, %15
%17 = load i32, i32* %2
%18 = load i32, i32* %1
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 0
br label %23
23: ; preds = %20, %16
%24 = phi i1 [ false, %16 ], [ %22, %20 ]
br i1 %24, label %25, label %48
25: ; preds = %23
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = call double @calculate_c(i32 %26, i32 %27)
store double %28, double* %4
%29 = load i32, i32* %1
%30 = sitofp i32 %29 to double
%31 = load i32, i32* %2
%32 = sitofp i32 %31 to double
%33 = fadd double %30, %32
%34 = load double, double* %4
%35 = fadd double %33, %34
store double %35, double* %5
%36 = load double, double* %5
%37 = fcmp oeq double %36, 1.000000e+03
br i1 %37, label %38, label %41
38: ; preds = %25
%39 = load double, double* %4
%40 = fptosi double %39 to i32
store i32 %40, i32* %3
br label %41
41: ; preds = %38, %25
%42 = load i32, i32* %3
%43 = icmp ne i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = load i32, i32* %2
%46 = add nsw i32 %45, 1
store i32 %46, i32* %2
br label %47
47: ; preds = %44, %41
br label %16
48: ; preds = %23
%49 = load i32, i32* %3
%50 = icmp ne i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = load i32, i32* %1
%53 = add nsw i32 %52, 1
store i32 %53, i32* %1
br label %54
54: ; preds = %51, %48
br label %7
55: ; preds = %13
%56 = load i32, i32* %1
%57 = load i32, i32* %2
%58 = load i32, i32* %3
%59 = load i32, i32* %1
%60 = load i32, i32* %2
%61 = mul nsw i32 %59, %60
%62 = load i32, i32* %3
%63 = mul nsw i32 %61, %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %56, i32 %57, i32 %58, i32 %63)
ret void
}

LLVM IR (-O2):
@.str.1 = [38 x i8] c"a = %d; b = %d; c = %d; product = %d\0A\00"
@str = [40 x i8] c"Problem Solution\0A-------------------\00"
define void @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %19, %0
%3 = phi i32 [ 100, %0 ], [ %21, %19 ]
%4 = sitofp i32 %3 to double
br label %5
5: ; preds = %2, %5
%6 = phi i32 [ 1, %2 ], [ %16, %5 ]
%7 = tail call double @calculate_c(i32 %3, i32 %6)
%8 = sitofp i32 %6 to double
%9 = fadd double %4, %8
%10 = fadd double %9, %7
%11 = fcmp oeq double %10, 1.000000e+03
%12 = fptosi double %7 to i32
%13 = select i1 %11, i32 %12, i32 0
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %6, %15
%17 = icmp ule i32 %16, %3
%18 = select i1 %17, i1 %14, i1 false
br i1 %18, label %5, label %19
19: ; preds = %5
%20 = zext i1 %14 to i32
%21 = add nuw nsw i32 %3, %20
%22 = icmp ult i32 %21, 501
%23 = icmp eq i32 %13, 0
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %2, label %25
25: ; preds = %19
%26 = mul i32 %16, %13
%27 = mul i32 %26, %21
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %16, i32 %13, i32 %27)
ret void
}