#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 /*<<< orphan*/ assert(int);
int /*<<< orphan*/ coco_error(char *);
int mo_get_dominance(double const *, double const *, int);
double mo_get_norm(double const *, double const *, int);
double mo_get_distance_to_ROI(const double *y, const double *ideal,
                              const double *nadir, const size_t dimension) {
  double distance = 0;
  assert(dimension == 2);
  assert(mo_get_dominance(ideal, y, 2) == 1);
  if (mo_get_dominance(y, nadir, 2) <= -1) {
    distance = mo_get_norm(y, nadir, 2);
  } else if (y[0] < nadir[0])
    distance = y[1] - nadir[1];
  else if (y[1] < nadir[1])
    distance = y[0] - nadir[0];
  else {
    coco_error("mo_get_distance_to_ROI(): unexpected exception");
    return 0;
  }
  return distance / ((nadir[1] - ideal[1]) * (nadir[0] - ideal[0]));
}


x86 assembly (clang, -O0):
<mo_get_distance_to_ROI>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpq   $0x2,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2,%edx
call   1060 <mo_get_dominance@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x2,%edx
call   1060 <mo_get_dominance@plt>
cmp    $0xffffffff,%eax
jg     11cb <mo_get_distance_to_ROI+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x2,%edx
call   1050 <mo_get_norm@plt>
movsd  %xmm0,-0x30(%rbp)
jmp    125a <mo_get_distance_to_ROI+0x11a>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    1201 <mo_get_distance_to_ROI+0xc1>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x20(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1255 <mo_get_distance_to_ROI+0x115>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    1237 <mo_get_distance_to_ROI+0xf7>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1250 <mo_get_distance_to_ROI+0x110>
lea    0xdc2(%rip),%rdi
call   1040 <coco_error@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    128e <mo_get_distance_to_ROI+0x14e>
jmp    1255 <mo_get_distance_to_ROI+0x115>
jmp    125a <mo_get_distance_to_ROI+0x11a>
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
subsd  0x8(%rax),%xmm1
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mo_get_distance_to_ROI>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
cmp    $0x2,%rcx
sete   %dil
call   1030 <assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1060 <mo_get_dominance@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1060 <mo_get_dominance@plt>
test   %eax,%eax
js     11b1 <mo_get_distance_to_ROI+0x71>
movsd  (%rbx),%xmm2
movsd  0x8(%rbx),%xmm0
movupd (%r15),%xmm1
ucomisd %xmm2,%xmm1
jbe    11c8 <mo_get_distance_to_ROI+0x88>
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
subsd  %xmm2,%xmm0
jmp    11de <mo_get_distance_to_ROI+0x9e>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1050 <mo_get_norm@plt>
movupd (%r15),%xmm1
jmp    11de <mo_get_distance_to_ROI+0x9e>
movapd %xmm1,%xmm3
unpckhpd %xmm1,%xmm3
ucomisd %xmm0,%xmm3
jbe    11fd <mo_get_distance_to_ROI+0xbd>
subsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
movupd (%r14),%xmm2
subpd  %xmm2,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
mulsd  %xmm1,%xmm2
divsd  %xmm2,%xmm0
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdfc(%rip),%rdi
call   1040 <coco_error@plt>
xorpd  %xmm0,%xmm0
jmp    11f7 <mo_get_distance_to_ROI+0xb7>

LLVM IR (-O0):
@.str = [47 x i8] c"mo_get_distance_to_ROI(): unexpected exception\00"
define double @mo_get_distance_to_ROI(double* %0, double* %1, double* %2, i64 %3) {
%5 = alloca double
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i64
%10 = alloca double
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store i64 %3, i64* %9
store double 0.000000e+00, double* %10
%11 = load i64, i64* %9
%12 = icmp eq i64 %11, 2
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load double*, double** %7
%16 = load double*, double** %6
%17 = call i32 @mo_get_dominance(double* %15, double* %16, i32 2)
%18 = icmp eq i32 %17, 1
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load double*, double** %6
%22 = load double*, double** %8
%23 = call i32 @mo_get_dominance(double* %21, double* %22, i32 2)
%24 = icmp sle i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %4
%26 = load double*, double** %6
%27 = load double*, double** %8
%28 = call double @mo_get_norm(double* %26, double* %27, i32 2)
store double %28, double* %10
br label %65
29: ; preds = %4
%30 = load double*, double** %6
%31 = getelementptr inbounds double, double* %30, i64 0
%32 = load double, double* %31
%33 = load double*, double** %8
%34 = getelementptr inbounds double, double* %33, i64 0
%35 = load double, double* %34
%36 = fcmp olt double %32, %35
br i1 %36, label %37, label %45
37: ; preds = %29
%38 = load double*, double** %6
%39 = getelementptr inbounds double, double* %38, i64 1
%40 = load double, double* %39
%41 = load double*, double** %8
%42 = getelementptr inbounds double, double* %41, i64 1
%43 = load double, double* %42
%44 = fsub double %40, %43
store double %44, double* %10
br label %64
45: ; preds = %29
%46 = load double*, double** %6
%47 = getelementptr inbounds double, double* %46, i64 1
%48 = load double, double* %47
%49 = load double*, double** %8
%50 = getelementptr inbounds double, double* %49, i64 1
%51 = load double, double* %50
%52 = fcmp olt double %48, %51
br i1 %52, label %53, label %61
53: ; preds = %45
%54 = load double*, double** %6
%55 = getelementptr inbounds double, double* %54, i64 0
%56 = load double, double* %55
%57 = load double*, double** %8
%58 = getelementptr inbounds double, double* %57, i64 0
%59 = load double, double* %58
%60 = fsub double %56, %59
store double %60, double* %10
br label %63
61: ; preds = %45
%62 = call i32 @coco_error(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %5
br label %83
63: ; preds = %53
br label %64
64: ; preds = %63, %37
br label %65
65: ; preds = %64, %25
%66 = load double, double* %10
%67 = load double*, double** %8
%68 = getelementptr inbounds double, double* %67, i64 1
%69 = load double, double* %68
%70 = load double*, double** %7
%71 = getelementptr inbounds double, double* %70, i64 1
%72 = load double, double* %71
%73 = fsub double %69, %72
%74 = load double*, double** %8
%75 = getelementptr inbounds double, double* %74, i64 0
%76 = load double, double* %75
%77 = load double*, double** %7
%78 = getelementptr inbounds double, double* %77, i64 0
%79 = load double, double* %78
%80 = fsub double %76, %79
%81 = fmul double %73, %80
%82 = fdiv double %66, %81
store double %82, double* %5
br label %83
83: ; preds = %65, %61
%84 = load double, double* %5
ret double %84
}

LLVM IR (-O2):
@.str = [47 x i8] c"mo_get_distance_to_ROI(): unexpected exception\00"
define double @mo_get_distance_to_ROI(double* %0, double* %1, double* %2, i64 %3) {
%5 = icmp eq i64 %3, 2
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32 @mo_get_dominance(double* %1, double* %0, i32 2)
%9 = icmp eq i32 %8, 1
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i32 @mo_get_dominance(double* %0, double* %2, i32 2)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = tail call double @mo_get_norm(double* %0, double* %2, i32 2)
%16 = bitcast double* %2 to <2 x double>*
%17 = load <2 x double>, <2 x double>* %16
br label %36
18: ; preds = %4
%19 = load double, double* %0
%20 = bitcast double* %2 to <2 x double>*
%21 = load <2 x double>, <2 x double>* %20
%22 = extractelement <2 x double> %21, i64 0
%23 = fcmp olt double %19, %22
%24 = getelementptr inbounds double, double* %0, i64 1
%25 = load double, double* %24
br i1 %23, label %26, label %29
26: ; preds = %18
%27 = extractelement <2 x double> %21, i64 1
%28 = fsub double %25, %27
br label %36
29: ; preds = %18
%30 = extractelement <2 x double> %21, i64 1
%31 = fcmp olt double %25, %30
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = fsub double %19, %22
br label %36
34: ; preds = %29
%35 = tail call i32 @coco_error(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %46
36: ; preds = %26, %32, %14
%37 = phi double [ %15, %14 ], [ %28, %26 ], [ %33, %32 ]
%38 = phi <2 x double> [ %17, %14 ], [ %21, %26 ], [ %21, %32 ]
%39 = bitcast double* %1 to <2 x double>*
%40 = load <2 x double>, <2 x double>* %39
%41 = fsub <2 x double> %38, %40
%42 = shufflevector <2 x double> %41, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%43 = fmul <2 x double> %42, %41
%44 = extractelement <2 x double> %43, i64 0
%45 = fdiv double %37, %44
br label %46
46: ; preds = %36, %34
%47 = phi double [ %45, %36 ], [ 0.000000e+00, %34 ]
ret double %47
}