#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 cross(int *, int *, int *);
double dabs(double);
double distance(int *, int *);
int dot(int *, int *, int *);
double linePointDist(int A[2], int B[2], int C[2], int isSegment) {
  double dist = cross(A, B, C) / distance(A, B);
  if (isSegment) {
    int dot1 = dot(A, B, C);
    if (dot1 > 0)
      return distance(B, C);
    int dot2 = dot(B, A, C);
    if (dot2 > 0)
      return distance(A, C);
  }
  return dabs(dist);
}


x86 assembly (clang, -O0):
<linePointDist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <cross@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <distance@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1204 <linePointDist+0xc4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dot@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    11ca <linePointDist+0x8a>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <distance@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1213 <linePointDist+0xd3>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dot@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jle    11ff <linePointDist+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <distance@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1213 <linePointDist+0xd3>
jmp    1204 <linePointDist+0xc4>
movsd  -0x30(%rbp),%xmm0
call   1040 <dabs@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linePointDist>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
call   1050 <cross@plt>
movsd  %xmm0,0x10(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <distance@plt>
movapd %xmm0,%xmm1
test   %ebp,%ebp
je     11b8 <linePointDist+0x78>
movsd  %xmm1,0x8(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <dot@plt>
mov    %rbx,%rdi
test   %eax,%eax
jg     11a6 <linePointDist+0x66>
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <dot@plt>
test   %eax,%eax
movsd  0x8(%rsp),%xmm1
jle    11b8 <linePointDist+0x78>
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <distance@plt>
movsd  0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <dabs@plt>

LLVM IR (-O0):
define double @linePointDist(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca double
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%13 = load i32*, i32** %6
%14 = load i32*, i32** %7
%15 = load i32*, i32** %8
%16 = call double @cross(i32* %13, i32* %14, i32* %15)
%17 = load i32*, i32** %6
%18 = load i32*, i32** %7
%19 = call double @distance(i32* %17, i32* %18)
%20 = fdiv double %16, %19
store double %20, double* %10
%21 = load i32, i32* %9
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %46
23: ; preds = %4
%24 = load i32*, i32** %6
%25 = load i32*, i32** %7
%26 = load i32*, i32** %8
%27 = call i32 @dot(i32* %24, i32* %25, i32* %26)
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %23
%31 = load i32*, i32** %7
%32 = load i32*, i32** %8
%33 = call double @distance(i32* %31, i32* %32)
store double %33, double* %5
br label %49
34: ; preds = %23
%35 = load i32*, i32** %7
%36 = load i32*, i32** %6
%37 = load i32*, i32** %8
%38 = call i32 @dot(i32* %35, i32* %36, i32* %37)
store i32 %38, i32* %12
%39 = load i32, i32* %12
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %34
%42 = load i32*, i32** %6
%43 = load i32*, i32** %8
%44 = call double @distance(i32* %42, i32* %43)
store double %44, double* %5
br label %49
45: ; preds = %34
br label %46
46: ; preds = %45, %4
%47 = load double, double* %10
%48 = call double @dabs(double %47)
store double %48, double* %5
br label %49
49: ; preds = %46, %41, %30
%50 = load double, double* %5
ret double %50
}

LLVM IR (-O2):
define double @linePointDist(i32* %0, i32* %1, i32* %2, i32 %3) {
%5 = tail call double @cross(i32* %0, i32* %1, i32* %2)
%6 = tail call double @distance(i32* %0, i32* %1)
%7 = fdiv double %5, %6
%8 = icmp eq i32 %3, 0
br i1 %8, label %19, label %9
9: ; preds = %4
%10 = tail call i32 @dot(i32* %0, i32* %1, i32* %2)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call double @distance(i32* %1, i32* %2)
br label %21
14: ; preds = %9
%15 = tail call i32 @dot(i32* %1, i32* %0, i32* %2)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call double @distance(i32* %0, i32* %2)
br label %21
19: ; preds = %14, %4
%20 = tail call double @dabs(double %7)
br label %21
21: ; preds = %17, %12, %19
%22 = phi double [ %20, %19 ], [ %18, %17 ], [ %13, %12 ]
ret double %22
}