#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 sqrt(double);
double erfi(double z) {
  double da1, out, zz = z * z;
  unsigned int n;
  da1 = z;
  out = da1;
  for (n = 1; n < 500; n++) {
    da1 *= zz / n;
    out += da1 / (2 * n + 1);
  }
  out *= 2 / sqrt(3.14159265358979328);
  return out;
}


x86 assembly (clang, -O0):
<erfi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x1f4,-0x24(%rbp)
jae    11a2 <erfi+0x92>
movsd  -0x20(%rbp),%xmm1
mov    -0x24(%rbp),%eax
cvtsi2sd %rax,%xmm0
divsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x24(%rbp),%ecx
mov    %ecx,%eax
lea    0x1(%rax,%rax,1),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1147 <erfi+0x37>
movsd  0xe56(%rip),%xmm0
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    $0x2,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<erfi>:
push   %rax
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0xedf(%rip),%xmm2
mov    $0x3,%eax
movapd %xmm2,%xmm3
movapd %xmm0,%xmm6
xchg   %ax,%ax
movapd %xmm1,%xmm4
divsd  %xmm3,%xmm4
mulsd  %xmm4,%xmm0
mov    %eax,%ecx
xorps  %xmm4,%xmm4
cvtsi2sd %rcx,%xmm4
movapd %xmm0,%xmm5
divsd  %xmm4,%xmm5
addsd  %xmm5,%xmm6
addsd  %xmm2,%xmm3
add    $0x2,%eax
cmp    $0x3e9,%eax
jne    1130 <erfi+0x20>
movsd  0xea0(%rip),%xmm0
movsd  %xmm6,(%rsp)
call   1030 <sqrt@plt>
mov    %eax,%ecx
mov    $0x2,%eax
xor    %edx,%edx
idiv   %ecx
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @erfi(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store double %0, double* %2
%7 = load double, double* %2
%8 = load double, double* %2
%9 = fmul double %7, %8
store double %9, double* %5
%10 = load double, double* %2
store double %10, double* %3
%11 = load double, double* %3
store double %11, double* %4
store i32 1, i32* %6
br label %12
12: ; preds = %30, %1
%13 = load i32, i32* %6
%14 = icmp ult i32 %13, 500
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = load double, double* %5
%17 = load i32, i32* %6
%18 = uitofp i32 %17 to double
%19 = fdiv double %16, %18
%20 = load double, double* %3
%21 = fmul double %20, %19
store double %21, double* %3
%22 = load double, double* %3
%23 = load i32, i32* %6
%24 = mul i32 2, %23
%25 = add i32 %24, 1
%26 = uitofp i32 %25 to double
%27 = fdiv double %22, %26
%28 = load double, double* %4
%29 = fadd double %28, %27
store double %29, double* %4
br label %30
30: ; preds = %15
%31 = load i32, i32* %6
%32 = add i32 %31, 1
store i32 %32, i32* %6
br label %12
33: ; preds = %12
%34 = call i32 @sqrt(double 0x400921FB54442D18)
%35 = sdiv i32 2, %34
%36 = sitofp i32 %35 to double
%37 = load double, double* %4
%38 = fmul double %37, %36
store double %38, double* %4
%39 = load double, double* %4
ret double %39
}

LLVM IR (-O2):
define double @erfi(double %0) {
%2 = fmul double %0, %0
br label %3
3: ; preds = %1, %3
%4 = phi i32 [ 1, %1 ], [ %15, %3 ]
%5 = phi double [ %0, %1 ], [ %9, %3 ]
%6 = phi double [ %0, %1 ], [ %14, %3 ]
%7 = uitofp i32 %4 to double
%8 = fdiv double %2, %7
%9 = fmul double %5, %8
%10 = shl nuw nsw i32 %4, 1
%11 = or i32 %10, 1
%12 = uitofp i32 %11 to double
%13 = fdiv double %9, %12
%14 = fadd double %6, %13
%15 = add nuw nsw i32 %4, 1
%16 = icmp eq i32 %15, 500
br i1 %16, label %17, label %3
17: ; preds = %3
%18 = tail call i32 @sqrt(double 0x400921FB54442D18)
%19 = sdiv i32 2, %18
%20 = sitofp i32 %19 to double
%21 = fmul double %14, %20
ret double %21
}