#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*/ exit(int);
double fabs(scalar_t__);
scalar_t__ floor(double);
double isoscelesArea(long long, long long);
int /*<<< orphan*/ printf(char *, long long, long long);
long long euler94(int n) {
  long long sum = 0, ant = 0;
  long long i, p;
  for (i = 2; i < n; i++) {
    double a = isoscelesArea(i, i - 1);
    double b = isoscelesArea(i, i + 1);
    if (fabs(floor(a) - a) < 0.000000001) {
      p = 3 * i - 1;
      sum += p;
    }
    if (fabs(floor(b) - b) < 0.000000001) {
      p = 3 * i + 1;
      sum += p;
    }
    if (sum < ant) {
      printf("overflow:\nant = %lld\nsum = %lld\n", ant, sum);
      exit(1);
    }
    ant = sum;
  }
  return sum;
}


x86 assembly (clang, -O0):
<euler94>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x2,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x4(%rbp),%rcx
cmp    %rcx,%rax
jge    128d <euler94+0x13d>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
sub    $0x1,%rsi
call   1060 <isoscelesArea@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1060 <isoscelesArea@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1070 <floor@plt>
cvtsi2sd %rax,%xmm0
subsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <fabs@plt>
movaps %xmm0,%xmm1
movsd  0xe27(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11fc <euler94+0xac>
imul   $0x3,-0x20(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1070 <floor@plt>
cvtsi2sd %rax,%xmm0
subsd  -0x38(%rbp),%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <fabs@plt>
movaps %xmm0,%xmm1
movsd  0xddb(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1248 <euler94+0xf8>
imul   $0x3,-0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1274 <euler94+0x124>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xda3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1173 <euler94+0x23>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<euler94>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
mov    $0x2,%eax
cmovge %edi,%eax
lea    (%rax,%rax,2),%r12
add    $0xfffffffffffffffa,%r12
mov    $0x2,%ebx
xor    %r13d,%r13d
xor    %ebp,%ebp
xor    %edx,%edx
nopl   (%rax)
mov    %rdx,%r15
cmp    %rbp,%r12
je     1250 <euler94+0x100>
lea    -0x1(%rbx),%rsi
mov    %rbx,%rdi
call   1060 <isoscelesArea@plt>
movsd  %xmm0,0x8(%rsp)
lea    0x1(%rbx),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <isoscelesArea@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1070 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
subsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <fabs@plt>
lea    0x5(%rbp),%rbx
movsd  0xe1e(%rip),%xmm1
ucomisd %xmm0,%xmm1
cmovbe %r13,%rbx
add    %r15,%rbx
movsd  0x10(%rsp),%xmm0
call   1070 <floor@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
subsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%rdi
call   1040 <fabs@plt>
movsd  0xde8(%rip),%xmm1
ucomisd %xmm0,%xmm1
lea    0x7(%rbp),%rdx
cmovbe %r13,%rdx
add    %rbx,%rdx
add    $0x3,%rbp
mov    %r14,%rbx
cmp    %r15,%rdx
jge    1180 <euler94+0x30>
lea    0xdca(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"overflow:\0Aant = %lld\0Asum = %lld\0A\00"
define i64 @euler94(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca double
%8 = alloca double
store i32 %0, i32* %2
store i64 0, i64* %3
store i64 0, i64* %4
store i64 2, i64* %5
br label %9
9: ; preds = %65, %1
%10 = load i64, i64* %5
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = icmp slt i64 %10, %12
br i1 %13, label %14, label %68
14: ; preds = %9
%15 = load i64, i64* %5
%16 = load i64, i64* %5
%17 = sub nsw i64 %16, 1
%18 = call double @isoscelesArea(i64 %15, i64 %17)
store double %18, double* %7
%19 = load i64, i64* %5
%20 = load i64, i64* %5
%21 = add nsw i64 %20, 1
%22 = call double @isoscelesArea(i64 %19, i64 %21)
store double %22, double* %8
%23 = load double, double* %7
%24 = call i64 @floor(double %23)
%25 = sitofp i64 %24 to double
%26 = load double, double* %7
%27 = fsub double %25, %26
%28 = fptosi double %27 to i64
%29 = call double @fabs(i64 %28)
%30 = fcmp olt double %29, 1.000000e-09
br i1 %30, label %31, label %38
31: ; preds = %14
%32 = load i64, i64* %5
%33 = mul nsw i64 3, %32
%34 = sub nsw i64 %33, 1
store i64 %34, i64* %6
%35 = load i64, i64* %6
%36 = load i64, i64* %3
%37 = add nsw i64 %36, %35
store i64 %37, i64* %3
br label %38
38: ; preds = %31, %14
%39 = load double, double* %8
%40 = call i64 @floor(double %39)
%41 = sitofp i64 %40 to double
%42 = load double, double* %8
%43 = fsub double %41, %42
%44 = fptosi double %43 to i64
%45 = call double @fabs(i64 %44)
%46 = fcmp olt double %45, 1.000000e-09
br i1 %46, label %47, label %54
47: ; preds = %38
%48 = load i64, i64* %5
%49 = mul nsw i64 3, %48
%50 = add nsw i64 %49, 1
store i64 %50, i64* %6
%51 = load i64, i64* %6
%52 = load i64, i64* %3
%53 = add nsw i64 %52, %51
store i64 %53, i64* %3
br label %54
54: ; preds = %47, %38
%55 = load i64, i64* %3
%56 = load i64, i64* %4
%57 = icmp slt i64 %55, %56
br i1 %57, label %58, label %63
58: ; preds = %54
%59 = load i64, i64* %4
%60 = load i64, i64* %3
%61 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64 %59, i64 %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %54
%64 = load i64, i64* %3
store i64 %64, i64* %4
br label %65
65: ; preds = %63
%66 = load i64, i64* %5
%67 = add nsw i64 %66, 1
store i64 %67, i64* %5
br label %9
68: ; preds = %9
%69 = load i64, i64* %3
ret i64 %69
}

LLVM IR (-O2):
@.str = [33 x i8] c"overflow:\0Aant = %lld\0Asum = %lld\0A\00"
define i64 @euler94(i32 %0) {
%2 = call i32 @llvm.smax.i32(i32 %0, i32 2)
%3 = zext i32 %2 to i64
br label %4
4: ; preds = %8, %1
%5 = phi i64 [ 2, %1 ], [ %11, %8 ]
%6 = phi i64 [ 0, %1 ], [ %31, %8 ]
%7 = icmp eq i64 %5, %3
br i1 %7, label %36, label %8
8: ; preds = %4
%9 = add nsw i64 %5, -1
%10 = tail call double @isoscelesArea(i64 %5, i64 %9)
%11 = add nuw nsw i64 %5, 1
%12 = tail call double @isoscelesArea(i64 %5, i64 %11)
%13 = tail call i64 @floor(double %10)
%14 = sitofp i64 %13 to double
%15 = fsub double %14, %10
%16 = fptosi double %15 to i64
%17 = tail call double @fabs(i64 %16)
%18 = fcmp olt double %17, 1.000000e-09
%19 = mul nuw nsw i64 %5, 3
%20 = add nsw i64 %19, -1
%21 = select i1 %18, i64 %20, i64 0
%22 = add nsw i64 %21, %6
%23 = tail call i64 @floor(double %12)
%24 = sitofp i64 %23 to double
%25 = fsub double %24, %12
%26 = fptosi double %25 to i64
%27 = tail call double @fabs(i64 %26)
%28 = fcmp olt double %27, 1.000000e-09
%29 = add nuw nsw i64 %19, 1
%30 = select i1 %28, i64 %29, i64 0
%31 = add nsw i64 %22, %30
%32 = icmp slt i64 %31, %6
br i1 %32, label %33, label %4
33: ; preds = %8
%34 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64 %6, i64 %31)
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %4
ret i64 %6
}