#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 const fabs(double);
scalar_t__ isinf(double);
scalar_t__ isnan(double);
double oo_xirrResult(double const *, double const *, int, double);
double oo_xirrResult_Deriv1(double const *, double const *, int, double);
double getXirr(const double *rValues, const double *rDates, int nCount,
               const double rGuessRate) {
  double fResultRate = rGuessRate;
  static const double fMaxEps = 1e-10;
  static const int nMaxIter = 50;
  double fNewRate, fRateEps, fResultValue;
  int nIter = 0;
  int nIterScan = 0;
  int bContLoop = 0;
  int bResultRateScanEnd = 0;
  do {
    if (nIterScan >= 1) {
      fResultRate = -0.99 + (nIterScan - 1) * 0.01;
    }
    do {
      fResultValue = oo_xirrResult(rValues, rDates, nCount, fResultRate);
      fNewRate = fResultRate -
                 fResultValue /
                     oo_xirrResult_Deriv1(rValues, rDates, nCount, fResultRate);
      fRateEps = fabs(fNewRate - fResultRate);
      fResultRate = fNewRate;
      bContLoop = (fRateEps > fMaxEps) && (fabs(fResultValue) > fMaxEps);
    } while (bContLoop && (++nIter < nMaxIter));
    nIter = 0;
    if (isnan(fResultRate) || isinf(fResultRate) || isnan(fResultValue) ||
        isinf(fResultValue)) {
      bContLoop = 1;
    }
    ++nIterScan;
    bResultRateScanEnd = (nIterScan >= 200);
  } while (bContLoop && !bResultRateScanEnd);
  if (bContLoop) {
    return -1;
  }
  return fResultRate;
}


x86 assembly (clang, -O0):
<getXirr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
cmpl   $0x1,-0x50(%rbp)
jl     11c2 <getXirr+0x72>
mov    -0x50(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe53(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe4f(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11c7 <getXirr+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
movsd  -0x30(%rbp),%xmm0
call   1030 <oo_xirrResult@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
movsd  -0x30(%rbp),%xmm0
call   1040 <oo_xirrResult_Deriv1@plt>
movsd  -0x70(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
call   1050 <fabs@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x40(%rbp),%xmm0
xor    %eax,%eax
movsd  0xdbf(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x59(%rbp)
jbe    127a <getXirr+0x12a>
movsd  -0x48(%rbp),%xmm0
call   1050 <fabs@plt>
movsd  0xda0(%rip),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x54(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x54(%rbp)
mov    %al,-0x71(%rbp)
je     12a6 <getXirr+0x156>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
cmp    $0x32,%eax
setl   %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    11c7 <getXirr+0x77>
movl   $0x0,-0x4c(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1060 <isnan@plt>
cmp    $0x0,%rax
jne    1308 <getXirr+0x1b8>
movsd  -0x30(%rbp),%xmm0
call   1070 <isinf@plt>
cmp    $0x0,%rax
jne    1308 <getXirr+0x1b8>
movsd  -0x48(%rbp),%xmm0
call   1060 <isnan@plt>
cmp    $0x0,%rax
jne    1308 <getXirr+0x1b8>
movsd  -0x48(%rbp),%xmm0
call   1070 <isinf@plt>
cmp    $0x0,%rax
je     130f <getXirr+0x1bf>
movl   $0x1,-0x54(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
cmpl   $0xc8,-0x50(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x58(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x54(%rbp)
mov    %al,-0x72(%rbp)
je     1345 <getXirr+0x1f5>
cmpl   $0x0,-0x58(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x72(%rbp)
mov    -0x72(%rbp),%al
test   $0x1,%al
jne    1191 <getXirr+0x41>
cmpl   $0x0,-0x54(%rbp)
je     136c <getXirr+0x21c>
movsd  0xcb6(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1376 <getXirr+0x226>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getXirr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%r13
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r15d,%eax
sub    $0x1,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  0xe8b(%rip),%xmm1
addsd  0xe8b(%rip),%xmm1
jb     1183 <getXirr+0x43>
movapd %xmm1,%xmm0
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm0,(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1030 <oo_xirrResult@plt>
movapd %xmm0,0x10(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
movsd  0x8(%rsp),%xmm0
call   1040 <oo_xirrResult_Deriv1@plt>
movapd 0x10(%rsp),%xmm4
movapd %xmm4,%xmm1
divsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
movapd 0xe2a(%rip),%xmm2
andpd  %xmm2,%xmm1
movsd  0xe0e(%rip),%xmm3
ucomisd %xmm3,%xmm1
seta   %al
movapd %xmm4,%xmm1
andpd  %xmm2,%xmm1
ucomisd %xmm3,%xmm1
seta   %bl
and    %al,%bl
cmp    $0x1,%bl
jne    122d <getXirr+0xed>
lea    0x1(%rbp),%eax
cmp    $0x31,%ebp
mov    %eax,%ebp
jb     1190 <getXirr+0x50>
call   1050 <isnan@plt>
test   %rax,%rax
jne    1270 <getXirr+0x130>
movsd  (%rsp),%xmm0
call   1060 <isinf@plt>
test   %rax,%rax
jne    1270 <getXirr+0x130>
movapd 0x10(%rsp),%xmm0
call   1050 <isnan@plt>
test   %rax,%rax
jne    1270 <getXirr+0x130>
movapd 0x10(%rsp),%xmm0
call   1060 <isinf@plt>
test   %rax,%rax
je     1294 <getXirr+0x154>
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%eax
movsd  (%rsp),%xmm0
test   %eax,%eax
je     1299 <getXirr+0x159>
lea    0x1(%r15),%ecx
cmp    $0xc7,%r15d
mov    %ecx,%r15d
jb     1160 <getXirr+0x20>
jmp    1299 <getXirr+0x159>
movzbl %bl,%eax
jmp    1275 <getXirr+0x135>
test   %eax,%eax
je     12a5 <getXirr+0x165>
movsd  0xd73(%rip),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@getXirr.fMaxEps = internal constant double 1.000000e-10
@getXirr.nMaxIter = internal constant i32 50
define double @getXirr(double* %0, double* %1, i32 %2, double %3) {
%5 = alloca double
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store i32 %2, i32* %8
store double %3, double* %9
%18 = load double, double* %9
store double %18, double* %10
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
store i32 0, i32* %17
br label %19
19: ; preds = %96, %4
%20 = load i32, i32* %15
%21 = icmp sge i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %15
%24 = sub nsw i32 %23, 1
%25 = sitofp i32 %24 to double
%26 = call double @llvm.fmuladd.f64(double %25, double 1.000000e-02, double 0xBFEFAE147AE147AE)
store double %26, double* %10
br label %27
27: ; preds = %22, %19
br label %28
28: ; preds = %64, %27
%29 = load double*, double** %6
%30 = load double*, double** %7
%31 = load i32, i32* %8
%32 = load double, double* %10
%33 = call double @oo_xirrResult(double* %29, double* %30, i32 %31, double %32)
store double %33, double* %13
%34 = load double, double* %10
%35 = load double, double* %13
%36 = load double*, double** %6
%37 = load double*, double** %7
%38 = load i32, i32* %8
%39 = load double, double* %10
%40 = call double @oo_xirrResult_Deriv1(double* %36, double* %37, i32 %38, double %39)
%41 = fdiv double %35, %40
%42 = fsub double %34, %41
store double %42, double* %11
%43 = load double, double* %11
%44 = load double, double* %10
%45 = fsub double %43, %44
%46 = call double @fabs(double %45)
store double %46, double* %12
%47 = load double, double* %11
store double %47, double* %10
%48 = load double, double* %12
%49 = fcmp ogt double %48, 1.000000e-10
br i1 %49, label %50, label %54
50: ; preds = %28
%51 = load double, double* %13
%52 = call double @fabs(double %51)
%53 = fcmp ogt double %52, 1.000000e-10
br label %54
54: ; preds = %50, %28
%55 = phi i1 [ false, %28 ], [ %53, %50 ]
%56 = zext i1 %55 to i32
store i32 %56, i32* %16
br label %57
57: ; preds = %54
%58 = load i32, i32* %16
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = load i32, i32* %14
%62 = add nsw i32 %61, 1
store i32 %62, i32* %14
%63 = icmp slt i32 %62, 50
br label %64
64: ; preds = %60, %57
%65 = phi i1 [ false, %57 ], [ %63, %60 ]
br i1 %65, label %28, label %66
66: ; preds = %64
store i32 0, i32* %14
%67 = load double, double* %10
%68 = call i64 @isnan(double %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %82, label %70
70: ; preds = %66
%71 = load double, double* %10
%72 = call i64 @isinf(double %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %82, label %74
74: ; preds = %70
%75 = load double, double* %13
%76 = call i64 @isnan(double %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %82, label %78
78: ; preds = %74
%79 = load double, double* %13
%80 = call i64 @isinf(double %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %78, %74, %70, %66
store i32 1, i32* %16
br label %83
83: ; preds = %82, %78
%84 = load i32, i32* %15
%85 = add nsw i32 %84, 1
store i32 %85, i32* %15
%86 = load i32, i32* %15
%87 = icmp sge i32 %86, 200
%88 = zext i1 %87 to i32
store i32 %88, i32* %17
br label %89
89: ; preds = %83
%90 = load i32, i32* %16
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %89
%93 = load i32, i32* %17
%94 = icmp ne i32 %93, 0
%95 = xor i1 %94, true
br label %96
96: ; preds = %92, %89
%97 = phi i1 [ false, %89 ], [ %95, %92 ]
br i1 %97, label %19, label %98
98: ; preds = %96
%99 = load i32, i32* %16
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %102
101: ; preds = %98
store double -1.000000e+00, double* %5
br label %104
102: ; preds = %98
%103 = load double, double* %10
store double %103, double* %5
br label %104
104: ; preds = %102, %101
%105 = load double, double* %5
ret double %105
}

LLVM IR (-O2):
define double @getXirr(double* %0, double* %1, i32 %2, double %3) {
br label %5
5: ; preds = %43, %4
%6 = phi double [ %3, %4 ], [ %19, %43 ]
%7 = phi i32 [ 0, %4 ], [ %45, %43 ]
%8 = icmp eq i32 %7, 0
%9 = add nsw i32 %7, -1
%10 = sitofp i32 %9 to double
%11 = tail call double @llvm.fmuladd.f64(double %10, double 1.000000e-02, double 0xBFEFAE147AE147AE)
%12 = select i1 %8, double %6, double %11
br label %13
13: ; preds = %13, %5
%14 = phi double [ %12, %5 ], [ %19, %13 ]
%15 = phi i32 [ 0, %5 ], [ %26, %13 ]
%16 = tail call double @oo_xirrResult(double* %0, double* %1, i32 %2, double %14)
%17 = tail call double @oo_xirrResult_Deriv1(double* %0, double* %1, i32 %2, double %14)
%18 = fdiv double %16, %17
%19 = fsub double %14, %18
%20 = fsub double %19, %14
%21 = tail call double @llvm.fabs.f64(double %20)
%22 = fcmp ogt double %21, 1.000000e-10
%23 = tail call double @llvm.fabs.f64(double %16)
%24 = fcmp ogt double %23, 1.000000e-10
%25 = select i1 %22, i1 %24, i1 false
%26 = add nuw nsw i32 %15, 1
%27 = icmp ult i32 %15, 49
%28 = select i1 %25, i1 %27, i1 false
br i1 %28, label %13, label %29
29: ; preds = %13
%30 = zext i1 %25 to i32
%31 = tail call i64 @isnan(double %19)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = tail call i64 @isinf(double %19)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = tail call i64 @isnan(double %16)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = tail call i64 @isinf(double %16)
%41 = icmp eq i64 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %39, %36, %33, %29
br label %43
43: ; preds = %42, %39
%44 = phi i32 [ 1, %42 ], [ %30, %39 ]
%45 = add nuw nsw i32 %7, 1
%46 = icmp ult i32 %7, 199
%47 = icmp ne i32 %44, 0
%48 = select i1 %47, i1 %46, i1 false
br i1 %48, label %5, label %49
49: ; preds = %43
%50 = select i1 %47, double -1.000000e+00, double %19
ret double %50
}