#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 reg_poly_is_left(double, double, double, double, double, double);
int reg_poly_winding_num(double *xpos, double *ypos, long nPoints, double x,
                         double y) {
  int wn = 0;
  long ii;
  double isLeft;
  for (ii = 0; ii < nPoints - 1; ii++) {
    isLeft =
        reg_poly_is_left(xpos[ii], ypos[ii], xpos[ii + 1], ypos[ii + 1], x, y);
    if (isLeft == 0) {
      if (((x <= xpos[ii] && x >= xpos[ii + 1]) ||
           (x <= xpos[ii + 1] && x >= xpos[ii])) &&
          ((y <= ypos[ii] && y >= ypos[ii + 1]) ||
           (y <= ypos[ii + 1] && y >= ypos[ii]))) {
        return 1;
      }
    }
    if (ypos[ii] <= y) {
      if (ypos[ii + 1] > y) {
        if (isLeft > 0) {
          wn++;
        }
      }
    } else {
      if (ypos[ii + 1] <= y) {
        if (isLeft < 0) {
          wn--;
        }
      }
    }
  }
  return wn;
}


x86 assembly (clang, -O0):
<reg_poly_winding_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jge    1347 <reg_poly_winding_num+0x237>
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm3
movsd  -0x28(%rbp),%xmm4
movsd  -0x30(%rbp),%xmm5
call   1030 <reg_poly_is_left@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1299 <reg_poly_winding_num+0x189>
jp     1299 <reg_poly_winding_num+0x189>
movsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     11e9 <reg_poly_winding_num+0xd9>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
ucomisd 0x8(%rax,%rcx,8),%xmm0
jae    121e <reg_poly_winding_num+0x10e>
movsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1294 <reg_poly_winding_num+0x184>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jb     1294 <reg_poly_winding_num+0x184>
movsd  -0x30(%rbp),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1253 <reg_poly_winding_num+0x143>
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
ucomisd 0x8(%rax,%rcx,8),%xmm0
jae    1288 <reg_poly_winding_num+0x178>
movsd  -0x30(%rbp),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1294 <reg_poly_winding_num+0x184>
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jb     1294 <reg_poly_winding_num+0x184>
movl   $0x1,-0x4(%rbp)
jmp    134d <reg_poly_winding_num+0x23d>
jmp    1299 <reg_poly_winding_num+0x189>
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     12f3 <reg_poly_winding_num+0x1e3>
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    12ee <reg_poly_winding_num+0x1de>
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12e9 <reg_poly_winding_num+0x1d9>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12ee <reg_poly_winding_num+0x1de>
jmp    1331 <reg_poly_winding_num+0x221>
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  0x8(%rax,%rcx,8),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     132c <reg_poly_winding_num+0x21c>
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1327 <reg_poly_winding_num+0x217>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    132c <reg_poly_winding_num+0x21c>
jmp    1331 <reg_poly_winding_num+0x221>
jmp    1336 <reg_poly_winding_num+0x226>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    113d <reg_poly_winding_num+0x2d>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reg_poly_winding_num>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
cmp    $0x2,%rdx
jl     123a <reg_poly_winding_num+0x12a>
movapd %xmm1,%xmm3
movapd %xmm0,%xmm4
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
movsd  (%rsi),%xmm1
xor    %ebp,%ebp
mov    $0x1,%ebx
movsd  %xmm3,0x8(%rsp)
movsd  %xmm0,(%rsp)
jmp    1186 <reg_poly_winding_num+0x76>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
ucomisd %xmm1,%xmm3
setae  %al
ucomisd %xmm0,%xmm5
seta   %cl
and    %al,%cl
movzbl %cl,%eax
neg    %eax
add    %eax,%ebp
add    $0x1,%rbx
mov    %ebp,%eax
cmp    %rbx,%r14
je     123a <reg_poly_winding_num+0x12a>
movsd  -0x8(%r15,%rbx,8),%xmm0
movsd  (%r15,%rbx,8),%xmm2
movsd  (%r12,%rbx,8),%xmm3
movsd  (%rsp),%xmm4
movsd  0x8(%rsp),%xmm5
call   1030 <reg_poly_is_left@plt>
xorpd  %xmm5,%xmm5
movsd  (%rsp),%xmm4
movsd  0x8(%rsp),%xmm3
ucomisd %xmm5,%xmm0
jne    120f <reg_poly_winding_num+0xff>
jp     120f <reg_poly_winding_num+0xff>
movsd  -0x8(%r15,%rbx,8),%xmm1
movsd  (%r15,%rbx,8),%xmm2
ucomisd %xmm4,%xmm1
jb     11d9 <reg_poly_winding_num+0xc9>
ucomisd %xmm2,%xmm4
jae    11e5 <reg_poly_winding_num+0xd5>
ucomisd %xmm4,%xmm2
jb     120f <reg_poly_winding_num+0xff>
ucomisd %xmm1,%xmm4
jb     120f <reg_poly_winding_num+0xff>
movsd  -0x8(%r12,%rbx,8),%xmm1
movsd  (%r12,%rbx,8),%xmm2
ucomisd %xmm3,%xmm1
mov    $0x1,%eax
jb     1203 <reg_poly_winding_num+0xf3>
ucomisd %xmm2,%xmm3
jae    123a <reg_poly_winding_num+0x12a>
ucomisd %xmm3,%xmm2
jb     120f <reg_poly_winding_num+0xff>
ucomisd %xmm1,%xmm3
jae    123a <reg_poly_winding_num+0x12a>
ucomisd -0x8(%r12,%rbx,8),%xmm3
movsd  (%r12,%rbx,8),%xmm1
jb     1160 <reg_poly_winding_num+0x50>
ucomisd %xmm3,%xmm1
seta   %al
ucomisd %xmm5,%xmm0
seta   %cl
and    %al,%cl
movzbl %cl,%eax
jmp    1175 <reg_poly_winding_num+0x65>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @reg_poly_winding_num(double* nocapture %0, double* nocapture %1, i64 %2, double %3, double %4) {
%6 = add i64 %2, -1
%7 = icmp sgt i64 %2, 1
br i1 %7, label %8, label %62
8: ; preds = %5
%9 = load double, double* %1
br label %10
10: ; preds = %8, %58
%11 = phi double [ %47, %58 ], [ %9, %8 ]
%12 = phi i64 [ %17, %58 ], [ 0, %8 ]
%13 = phi i32 [ %60, %58 ], [ 0, %8 ]
%14 = getelementptr inbounds double, double* %0, i64 %12
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %1, i64 %12
%17 = add nuw nsw i64 %12, 1
%18 = getelementptr inbounds double, double* %0, i64 %17
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %1, i64 %17
%21 = load double, double* %20
%22 = tail call double @reg_poly_is_left(double %15, double %11, double %19, double %21, double %3, double %4)
%23 = fcmp oeq double %22, 0.000000e+00
br i1 %23, label %24, label %44
24: ; preds = %10
%25 = load double, double* %14
%26 = fcmp ult double %25, %3
%27 = load double, double* %18
%28 = fcmp ugt double %27, %3
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = fcmp ult double %27, %3
%32 = fcmp ugt double %25, %3
%33 = select i1 %31, i1 true, i1 %32
br i1 %33, label %44, label %34
34: ; preds = %24, %30
%35 = load double, double* %16
%36 = fcmp ult double %35, %4
%37 = load double, double* %20
%38 = fcmp ugt double %37, %4
%39 = select i1 %36, i1 true, i1 %38
br i1 %39, label %40, label %62
40: ; preds = %34
%41 = fcmp ult double %37, %4
%42 = fcmp ugt double %35, %4
%43 = select i1 %41, i1 true, i1 %42
br i1 %43, label %44, label %62
44: ; preds = %30, %40, %10
%45 = load double, double* %16
%46 = fcmp ugt double %45, %4
%47 = load double, double* %20
br i1 %46, label %53, label %48
48: ; preds = %44
%49 = fcmp ogt double %47, %4
%50 = fcmp ogt double %22, 0.000000e+00
%51 = select i1 %49, i1 %50, i1 false
%52 = zext i1 %51 to i32
br label %58
53: ; preds = %44
%54 = fcmp ole double %47, %4
%55 = fcmp olt double %22, 0.000000e+00
%56 = select i1 %54, i1 %55, i1 false
%57 = sext i1 %56 to i32
br label %58
58: ; preds = %53, %48
%59 = phi i32 [ %52, %48 ], [ %57, %53 ]
%60 = add nsw i32 %59, %13
%61 = icmp eq i64 %17, %6
br i1 %61, label %62, label %10
62: ; preds = %58, %40, %34, %5
%63 = phi i32 [ 0, %5 ], [ 1, %40 ], [ %60, %58 ], [ 1, %34 ]
ret i32 %63
}