#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 fabs(double);
scalar_t__ nlopt_isinf(double);
int relstop(double vold, double vnew, double reltol, double abstol) {
  if (nlopt_isinf(vold))
    return 0;
  return (fabs(vnew - vold) < abstol ||
          fabs(vnew - vold) < reltol * (fabs(vnew) + fabs(vold)) * 0.5 ||
          (reltol > 0 && vnew == vold));
}


x86 assembly (clang, -O0):
<relstop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <nlopt_isinf@plt>
cmp    $0x0,%rax
je     114c <relstop+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    120f <relstop+0xff>
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movaps 0xea3(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mov    $0x1,%al
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
ja     1204 <relstop+0xf4>
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movaps 0xe7a(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movaps 0xe65(%rip),%xmm3
pand   %xmm3,%xmm2
movsd  -0x10(%rbp),%xmm3
movaps 0xe55(%rip),%xmm4
pand   %xmm4,%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
movsd  0xe51(%rip),%xmm2
mulsd  %xmm2,%xmm0
mov    $0x1,%al
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
ja     1204 <relstop+0xf4>
movsd  -0x20(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x2a(%rbp)
jbe    11fe <relstop+0xee>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<relstop>:
sub    $0x38,%rsp
movsd  %xmm3,0x30(%rsp)
movsd  %xmm2,0x28(%rsp)
movapd %xmm1,0x10(%rsp)
movapd %xmm0,(%rsp)
call   1030 <nlopt_isinf@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     113f <relstop+0x2f>
add    $0x38,%rsp
ret
movsd  0x28(%rsp),%xmm3
movapd 0x10(%rsp),%xmm0
subsd  (%rsp),%xmm0
andpd  0xea8(%rip),%xmm0
mov    $0x1,%eax
movsd  0x30(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     113a <relstop+0x2a>
movapd 0xe8f(%rip),%xmm1
movapd 0x10(%rsp),%xmm2
andpd  %xmm1,%xmm2
andpd  (%rsp),%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm3,%xmm1
mulsd  0xe80(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     113a <relstop+0x2a>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
seta   %al
movapd 0x10(%rsp),%xmm0
ucomisd (%rsp),%xmm0
setnp  %cl
sete   %dl
and    %cl,%dl
and    %al,%dl
movzbl %dl,%eax
add    $0x38,%rsp
ret

LLVM IR (-O0):
define i32 @relstop(double %0, double %1, double %2, double %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%10 = load double, double* %6
%11 = call i64 @nlopt_isinf(double %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %4
store i32 0, i32* %5
br label %47
14: ; preds = %4
%15 = load double, double* %7
%16 = load double, double* %6
%17 = fsub double %15, %16
%18 = call double @llvm.fabs.f64(double %17)
%19 = load double, double* %9
%20 = fcmp olt double %18, %19
br i1 %20, label %44, label %21
21: ; preds = %14
%22 = load double, double* %7
%23 = load double, double* %6
%24 = fsub double %22, %23
%25 = call double @llvm.fabs.f64(double %24)
%26 = load double, double* %8
%27 = load double, double* %7
%28 = call double @llvm.fabs.f64(double %27)
%29 = load double, double* %6
%30 = call double @llvm.fabs.f64(double %29)
%31 = fadd double %28, %30
%32 = fmul double %26, %31
%33 = fmul double %32, 5.000000e-01
%34 = fcmp olt double %25, %33
br i1 %34, label %44, label %35
35: ; preds = %21
%36 = load double, double* %8
%37 = fcmp ogt double %36, 0.000000e+00
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load double, double* %7
%40 = load double, double* %6
%41 = fcmp oeq double %39, %40
br label %42
42: ; preds = %38, %35
%43 = phi i1 [ false, %35 ], [ %41, %38 ]
br label %44
44: ; preds = %42, %21, %14
%45 = phi i1 [ true, %21 ], [ true, %14 ], [ %43, %42 ]
%46 = zext i1 %45 to i32
store i32 %46, i32* %5
br label %47
47: ; preds = %44, %13
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
define i32 @relstop(double %0, double %1, double %2, double %3) {
%5 = tail call i64 @nlopt_isinf(double %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = fsub double %1, %0
%9 = tail call double @llvm.fabs.f64(double %8)
%10 = fcmp olt double %9, %3
br i1 %10, label %23, label %11
11: ; preds = %7
%12 = tail call double @llvm.fabs.f64(double %1)
%13 = tail call double @llvm.fabs.f64(double %0)
%14 = fadd double %13, %12
%15 = fmul double %14, %2
%16 = fmul double %15, 5.000000e-01
%17 = fcmp olt double %9, %16
br i1 %17, label %23, label %18
18: ; preds = %11
%19 = fcmp ogt double %2, 0.000000e+00
%20 = fcmp oeq double %1, %0
%21 = and i1 %20, %19
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %7, %11, %18, %4
%24 = phi i32 [ 0, %4 ], [ 1, %11 ], [ 1, %7 ], [ %22, %18 ]
ret i32 %24
}