#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 LeftTurn(double const *, double const *, double const *);
scalar_t__ dsign(double);
scalar_t__ fabs(double);
int SegmentsIntersect(const double a[2], const double b[2], const double c[2],
                      const double d[2], double *x, double *t) {
  double c0, c1, c2, c3;
  c0 = LeftTurn(a, b, c);
  c1 = LeftTurn(a, b, d);
  if (0 == c0 && 0 == c1) {
    return 0;
  }
  if (dsign(c0) != dsign(c1)) {
    c2 = LeftTurn(c, d, a);
    c3 = LeftTurn(c, d, b);
    if (dsign(c2) != dsign(c3)) {
      if (NULL != x) {
        double r;
        c1 = c0 - c1;
        c3 = c2 - c3;
        if (fabs(c1) > fabs(c3)) {
          r = c0 / c1;
          x[0] = c[0] + r * (d[0] - c[0]);
          x[1] = c[1] + r * (d[1] - c[1]);
        } else {
          r = c2 / c3;
          x[0] = a[0] + r * (b[0] - a[0]);
          x[1] = a[1] + r * (b[1] - a[1]);
        }
        if (NULL != t) {
          *t = r;
        }
      }
      return 1;
    } else {
      return 0;
    }
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<SegmentsIntersect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <LeftTurn@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <LeftTurn@plt>
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jne    11b3 <SegmentsIntersect+0x83>
jp     11b3 <SegmentsIntersect+0x83>
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jne    11b3 <SegmentsIntersect+0x83>
jp     11b3 <SegmentsIntersect+0x83>
movl   $0x0,-0x4(%rbp)
jmp    139d <SegmentsIntersect+0x26d>
movsd  -0x40(%rbp),%xmm0
call   1050 <dsign@plt>
mov    %rax,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1050 <dsign@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
cmp    %rcx,%rax
je     1396 <SegmentsIntersect+0x266>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <LeftTurn@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <LeftTurn@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
call   1050 <dsign@plt>
mov    %rax,-0x70(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1050 <dsign@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
cmp    %rcx,%rax
je     138a <SegmentsIntersect+0x25a>
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
je     137e <SegmentsIntersect+0x24e>
movsd  -0x40(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x78(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
cmp    %rcx,%rax
jle    12f3 <SegmentsIntersect+0x1c3>
movsd  -0x40(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x60(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x20(%rbp),%rax
subsd  (%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  -0x60(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x20(%rbp),%rax
subsd  0x8(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,0x8(%rax)
jmp    1360 <SegmentsIntersect+0x230>
movsd  -0x50(%rbp),%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x60(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  -0x60(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x10(%rbp),%rax
subsd  0x8(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,0x8(%rax)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
je     1379 <SegmentsIntersect+0x249>
movsd  -0x60(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    137e <SegmentsIntersect+0x24e>
movl   $0x1,-0x4(%rbp)
jmp    139d <SegmentsIntersect+0x26d>
movl   $0x0,-0x4(%rbp)
jmp    139d <SegmentsIntersect+0x26d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SegmentsIntersect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r15
mov    %r8,%rbp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r14
call   1040 <LeftTurn@plt>
movsd  %xmm0,0x20(%rsp)
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <LeftTurn@plt>
movsd  0x20(%rsp),%xmm1
movapd %xmm0,%xmm2
xor    %eax,%eax
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    118d <SegmentsIntersect+0x5d>
jp     118d <SegmentsIntersect+0x5d>
ucomisd %xmm0,%xmm2
jne    118d <SegmentsIntersect+0x5d>
jnp    1311 <SegmentsIntersect+0x1e1>
mov    %rbx,0x30(%rsp)
mov    %r15,0x28(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1050 <dsign@plt>
mov    %rax,%r15
movsd  0x8(%rsp),%xmm0
call   1050 <dsign@plt>
cmp    %rax,%r15
jne    11c0 <SegmentsIntersect+0x90>
xor    %eax,%eax
jmp    1311 <SegmentsIntersect+0x1e1>
mov    %r12,%rdi
mov    0x30(%rsp),%rbx
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <LeftTurn@plt>
movsd  %xmm0,0x18(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1040 <LeftTurn@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <dsign@plt>
mov    %rax,%r15
movsd  0x10(%rsp),%xmm0
call   1050 <dsign@plt>
cmp    %rax,%r15
mov    $0x0,%eax
je     1311 <SegmentsIntersect+0x1e1>
mov    $0x1,%eax
mov    %rbp,%rcx
test   %rbp,%rbp
je     1311 <SegmentsIntersect+0x1e1>
movsd  0x20(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
subsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <fabs@plt>
mov    %rax,%r15
movsd  0x8(%rsp),%xmm0
call   1030 <fabs@plt>
cmp    %rax,%r15
jle    12b5 <SegmentsIntersect+0x185>
movsd  0x20(%rsp),%xmm2
divsd  0x10(%rsp),%xmm2
movsd  (%r12),%xmm0
mov    0x30(%rsp),%rax
movsd  (%rax),%xmm1
subsd  %xmm0,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%rbp)
movsd  0x8(%r12),%xmm1
movsd  0x8(%rax),%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    0x28(%rsp),%rbx
mov    $0x1,%eax
movapd %xmm2,%xmm1
jmp    1303 <SegmentsIntersect+0x1d3>
movsd  0x18(%rsp),%xmm2
divsd  0x8(%rsp),%xmm2
movsd  (%r14),%xmm0
movsd  0x0(%r13),%xmm1
subsd  %xmm0,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%rbp)
movsd  0x8(%r14),%xmm1
movsd  0x8(%r13),%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movapd %xmm2,%xmm1
mov    0x28(%rsp),%rbx
mov    $0x1,%eax
movsd  %xmm0,0x8(%rbp)
test   %rbx,%rbx
je     1311 <SegmentsIntersect+0x1e1>
movsd  %xmm1,(%rbx)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @SegmentsIntersect(double* %0, double* %1, double* %2, double* %3, double* %4, double* %5) {
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%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** %8
store double* %1, double** %9
store double* %2, double** %10
store double* %3, double** %11
store double* %4, double** %12
store double* %5, double** %13
%19 = load double*, double** %8
%20 = load double*, double** %9
%21 = load double*, double** %10
%22 = call double @LeftTurn(double* %19, double* %20, double* %21)
store double %22, double* %14
%23 = load double*, double** %8
%24 = load double*, double** %9
%25 = load double*, double** %11
%26 = call double @LeftTurn(double* %23, double* %24, double* %25)
store double %26, double* %15
%27 = load double, double* %14
%28 = fcmp oeq double 0.000000e+00, %27
br i1 %28, label %29, label %33
29: ; preds = %6
%30 = load double, double* %15
%31 = fcmp oeq double 0.000000e+00, %30
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 0, i32* %7
br label %142
33: ; preds = %29, %6
%34 = load double, double* %14
%35 = call i64 @dsign(double %34)
%36 = load double, double* %15
%37 = call i64 @dsign(double %36)
%38 = icmp ne i64 %35, %37
br i1 %38, label %39, label %141
39: ; preds = %33
%40 = load double*, double** %10
%41 = load double*, double** %11
%42 = load double*, double** %8
%43 = call double @LeftTurn(double* %40, double* %41, double* %42)
store double %43, double* %16
%44 = load double*, double** %10
%45 = load double*, double** %11
%46 = load double*, double** %9
%47 = call double @LeftTurn(double* %44, double* %45, double* %46)
store double %47, double* %17
%48 = load double, double* %16
%49 = call i64 @dsign(double %48)
%50 = load double, double* %17
%51 = call i64 @dsign(double %50)
%52 = icmp ne i64 %49, %51
br i1 %52, label %53, label %140
53: ; preds = %39
%54 = load double*, double** %12
%55 = icmp ne double* null, %54
br i1 %55, label %56, label %139
56: ; preds = %53
%57 = load double, double* %14
%58 = load double, double* %15
%59 = fsub double %57, %58
store double %59, double* %15
%60 = load double, double* %16
%61 = load double, double* %17
%62 = fsub double %60, %61
store double %62, double* %17
%63 = load double, double* %15
%64 = call i64 @fabs(double %63)
%65 = load double, double* %17
%66 = call i64 @fabs(double %65)
%67 = icmp sgt i64 %64, %66
br i1 %67, label %68, label %100
68: ; preds = %56
%69 = load double, double* %14
%70 = load double, double* %15
%71 = fdiv double %69, %70
store double %71, double* %18
%72 = load double*, double** %10
%73 = getelementptr inbounds double, double* %72, i64 0
%74 = load double, double* %73
%75 = load double, double* %18
%76 = load double*, double** %11
%77 = getelementptr inbounds double, double* %76, i64 0
%78 = load double, double* %77
%79 = load double*, double** %10
%80 = getelementptr inbounds double, double* %79, i64 0
%81 = load double, double* %80
%82 = fsub double %78, %81
%83 = call double @llvm.fmuladd.f64(double %75, double %82, double %74)
%84 = load double*, double** %12
%85 = getelementptr inbounds double, double* %84, i64 0
store double %83, double* %85
%86 = load double*, double** %10
%87 = getelementptr inbounds double, double* %86, i64 1
%88 = load double, double* %87
%89 = load double, double* %18
%90 = load double*, double** %11
%91 = getelementptr inbounds double, double* %90, i64 1
%92 = load double, double* %91
%93 = load double*, double** %10
%94 = getelementptr inbounds double, double* %93, i64 1
%95 = load double, double* %94
%96 = fsub double %92, %95
%97 = call double @llvm.fmuladd.f64(double %89, double %96, double %88)
%98 = load double*, double** %12
%99 = getelementptr inbounds double, double* %98, i64 1
store double %97, double* %99
br label %132
100: ; preds = %56
%101 = load double, double* %16
%102 = load double, double* %17
%103 = fdiv double %101, %102
store double %103, double* %18
%104 = load double*, double** %8
%105 = getelementptr inbounds double, double* %104, i64 0
%106 = load double, double* %105
%107 = load double, double* %18
%108 = load double*, double** %9
%109 = getelementptr inbounds double, double* %108, i64 0
%110 = load double, double* %109
%111 = load double*, double** %8
%112 = getelementptr inbounds double, double* %111, i64 0
%113 = load double, double* %112
%114 = fsub double %110, %113
%115 = call double @llvm.fmuladd.f64(double %107, double %114, double %106)
%116 = load double*, double** %12
%117 = getelementptr inbounds double, double* %116, i64 0
store double %115, double* %117
%118 = load double*, double** %8
%119 = getelementptr inbounds double, double* %118, i64 1
%120 = load double, double* %119
%121 = load double, double* %18
%122 = load double*, double** %9
%123 = getelementptr inbounds double, double* %122, i64 1
%124 = load double, double* %123
%125 = load double*, double** %8
%126 = getelementptr inbounds double, double* %125, i64 1
%127 = load double, double* %126
%128 = fsub double %124, %127
%129 = call double @llvm.fmuladd.f64(double %121, double %128, double %120)
%130 = load double*, double** %12
%131 = getelementptr inbounds double, double* %130, i64 1
store double %129, double* %131
br label %132
132: ; preds = %100, %68
%133 = load double*, double** %13
%134 = icmp ne double* null, %133
br i1 %134, label %135, label %138
135: ; preds = %132
%136 = load double, double* %18
%137 = load double*, double** %13
store double %136, double* %137
br label %138
138: ; preds = %135, %132
br label %139
139: ; preds = %138, %53
store i32 1, i32* %7
br label %142
140: ; preds = %39
store i32 0, i32* %7
br label %142
141: ; preds = %33
store i32 0, i32* %7
br label %142
142: ; preds = %141, %140, %139, %32
%143 = load i32, i32* %7
ret i32 %143
}

LLVM IR (-O2):
define i32 @SegmentsIntersect(double* %0, double* %1, double* %2, double* %3, double* writeonly %4, double* writeonly %5) {
%7 = tail call double @LeftTurn(double* %0, double* %1, double* %2)
%8 = tail call double @LeftTurn(double* %0, double* %1, double* %3)
%9 = fcmp oeq double %7, 0.000000e+00
%10 = fcmp oeq double %8, 0.000000e+00
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %60, label %12
12: ; preds = %6
%13 = tail call i64 @dsign(double %7)
%14 = tail call i64 @dsign(double %8)
%15 = icmp eq i64 %13, %14
br i1 %15, label %60, label %16
16: ; preds = %12
%17 = tail call double @LeftTurn(double* %2, double* %3, double* %0)
%18 = tail call double @LeftTurn(double* %2, double* %3, double* %1)
%19 = tail call i64 @dsign(double %17)
%20 = tail call i64 @dsign(double %18)
%21 = icmp eq i64 %19, %20
br i1 %21, label %60, label %22
22: ; preds = %16
%23 = icmp eq double* %4, null
br i1 %23, label %60, label %24
24: ; preds = %22
%25 = fsub double %7, %8
%26 = fsub double %17, %18
%27 = tail call i64 @fabs(double %25)
%28 = tail call i64 @fabs(double %26)
%29 = icmp sgt i64 %27, %28
br i1 %29, label %30, label %42
30: ; preds = %24
%31 = fdiv double %7, %25
%32 = load double, double* %2
%33 = load double, double* %3
%34 = fsub double %33, %32
%35 = tail call double @llvm.fmuladd.f64(double %31, double %34, double %32)
store double %35, double* %4
%36 = getelementptr inbounds double, double* %2, i64 1
%37 = load double, double* %36
%38 = getelementptr inbounds double, double* %3, i64 1
%39 = load double, double* %38
%40 = fsub double %39, %37
%41 = tail call double @llvm.fmuladd.f64(double %31, double %40, double %37)
br label %54
42: ; preds = %24
%43 = fdiv double %17, %26
%44 = load double, double* %0
%45 = load double, double* %1
%46 = fsub double %45, %44
%47 = tail call double @llvm.fmuladd.f64(double %43, double %46, double %44)
store double %47, double* %4
%48 = getelementptr inbounds double, double* %0, i64 1
%49 = load double, double* %48
%50 = getelementptr inbounds double, double* %1, i64 1
%51 = load double, double* %50
%52 = fsub double %51, %49
%53 = tail call double @llvm.fmuladd.f64(double %43, double %52, double %49)
br label %54
54: ; preds = %42, %30
%55 = phi double [ %41, %30 ], [ %53, %42 ]
%56 = phi double [ %31, %30 ], [ %43, %42 ]
%57 = getelementptr inbounds double, double* %4, i64 1
store double %55, double* %57
%58 = icmp eq double* %5, null
br i1 %58, label %60, label %59
59: ; preds = %54
store double %56, double* %5
br label %60
60: ; preds = %12, %16, %22, %59, %54, %6
%61 = phi i32 [ 0, %6 ], [ 1, %54 ], [ 1, %59 ], [ 1, %22 ], [ 0, %16 ], [ 0, %12 ]
ret i32 %61
}