#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__ FLT_GT(double, double, double);
int /*<<< orphan*/ debug(char *, double);
scalar_t__ fabs(double);
scalar_t__ log(scalar_t__);
double lorentzian(double *s, double *z, int len, double bsf, double epsilon) {
  double dist = 0;
  while (--len) {
    dist += log(1 + fabs(*s - *z));
    s++;
    z++;
    if (FLT_GT(dist, bsf, epsilon)) {
      debug(" %.6f (early abandoned)\n", dist);
      return dist;
    }
  }
  debug(" %.6f\n", dist);
  return dist;
}


x86 assembly (clang, -O0):
<lorentzian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1202 <lorentzian+0xc2>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
call   1040 <fabs@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <log@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
call   1050 <FLT_GT@plt>
cmp    $0x0,%rax
je     11fd <lorentzian+0xbd>
movsd  -0x38(%rbp),%xmm0
lea    0xe17(%rip),%rdi
call   1030 <debug@plt>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121d <lorentzian+0xdd>
jmp    1165 <lorentzian+0x25>
movsd  -0x38(%rbp),%xmm0
lea    0xe0b(%rip),%rdi
call   1030 <debug@plt>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lorentzian>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
add    $0xffffffff,%r12d
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
nop
cmp    %ebx,%r12d
je     11c8 <lorentzian+0x88>
movsd  (%r15,%rbx,8),%xmm0
subsd  (%r14,%rbx,8),%xmm0
call   1040 <fabs@plt>
lea    0x1(%rax),%rdi
call   1060 <log@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
call   1050 <FLT_GT@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1170 <lorentzian+0x30>
lea    0xe3a(%rip),%rdi
jmp    11cf <lorentzian+0x8f>
lea    0xe4a(%rip),%rdi
movsd  (%rsp),%xmm0
call   1030 <debug@plt>
movsd  (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c" %.6f (early abandoned)\0A\00"
@.str.1 = [7 x i8] c" %.6f\0A\00"
define double @lorentzian(double* %0, double* %1, i32 %2, double %3, double %4) {
%6 = alloca double
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
store double* %0, double** %7
store double* %1, double** %8
store i32 %2, i32* %9
store double %3, double* %10
store double %4, double* %11
store double 0.000000e+00, double* %12
br label %13
13: ; preds = %42, %5
%14 = load i32, i32* %9
%15 = add nsw i32 %14, -1
store i32 %15, i32* %9
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %43
17: ; preds = %13
%18 = load double*, double** %7
%19 = load double, double* %18
%20 = load double*, double** %8
%21 = load double, double* %20
%22 = fsub double %19, %21
%23 = call i64 @fabs(double %22)
%24 = add nsw i64 1, %23
%25 = call i64 @log(i64 %24)
%26 = sitofp i64 %25 to double
%27 = load double, double* %12
%28 = fadd double %27, %26
store double %28, double* %12
%29 = load double*, double** %7
%30 = getelementptr inbounds double, double* %29, i32 1
store double* %30, double** %7
%31 = load double*, double** %8
%32 = getelementptr inbounds double, double* %31, i32 1
store double* %32, double** %8
%33 = load double, double* %12
%34 = load double, double* %10
%35 = load double, double* %11
%36 = call i64 @FLT_GT(double %33, double %34, double %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %17
%39 = load double, double* %12
%40 = call i32 @debug(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %39)
%41 = load double, double* %12
store double %41, double* %6
br label %47
42: ; preds = %17
br label %13
43: ; preds = %13
%44 = load double, double* %12
%45 = call i32 @debug(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %44)
%46 = load double, double* %12
store double %46, double* %6
br label %47
47: ; preds = %43, %38
%48 = load double, double* %6
ret double %48
}

LLVM IR (-O2):
@.str = [25 x i8] c" %.6f (early abandoned)\0A\00"
@.str.1 = [7 x i8] c" %.6f\0A\00"
define double @lorentzian(double* nocapture %0, double* nocapture %1, i32 %2, double %3, double %4) {
br label %6
6: ; preds = %13, %5
%7 = phi double* [ %1, %5 ], [ %23, %13 ]
%8 = phi i32 [ %2, %5 ], [ %11, %13 ]
%9 = phi double* [ %0, %5 ], [ %22, %13 ]
%10 = phi double [ 0.000000e+00, %5 ], [ %21, %13 ]
%11 = add nsw i32 %8, -1
%12 = icmp eq i32 %11, 0
br i1 %12, label %28, label %13
13: ; preds = %6
%14 = load double, double* %9
%15 = load double, double* %7
%16 = fsub double %14, %15
%17 = tail call i64 @fabs(double %16)
%18 = add nsw i64 %17, 1
%19 = tail call i64 @log(i64 %18)
%20 = sitofp i64 %19 to double
%21 = fadd double %10, %20
%22 = getelementptr inbounds double, double* %9, i64 1
%23 = getelementptr inbounds double, double* %7, i64 1
%24 = tail call i64 @FLT_GT(double %21, double %3, double %4)
%25 = icmp eq i64 %24, 0
br i1 %25, label %6, label %26
26: ; preds = %13
%27 = tail call i32 @debug(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %21)
br label %30
28: ; preds = %6
%29 = tail call i32 @debug(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %10)
br label %30
30: ; preds = %28, %26
%31 = phi double [ %21, %26 ], [ %10, %28 ]
ret double %31
}