#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);
double sqrt(double);
double height(double *vertex, int v0, int v1, int v) {
  double x, y, x0, y0, x1, y1, s, r, c;
  x = vertex[2 * v + 0], y = vertex[2 * v + 1];
  x0 = vertex[2 * v0 + 0], y0 = vertex[2 * v0 + 1];
  x1 = vertex[2 * v1 + 0], y1 = vertex[2 * v1 + 1];
  c = ((x - x0) * (x1 - x0) + (y - y0) * (y1 - y0)) /
      ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
  if (c <= 0.0)
    return sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0));
  else if (c >= 1.0)
    return sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
  s = (x0 - x) * (y1 - y) - (y0 - y) * (x1 - x);
  r = sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
  return fabs(s) / r;
}


x86 assembly (clang, -O0):
<height>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
subsd  -0x38(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm3
subsd  -0x40(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x48(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm3
subsd  -0x38(%rbp),%xmm3
movsd  -0x50(%rbp),%xmm2
subsd  -0x40(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm4
subsd  -0x40(%rbp),%xmm4
mulsd  %xmm4,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x68(%rbp),%xmm0
jb     1283 <height+0x173>
movsd  -0x28(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
subsd  -0x38(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm3
subsd  -0x40(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    138a <height+0x27a>
movsd  -0x68(%rbp),%xmm0
movsd  0xd70(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     12dd <height+0x1cd>
movsd  -0x48(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
subsd  -0x28(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm3
subsd  -0x30(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    138a <height+0x27a>
jmp    12e2 <height+0x1d2>
movsd  -0x38(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
subsd  -0x30(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm3
subsd  -0x28(%rbp),%xmm3
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
subsd  -0x38(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm3
subsd  -0x40(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
movaps 0xc94(%rip),%xmm1
pand   %xmm1,%xmm0
divsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<height>:
sub    $0x18,%rsp
lea    (%rcx,%rcx,1),%eax
cltq
movsd  (%rdi,%rax,8),%xmm8
lea    0x1(%rcx,%rcx,1),%eax
cltq
movsd  (%rdi,%rax,8),%xmm9
lea    (%rsi,%rsi,1),%eax
cltq
movsd  (%rdi,%rax,8),%xmm6
lea    0x1(%rsi,%rsi,1),%eax
cltq
movsd  (%rdi,%rax,8),%xmm10
lea    (%rdx,%rdx,1),%eax
cltq
movsd  (%rdi,%rax,8),%xmm0
lea    0x1(%rdx,%rdx,1),%eax
cltq
movsd  (%rdi,%rax,8),%xmm5
movapd %xmm8,%xmm3
unpcklpd %xmm0,%xmm3
movapd %xmm6,%xmm1
unpcklpd %xmm6,%xmm1
subpd  %xmm1,%xmm3
movapd %xmm9,%xmm7
unpcklpd %xmm5,%xmm7
movapd %xmm10,%xmm1
unpcklpd %xmm10,%xmm1
subpd  %xmm1,%xmm7
movapd %xmm7,%xmm2
unpckhpd %xmm7,%xmm2
mulpd  %xmm7,%xmm2
movapd %xmm3,%xmm1
unpckhpd %xmm3,%xmm1
mulpd  %xmm3,%xmm1
addpd  %xmm2,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
divsd  %xmm2,%xmm1
xorpd  %xmm4,%xmm4
ucomisd %xmm1,%xmm4
jae    11f2 <height+0xe2>
ucomisd 0xe44(%rip),%xmm1
jae    120d <height+0xfd>
subsd  %xmm8,%xmm6
subsd  %xmm9,%xmm5
mulsd  %xmm6,%xmm5
subsd  %xmm9,%xmm10
subsd  %xmm8,%xmm0
mulsd  %xmm10,%xmm0
subsd  %xmm0,%xmm5
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jb     1243 <height+0x133>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
jmp    1256 <height+0x146>
mulsd  %xmm7,%xmm7
mulsd  %xmm3,%xmm3
addsd  %xmm7,%xmm3
ucomisd %xmm4,%xmm3
jb     1236 <height+0x126>
xorps  %xmm5,%xmm5
sqrtsd %xmm3,%xmm5
jmp    1262 <height+0x152>
subsd  %xmm8,%xmm0
subsd  %xmm9,%xmm5
mulsd  %xmm5,%xmm5
mulsd  %xmm0,%xmm0
addsd  %xmm5,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     126b <height+0x15b>
xorps  %xmm5,%xmm5
sqrtsd %xmm0,%xmm5
jmp    1262 <height+0x152>
movapd %xmm3,%xmm0
add    $0x18,%rsp
jmp    1030 <sqrt@plt>
movapd %xmm2,%xmm0
movapd %xmm5,(%rsp)
call   1030 <sqrt@plt>
movapd (%rsp),%xmm5
andpd  0xdb2(%rip),%xmm5
divsd  %xmm0,%xmm5
movapd %xmm5,%xmm0
add    $0x18,%rsp
ret
add    $0x18,%rsp
jmp    1030 <sqrt@plt>

LLVM IR (-O0):
define double @height(double* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca double
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
store double* %0, double** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%19 = load double*, double** %6
%20 = load i32, i32* %9
%21 = mul nsw i32 2, %20
%22 = add nsw i32 %21, 0
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %19, i64 %23
%25 = load double, double* %24
store double %25, double* %10
%26 = load double*, double** %6
%27 = load i32, i32* %9
%28 = mul nsw i32 2, %27
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %26, i64 %30
%32 = load double, double* %31
store double %32, double* %11
%33 = load double*, double** %6
%34 = load i32, i32* %7
%35 = mul nsw i32 2, %34
%36 = add nsw i32 %35, 0
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %33, i64 %37
%39 = load double, double* %38
store double %39, double* %12
%40 = load double*, double** %6
%41 = load i32, i32* %7
%42 = mul nsw i32 2, %41
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %40, i64 %44
%46 = load double, double* %45
store double %46, double* %13
%47 = load double*, double** %6
%48 = load i32, i32* %8
%49 = mul nsw i32 2, %48
%50 = add nsw i32 %49, 0
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %47, i64 %51
%53 = load double, double* %52
store double %53, double* %14
%54 = load double*, double** %6
%55 = load i32, i32* %8
%56 = mul nsw i32 2, %55
%57 = add nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %54, i64 %58
%60 = load double, double* %59
store double %60, double* %15
%61 = load double, double* %10
%62 = load double, double* %12
%63 = fsub double %61, %62
%64 = load double, double* %14
%65 = load double, double* %12
%66 = fsub double %64, %65
%67 = load double, double* %11
%68 = load double, double* %13
%69 = fsub double %67, %68
%70 = load double, double* %15
%71 = load double, double* %13
%72 = fsub double %70, %71
%73 = fmul double %69, %72
%74 = call double @llvm.fmuladd.f64(double %63, double %66, double %73)
%75 = load double, double* %14
%76 = load double, double* %12
%77 = fsub double %75, %76
%78 = load double, double* %14
%79 = load double, double* %12
%80 = fsub double %78, %79
%81 = load double, double* %15
%82 = load double, double* %13
%83 = fsub double %81, %82
%84 = load double, double* %15
%85 = load double, double* %13
%86 = fsub double %84, %85
%87 = fmul double %83, %86
%88 = call double @llvm.fmuladd.f64(double %77, double %80, double %87)
%89 = fdiv double %74, %88
store double %89, double* %18
%90 = load double, double* %18
%91 = fcmp ole double %90, 0.000000e+00
br i1 %91, label %92, label %108
92: ; preds = %4
%93 = load double, double* %10
%94 = load double, double* %12
%95 = fsub double %93, %94
%96 = load double, double* %10
%97 = load double, double* %12
%98 = fsub double %96, %97
%99 = load double, double* %11
%100 = load double, double* %13
%101 = fsub double %99, %100
%102 = load double, double* %11
%103 = load double, double* %13
%104 = fsub double %102, %103
%105 = fmul double %101, %104
%106 = call double @llvm.fmuladd.f64(double %95, double %98, double %105)
%107 = call double @sqrt(double %106)
store double %107, double* %5
br label %163
108: ; preds = %4
%109 = load double, double* %18
%110 = fcmp oge double %109, 1.000000e+00
br i1 %110, label %111, label %127
111: ; preds = %108
%112 = load double, double* %14
%113 = load double, double* %10
%114 = fsub double %112, %113
%115 = load double, double* %14
%116 = load double, double* %10
%117 = fsub double %115, %116
%118 = load double, double* %15
%119 = load double, double* %11
%120 = fsub double %118, %119
%121 = load double, double* %15
%122 = load double, double* %11
%123 = fsub double %121, %122
%124 = fmul double %120, %123
%125 = call double @llvm.fmuladd.f64(double %114, double %117, double %124)
%126 = call double @sqrt(double %125)
store double %126, double* %5
br label %163
127: ; preds = %108
br label %128
128: ; preds = %127
%129 = load double, double* %12
%130 = load double, double* %10
%131 = fsub double %129, %130
%132 = load double, double* %15
%133 = load double, double* %11
%134 = fsub double %132, %133
%135 = load double, double* %13
%136 = load double, double* %11
%137 = fsub double %135, %136
%138 = load double, double* %14
%139 = load double, double* %10
%140 = fsub double %138, %139
%141 = fmul double %137, %140
%142 = fneg double %141
%143 = call double @llvm.fmuladd.f64(double %131, double %134, double %142)
store double %143, double* %16
%144 = load double, double* %14
%145 = load double, double* %12
%146 = fsub double %144, %145
%147 = load double, double* %14
%148 = load double, double* %12
%149 = fsub double %147, %148
%150 = load double, double* %15
%151 = load double, double* %13
%152 = fsub double %150, %151
%153 = load double, double* %15
%154 = load double, double* %13
%155 = fsub double %153, %154
%156 = fmul double %152, %155
%157 = call double @llvm.fmuladd.f64(double %146, double %149, double %156)
%158 = call double @sqrt(double %157)
store double %158, double* %17
%159 = load double, double* %16
%160 = call double @llvm.fabs.f64(double %159)
%161 = load double, double* %17
%162 = fdiv double %160, %161
store double %162, double* %5
br label %163
163: ; preds = %128, %111, %92
%164 = load double, double* %5
ret double %164
}

LLVM IR (-O2):
define double @height(double* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = shl nsw i32 %3, 1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds double, double* %0, i64 %6
%8 = load double, double* %7
%9 = or i32 %5, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds double, double* %0, i64 %10
%12 = load double, double* %11
%13 = shl nsw i32 %1, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = load double, double* %15
%17 = or i32 %13, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %0, i64 %18
%20 = load double, double* %19
%21 = shl nsw i32 %2, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %0, i64 %22
%24 = load double, double* %23
%25 = or i32 %21, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %0, i64 %26
%28 = load double, double* %27
%29 = insertelement <2 x double> poison, double %8, i64 0
%30 = insertelement <2 x double> %29, double %24, i64 1
%31 = insertelement <2 x double> poison, double %16, i64 0
%32 = shufflevector <2 x double> %31, <2 x double> poison, <2 x i32> zeroinitializer
%33 = fsub <2 x double> %30, %32
%34 = insertelement <2 x double> poison, double %12, i64 0
%35 = insertelement <2 x double> %34, double %28, i64 1
%36 = insertelement <2 x double> poison, double %20, i64 0
%37 = shufflevector <2 x double> %36, <2 x double> poison, <2 x i32> zeroinitializer
%38 = fsub <2 x double> %35, %37
%39 = shufflevector <2 x double> %38, <2 x double> undef, <2 x i32> <i32 1, i32 1>
%40 = fmul <2 x double> %39, %38
%41 = shufflevector <2 x double> %33, <2 x double> undef, <2 x i32> <i32 1, i32 1>
%42 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %33, <2 x double> %41, <2 x double> %40)
%43 = extractelement <2 x double> %42, i64 0
%44 = extractelement <2 x double> %42, i64 1
%45 = fdiv double %43, %44
%46 = fcmp ugt double %45, 0.000000e+00
br i1 %46, label %53, label %47
47: ; preds = %4
%48 = fmul <2 x double> %38, %38
%49 = extractelement <2 x double> %48, i64 0
%50 = extractelement <2 x double> %33, i64 0
%51 = tail call double @llvm.fmuladd.f64(double %50, double %50, double %49)
%52 = tail call double @sqrt(double %51)
br label %72
53: ; preds = %4
%54 = fcmp ult double %45, 1.000000e+00
br i1 %54, label %61, label %55
55: ; preds = %53
%56 = fsub double %24, %8
%57 = fsub double %28, %12
%58 = fmul double %57, %57
%59 = tail call double @llvm.fmuladd.f64(double %56, double %56, double %58)
%60 = tail call double @sqrt(double %59)
br label %72
61: ; preds = %53
%62 = fsub double %16, %8
%63 = fsub double %28, %12
%64 = fsub double %20, %12
%65 = fsub double %24, %8
%66 = fneg double %64
%67 = fmul double %65, %66
%68 = tail call double @llvm.fmuladd.f64(double %62, double %63, double %67)
%69 = tail call double @sqrt(double %44)
%70 = tail call double @llvm.fabs.f64(double %68)
%71 = fdiv double %70, %69
br label %72
72: ; preds = %61, %55, %47
%73 = phi double [ %52, %47 ], [ %60, %55 ], [ %71, %61 ]
ret double %73
}