#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 compute_term(long, int);
int compute_digit(long n) {
  double s;
  s = 4.0 * compute_term(n, 1);
  s -= 2.0 * compute_term(n, 4);
  s -= compute_term(n, 5);
  s -= compute_term(n, 6);
  while (s < 0) {
    s++;
  }
  while (s > 1) {
    s--;
  }
  return s * 16;
}


x86 assembly (clang, -O0):
<compute_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1030 <compute_term@plt>
movaps %xmm0,%xmm1
movsd  0xecb(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1030 <compute_term@plt>
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5,%esi
call   1030 <compute_term@plt>
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x6,%esi
call   1030 <compute_term@plt>
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11c4 <compute_digit+0xb4>
movsd  0xe53(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    119f <compute_digit+0x8f>
jmp    11c9 <compute_digit+0xb9>
movsd  -0x10(%rbp),%xmm0
movsd  0xe32(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f7 <compute_digit+0xe7>
movsd  0xe30(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11c9 <compute_digit+0xb9>
movsd  0xe11(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_digit>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x1,%esi
call   1030 <compute_term@plt>
mulsd  0xed6(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <compute_term@plt>
addsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <compute_term@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %rbx,%rdi
mov    $0x6,%esi
call   1030 <compute_term@plt>
movsd  0x8(%rsp),%xmm2
subsd  %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jbe    11aa <compute_digit+0x9a>
movsd  0xe71(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
addsd  %xmm1,%xmm2
ucomisd %xmm2,%xmm0
ja     11a0 <compute_digit+0x90>
ucomisd 0xe56(%rip),%xmm2
jbe    11da <compute_digit+0xca>
movsd  0xe54(%rip),%xmm0
movsd  0xe44(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
addsd  %xmm0,%xmm2
ucomisd %xmm1,%xmm2
ja     11d0 <compute_digit+0xc0>
mulsd  0xe36(%rip),%xmm2
cvttsd2si %xmm2,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @compute_digit(i64 %0) {
%2 = alloca i64
%3 = alloca double
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = call double @compute_term(i64 %4, i32 1)
%6 = fmul double 4.000000e+00, %5
store double %6, double* %3
%7 = load i64, i64* %2
%8 = call double @compute_term(i64 %7, i32 4)
%9 = load double, double* %3
%10 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %8, double %9)
store double %10, double* %3
%11 = load i64, i64* %2
%12 = call double @compute_term(i64 %11, i32 5)
%13 = load double, double* %3
%14 = fsub double %13, %12
store double %14, double* %3
%15 = load i64, i64* %2
%16 = call double @compute_term(i64 %15, i32 6)
%17 = load double, double* %3
%18 = fsub double %17, %16
store double %18, double* %3
br label %19
19: ; preds = %22, %1
%20 = load double, double* %3
%21 = fcmp olt double %20, 0.000000e+00
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load double, double* %3
%24 = fadd double %23, 1.000000e+00
store double %24, double* %3
br label %19
25: ; preds = %19
br label %26
26: ; preds = %29, %25
%27 = load double, double* %3
%28 = fcmp ogt double %27, 1.000000e+00
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load double, double* %3
%31 = fadd double %30, -1.000000e+00
store double %31, double* %3
br label %26
32: ; preds = %26
%33 = load double, double* %3
%34 = fmul double %33, 1.600000e+01
%35 = fptosi double %34 to i32
ret i32 %35
}

LLVM IR (-O2):
define i32 @compute_digit(i64 %0) {
%2 = tail call double @compute_term(i64 %0, i32 1)
%3 = fmul double %2, 4.000000e+00
%4 = tail call double @compute_term(i64 %0, i32 4)
%5 = tail call double @llvm.fmuladd.f64(double %4, double -2.000000e+00, double %3)
%6 = tail call double @compute_term(i64 %0, i32 5)
%7 = fsub double %5, %6
%8 = tail call double @compute_term(i64 %0, i32 6)
%9 = fsub double %7, %8
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %14, label %11
11: ; preds = %14, %1
%12 = phi double [ %9, %1 ], [ %16, %14 ]
%13 = fcmp ogt double %12, 1.000000e+00
br i1 %13, label %18, label %22
14: ; preds = %1, %14
%15 = phi double [ %16, %14 ], [ %9, %1 ]
%16 = fadd double %15, 1.000000e+00
%17 = fcmp olt double %16, 0.000000e+00
br i1 %17, label %14, label %11
18: ; preds = %11, %18
%19 = phi double [ %20, %18 ], [ %12, %11 ]
%20 = fadd double %19, -1.000000e+00
%21 = fcmp ogt double %20, 1.000000e+00
br i1 %21, label %18, label %22
22: ; preds = %18, %11
%23 = phi double [ %12, %11 ], [ %20, %18 ]
%24 = fmul double %23, 1.600000e+01
%25 = fptosi double %24 to i32
ret i32 %25
}