#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__ isfinite(double);
double nan(char *);
int intersection_2d(double *out, double *L1, double *L2) {
  if (L1[2] < 1e100 && L1[2] > -1e100 && L2[2] < 1e100 && L2[2] > -1e100) {
    double delta_y;
    double delta_x;
    double delta_s;
    delta_s = L1[2] - L2[2];
    if (!delta_s) {
      out[1] = out[0] = (nan("NAN"));
      return 1;
    }
    delta_y = L2[1] + L2[2] * (L1[0] - L2[0]) - L1[1];
    delta_x = delta_y / delta_s;
    out[0] = L1[0] + delta_x;
    out[1] = L1[1] + delta_x * L1[2];
    return 0;
  } else if (isfinite(L1[2])) {
    out[0] = L2[0];
    out[1] = L1[1] + (L2[0] - L1[0]) * L1[2];
    return 0;
  } else if (isfinite(L2[2])) {
    out[0] = L1[0];
    out[1] = L2[1] + (L1[0] - L2[0]) * L2[2];
    return 0;
  }
  out[1] = out[0] = (nan("NAN"));
  return 1;
}


x86 assembly (clang, -O0):
<intersection_2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsd  0xec0(%rip),%xmm0
ucomisd 0x10(%rax),%xmm0
jbe    1280 <intersection_2d+0x160>
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  0xeac(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1280 <intersection_2d+0x160>
mov    -0x20(%rbp),%rax
movsd  0xe8e(%rip),%xmm0
ucomisd 0x10(%rax),%xmm0
jbe    1280 <intersection_2d+0x160>
mov    -0x20(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  0xe7a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1280 <intersection_2d+0x160>
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x20(%rbp),%rax
subsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11f0 <intersection_2d+0xd0>
jp     11f0 <intersection_2d+0xd0>
lea    0xe42(%rip),%rdi
call   1030 <nan@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movl   $0x1,-0x4(%rbp)
jmp    137c <intersection_2d+0x25c>
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x20(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x20(%rbp),%rax
subsd  (%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
addsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movl   $0x0,-0x4(%rbp)
jmp    137c <intersection_2d+0x25c>
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
call   1040 <isfinite@plt>
cmp    $0x0,%rax
je     12e7 <intersection_2d+0x1c7>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movl   $0x0,-0x4(%rbp)
jmp    137c <intersection_2d+0x25c>
mov    -0x20(%rbp),%rax
movsd  0x10(%rax),%xmm0
call   1040 <isfinite@plt>
cmp    $0x0,%rax
je     134e <intersection_2d+0x22e>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
subsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movl   $0x0,-0x4(%rbp)
jmp    137c <intersection_2d+0x25c>
jmp    1353 <intersection_2d+0x233>
jmp    1358 <intersection_2d+0x238>
lea    0xcb1(%rip),%rdi
call   1030 <nan@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intersection_2d>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
movsd  0x10(%rsi),%xmm1
movsd  0xec5(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    11a0 <intersection_2d+0x80>
ucomisd 0xebf(%rip),%xmm1
jbe    11a0 <intersection_2d+0x80>
movsd  0x10(%r15),%xmm0
ucomisd %xmm0,%xmm2
jbe    11a0 <intersection_2d+0x80>
ucomisd 0xea9(%rip),%xmm0
jbe    11a0 <intersection_2d+0x80>
subsd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    1175 <intersection_2d+0x55>
jnp    1201 <intersection_2d+0xe1>
movsd  (%rbx),%xmm2
movapd %xmm2,%xmm3
subsd  (%r15),%xmm3
mulsd  %xmm3,%xmm0
addsd  0x8(%r15),%xmm0
subsd  0x8(%rbx),%xmm0
divsd  %xmm1,%xmm0
addsd  %xmm0,%xmm2
movsd  %xmm2,(%r14)
jmp    11c1 <intersection_2d+0xa1>
movapd %xmm1,%xmm0
call   1040 <isfinite@plt>
test   %rax,%rax
je     11cf <intersection_2d+0xaf>
movsd  (%r15),%xmm0
movsd  %xmm0,(%r14)
movsd  (%r15),%xmm0
subsd  (%rbx),%xmm0
mulsd  0x10(%rbx),%xmm0
addsd  0x8(%rbx),%xmm0
xor    %eax,%eax
jmp    1217 <intersection_2d+0xf7>
movsd  0x10(%r15),%xmm0
call   1040 <isfinite@plt>
test   %rax,%rax
je     1201 <intersection_2d+0xe1>
movsd  (%rbx),%xmm0
movsd  %xmm0,(%r14)
movsd  (%rbx),%xmm0
subsd  (%r15),%xmm0
mulsd  0x10(%r15),%xmm0
addsd  0x8(%r15),%xmm0
xor    %eax,%eax
jmp    1217 <intersection_2d+0xf7>
lea    0xe08(%rip),%rdi
call   1030 <nan@plt>
movsd  %xmm0,(%r14)
mov    $0x1,%eax
movsd  %xmm0,0x8(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"NAN\00"
define i32 @intersection_2d(double* nocapture writeonly %0, double* nocapture %1, double* nocapture %2) {
%4 = getelementptr inbounds double, double* %1, i64 2
%5 = load double, double* %4
%6 = fcmp olt double %5, 1.000000e+100
%7 = fcmp ogt double %5, -1.000000e+100
%8 = and i1 %6, %7
br i1 %8, label %9, label %35
9: ; preds = %3
%10 = getelementptr inbounds double, double* %2, i64 2
%11 = load double, double* %10
%12 = fcmp olt double %11, 1.000000e+100
%13 = fcmp ogt double %11, -1.000000e+100
%14 = and i1 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %9
%16 = fsub double %5, %11
%17 = fcmp une double %16, 0.000000e+00
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call double @nan(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store double %19, double* %0
br label %63
20: ; preds = %15
%21 = getelementptr inbounds double, double* %2, i64 1
%22 = load double, double* %21
%23 = load double, double* %1
%24 = load double, double* %2
%25 = fsub double %23, %24
%26 = tail call double @llvm.fmuladd.f64(double %11, double %25, double %22)
%27 = getelementptr inbounds double, double* %1, i64 1
%28 = load double, double* %27
%29 = fsub double %26, %28
%30 = fdiv double %29, %16
%31 = fadd double %23, %30
store double %31, double* %0
%32 = load double, double* %27
%33 = load double, double* %4
%34 = tail call double @llvm.fmuladd.f64(double %30, double %33, double %32)
br label %63
35: ; preds = %9, %3
%36 = tail call i64 @isfinite(double %5)
%37 = icmp eq i64 %36, 0
br i1 %37, label %47, label %38
38: ; preds = %35
%39 = load double, double* %2
store double %39, double* %0
%40 = getelementptr inbounds double, double* %1, i64 1
%41 = load double, double* %40
%42 = load double, double* %2
%43 = load double, double* %1
%44 = fsub double %42, %43
%45 = load double, double* %4
%46 = tail call double @llvm.fmuladd.f64(double %44, double %45, double %41)
br label %63
47: ; preds = %35
%48 = getelementptr inbounds double, double* %2, i64 2
%49 = load double, double* %48
%50 = tail call i64 @isfinite(double %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %61, label %52
52: ; preds = %47
%53 = load double, double* %1
store double %53, double* %0
%54 = getelementptr inbounds double, double* %2, i64 1
%55 = load double, double* %54
%56 = load double, double* %1
%57 = load double, double* %2
%58 = fsub double %56, %57
%59 = load double, double* %48
%60 = tail call double @llvm.fmuladd.f64(double %58, double %59, double %55)
br label %63
61: ; preds = %47
%62 = tail call double @nan(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store double %62, double* %0
br label %63
63: ; preds = %18, %20, %61, %52, %38
%64 = phi double [ %19, %18 ], [ %34, %20 ], [ %62, %61 ], [ %60, %52 ], [ %46, %38 ]
%65 = phi i32 [ 1, %18 ], [ 0, %20 ], [ 1, %61 ], [ 0, %52 ], [ 0, %38 ]
%66 = getelementptr inbounds double, double* %0, i64 1
store double %64, double* %66
ret i32 %65
}