#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 */
scalar_t__ faki(int);
long subfak(int n) {
  double subf = 0;
  int a, f;
  if (n < 0)
    return -1;
  for (a = 0; a <= n; a++) {
    if ((a + 2) % 2 == 0)
      f = -1;
    else
      f = 1;
    subf += (-1) * f / (double)faki(a);
  }
  subf = subf * (double)faki(n);
  return (long)subf;
}


x86 assembly (clang, -O0):
<subfak>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    113a <subfak+0x2a>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11e4 <subfak+0xd4>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11b5 <subfak+0xa5>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1170 <subfak+0x60>
movl   $0xffffffff,-0x20(%rbp)
jmp    1177 <subfak+0x67>
movl   $0x1,-0x20(%rbp)
imul   $0xffffffff,-0x20(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <faki@plt>
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1141 <subfak+0x31>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <faki@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
cvttsd2si -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subfak>:
test   %edi,%edi
js     11af <subfak+0x9f>
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
lea    0x1(%r14),%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %ebp,%ebp
lea    0xec4(%rip),%r15
nopl   0x0(%rax)
xor    %eax,%eax
test   $0x1,%bpl
sete   %al
movsd  (%r15,%rax,8),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %ebp,%edi
call   1030 <faki@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1140 <subfak+0x30>
mov    %r14d,%edi
call   1030 <faki@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffffffffffff,%rax
ret

LLVM IR (-O0):
define i64 @subfak(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store double 0.000000e+00, double* %4
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i64 -1, i64* %2
br label %43
10: ; preds = %1
store i32 0, i32* %5
br label %11
11: ; preds = %32, %10
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %11
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 2
%18 = srem i32 %17, 2
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 -1, i32* %6
br label %22
21: ; preds = %15
store i32 1, i32* %6
br label %22
22: ; preds = %21, %20
%23 = load i32, i32* %6
%24 = mul nsw i32 -1, %23
%25 = sitofp i32 %24 to double
%26 = load i32, i32* %5
%27 = call i64 @faki(i32 %26)
%28 = sitofp i64 %27 to double
%29 = fdiv double %25, %28
%30 = load double, double* %4
%31 = fadd double %30, %29
store double %31, double* %4
br label %32
32: ; preds = %22
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %11
35: ; preds = %11
%36 = load double, double* %4
%37 = load i32, i32* %3
%38 = call i64 @faki(i32 %37)
%39 = sitofp i64 %38 to double
%40 = fmul double %36, %39
store double %40, double* %4
%41 = load double, double* %4
%42 = fptosi double %41 to i64
store i64 %42, i64* %2
br label %43
43: ; preds = %35, %9
%44 = load i64, i64* %2
ret i64 %44
}

LLVM IR (-O2):
define i64 @subfak(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %20, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %13, %3 ], [ 0, %1 ]
%5 = phi double [ %12, %3 ], [ 0.000000e+00, %1 ]
%6 = and i32 %4, 1
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, double 1.000000e+00, double -1.000000e+00
%9 = tail call i64 @faki(i32 %4)
%10 = sitofp i64 %9 to double
%11 = fdiv double %8, %10
%12 = fadd double %5, %11
%13 = add nuw i32 %4, 1
%14 = icmp eq i32 %4, %0
br i1 %14, label %15, label %3
15: ; preds = %3
%16 = tail call i64 @faki(i32 %0)
%17 = sitofp i64 %16 to double
%18 = fmul double %12, %17
%19 = fptosi double %18 to i64
br label %20
20: ; preds = %1, %15
%21 = phi i64 [ %19, %15 ], [ -1, %1 ]
ret i64 %21
}