#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__ double_equal(double, double);
int /*<<< orphan*/ error(char *);
double inter_hi(double x, double x1, double y1, double x2, double y2) {
  if (x1 > x2 || x < x1 || x > x2)
    error("inter_hi: unsuitable input, 'x1>x2' or 'x<x1' or 'x>x2'.");
  if (double_equal(x1, x2) && y1 < y2)
    return y2;
  if (double_equal(x1, x2) && y1 > y2)
    return y1;
  return y1 + (x - x1) * (y2 - y1) / (x2 - x1);
}


x86 assembly (clang, -O0):
<inter_hi>:
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  %xmm4,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
ja     1175 <inter_hi+0x55>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1175 <inter_hi+0x55>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1181 <inter_hi+0x61>
lea    0xe84(%rip),%rdi
call   1040 <error@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <double_equal@plt>
cmp    $0x0,%rax
je     11bd <inter_hi+0x9d>
movsd  -0x20(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11bd <inter_hi+0x9d>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1229 <inter_hi+0x109>
movsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1030 <double_equal@plt>
cmp    $0x0,%rax
je     11f5 <inter_hi+0xd5>
movsd  -0x20(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    11f5 <inter_hi+0xd5>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1229 <inter_hi+0x109>
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
subsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  -0x28(%rbp),%xmm2
subsd  -0x18(%rbp),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inter_hi>:
sub    $0x28,%rsp
movsd  %xmm4,0x20(%rsp)
movsd  %xmm2,(%rsp)
movsd  %xmm0,0x18(%rsp)
ucomisd %xmm3,%xmm0
movsd  %xmm3,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
ja     1155 <inter_hi+0x35>
ucomisd 0x18(%rsp),%xmm1
ja     1155 <inter_hi+0x35>
ucomisd %xmm3,%xmm1
jbe    116d <inter_hi+0x4d>
lea    0xea4(%rip),%rdi
call   1040 <error@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm3
movapd %xmm1,%xmm0
movapd %xmm3,%xmm1
call   1030 <double_equal@plt>
movsd  0x20(%rsp),%xmm0
ucomisd (%rsp),%xmm0
jbe    1191 <inter_hi+0x71>
test   %rax,%rax
je     1191 <inter_hi+0x71>
add    $0x28,%rsp
ret
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1030 <double_equal@plt>
movsd  0x20(%rsp),%xmm0
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    11c2 <inter_hi+0xa2>
test   %rax,%rax
je     11c2 <inter_hi+0xa2>
movsd  (%rsp),%xmm0
add    $0x28,%rsp
ret
movsd  0x8(%rsp),%xmm3
movsd  0x18(%rsp),%xmm2
subsd  %xmm3,%xmm2
movsd  (%rsp),%xmm1
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
movsd  0x10(%rsp),%xmm2
subsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [57 x i8] c"inter_hi: unsuitable input, 'x1>x2' or 'x<x1' or 'x>x2'.\00"
define double @inter_hi(double %0, double %1, double %2, double %3, double %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
%12 = load double, double* %8
%13 = load double, double* %10
%14 = fcmp ogt double %12, %13
br i1 %14, label %23, label %15
15: ; preds = %5
%16 = load double, double* %7
%17 = load double, double* %8
%18 = fcmp olt double %16, %17
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load double, double* %7
%21 = load double, double* %10
%22 = fcmp ogt double %20, %21
br i1 %22, label %23, label %25
23: ; preds = %19, %15, %5
%24 = call i32 @error(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = load double, double* %8
%27 = load double, double* %10
%28 = call i64 @double_equal(double %26, double %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load double, double* %9
%32 = load double, double* %11
%33 = fcmp olt double %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = load double, double* %11
store double %35, double* %6
br label %61
36: ; preds = %30, %25
%37 = load double, double* %8
%38 = load double, double* %10
%39 = call i64 @double_equal(double %37, double %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %36
%42 = load double, double* %9
%43 = load double, double* %11
%44 = fcmp ogt double %42, %43
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = load double, double* %9
store double %46, double* %6
br label %61
47: ; preds = %41, %36
%48 = load double, double* %9
%49 = load double, double* %7
%50 = load double, double* %8
%51 = fsub double %49, %50
%52 = load double, double* %11
%53 = load double, double* %9
%54 = fsub double %52, %53
%55 = fmul double %51, %54
%56 = load double, double* %10
%57 = load double, double* %8
%58 = fsub double %56, %57
%59 = fdiv double %55, %58
%60 = fadd double %48, %59
store double %60, double* %6
br label %61
61: ; preds = %47, %45, %34
%62 = load double, double* %6
ret double %62
}

LLVM IR (-O2):
@.str = [57 x i8] c"inter_hi: unsuitable input, 'x1>x2' or 'x<x1' or 'x>x2'.\00"
define double @inter_hi(double %0, double %1, double %2, double %3, double %4) {
%6 = fcmp ogt double %1, %3
%7 = fcmp olt double %0, %1
%8 = or i1 %7, %6
%9 = fcmp ogt double %0, %3
%10 = or i1 %9, %8
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 @error(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %5, %11
%14 = tail call i64 @double_equal(double %1, double %3)
%15 = icmp ne i64 %14, 0
%16 = fcmp olt double %2, %4
%17 = and i1 %16, %15
br i1 %17, label %30, label %18
18: ; preds = %13
%19 = tail call i64 @double_equal(double %1, double %3)
%20 = icmp ne i64 %19, 0
%21 = fcmp ogt double %2, %4
%22 = and i1 %21, %20
br i1 %22, label %30, label %23
23: ; preds = %18
%24 = fsub double %0, %1
%25 = fsub double %4, %2
%26 = fmul double %24, %25
%27 = fsub double %3, %1
%28 = fdiv double %26, %27
%29 = fadd double %28, %2
br label %30
30: ; preds = %18, %13, %23
%31 = phi double [ %29, %23 ], [ %4, %13 ], [ %2, %18 ]
ret double %31
}