#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ file_readline(int /*<<< orphan*/ *, char *, int);
scalar_t__ fillPolygon(int, int *, int *, unsigned char *, int, int);
int getFloat(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, int, int);
char *nextWord(char *);
int /*<<< orphan*/ strStrip(char *, char *);
scalar_t__ strlen(char *);
void fillPolygonsFromFile(FILE *infile, unsigned char *mask, int width,
                          int height) {
  char line[4096];
  int polyCorners = 0, polyX[1024], polyY[1024];
  int stopping = 0, filledPixels = 0;
  memset(mask, 0, width * height);
  while (!stopping) {
    if (feof(infile)) {
      stopping = 1;
      goto blankLine;
    }
    file_readline(infile, line, 32768);
    strStrip(line, line);
    if (strlen(line) == 0)
      goto blankLine;
    if (line[0] == '#')
      continue;
    char *cp = line;
    polyX[polyCorners] = getFloat(cp, NULL);
    cp = nextWord(cp);
    polyY[polyCorners] = getFloat(cp, NULL);
    polyCorners++;
    continue;
  blankLine:
    if (polyCorners > 2) {
      filledPixels +=
          fillPolygon(polyCorners, polyX, polyY, mask, width, height);
      polyCorners = 0;
    }
  }
  if (filledPixels < 1)
    memset(mask, 1, width * height);
  return;
}


x86 assembly (clang, -O0):
<fillPolygonsFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1024(%rbp)
movl   $0x0,-0x3034(%rbp)
movl   $0x0,-0x3038(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
imul   -0x18(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
cmpl   $0x0,-0x3034(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e2 <fillPolygonsFromFile+0x62>
jmp    1325 <fillPolygonsFromFile+0x1a5>
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1204 <fillPolygonsFromFile+0x84>
movl   $0x1,-0x3034(%rbp)
jmp    12d1 <fillPolygonsFromFile+0x151>
mov    -0x8(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    $0x8000,%edx
call   1090 <file_readline@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
call   1030 <strStrip@plt>
lea    -0x1020(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jne    1247 <fillPolygonsFromFile+0xc7>
jmp    12d1 <fillPolygonsFromFile+0x151>
movsbl -0x1020(%rbp),%eax
cmp    $0x23,%eax
jne    125c <fillPolygonsFromFile+0xdc>
jmp    11c9 <fillPolygonsFromFile+0x49>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x3040(%rbp)
mov    -0x3040(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <getFloat@plt>
mov    %eax,%ecx
movslq -0x1024(%rbp),%rax
mov    %ecx,-0x2030(%rbp,%rax,4)
mov    -0x3040(%rbp),%rdi
call   1080 <nextWord@plt>
mov    %rax,-0x3040(%rbp)
mov    -0x3040(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <getFloat@plt>
mov    %eax,%ecx
movslq -0x1024(%rbp),%rax
mov    %ecx,-0x3030(%rbp,%rax,4)
mov    -0x1024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1024(%rbp)
jmp    11c9 <fillPolygonsFromFile+0x49>
cmpl   $0x2,-0x1024(%rbp)
jle    1320 <fillPolygonsFromFile+0x1a0>
mov    -0x1024(%rbp),%edi
lea    -0x2030(%rbp),%rsi
lea    -0x3030(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
call   10a0 <fillPolygon@plt>
mov    %rax,%rcx
movslq -0x3038(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x3038(%rbp)
movl   $0x0,-0x1024(%rbp)
jmp    11c9 <fillPolygonsFromFile+0x49>
cmpl   $0x1,-0x3038(%rbp)
jge    1347 <fillPolygonsFromFile+0x1c7>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
imul   -0x18(%rbp),%edx
mov    $0x1,%esi
call   1060 <memset@plt>
add    $0x3040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fillPolygonsFromFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3018,%rsp
mov    %ecx,%r13d
mov    %rsi,%r14
mov    %rdi,%rbp
mov    %ecx,0xc(%rsp)
mov    %edx,0x8(%rsp)
imul   %edx,%r13d
xor    %r12d,%r12d
mov    %rsi,%rdi
xor    %esi,%esi
mov    %r13d,%edx
call   1050 <memset@plt>
lea    0x2010(%rsp),%rbx
movl   $0x0,0x4(%rsp)
xor    %r15d,%r15d
movslq %r15d,%r15
nopl   0x0(%rax)
test   %r12d,%r12d
jne    127b <fillPolygonsFromFile+0x10b>
mov    %rbp,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    1240 <fillPolygonsFromFile+0xd0>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x8000,%edx
call   1080 <file_readline@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <strStrip@plt>
xor    %r12d,%r12d
movzbl 0x2010(%rsp),%eax
cmp    $0x23,%al
je     11c0 <fillPolygonsFromFile+0x50>
test   %al,%al
je     1246 <fillPolygonsFromFile+0xd6>
xor    %r12d,%r12d
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <getFloat@plt>
mov    %eax,0x1010(%rsp,%r15,4)
mov    %rbx,%rdi
call   1070 <nextWord@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1040 <getFloat@plt>
mov    %eax,0x10(%rsp,%r15,4)
add    $0x1,%r15
jmp    11c0 <fillPolygonsFromFile+0x50>
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%r12d
cmp    $0x3,%r15d
jl     11b9 <fillPolygonsFromFile+0x49>
mov    %r15d,%edi
lea    0x1010(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rcx
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%r9d
call   1090 <fillPolygon@plt>
add    %eax,0x4(%rsp)
jmp    11b6 <fillPolygonsFromFile+0x46>
cmpl   $0x0,0x4(%rsp)
jg     1292 <fillPolygonsFromFile+0x122>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
call   1050 <memset@plt>
add    $0x3018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fillPolygonsFromFile(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4096 x i8]
%10 = alloca i32
%11 = alloca [1024 x i32]
%12 = alloca [1024 x i32]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %10
store i32 0, i32* %13
store i32 0, i32* %14
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = mul nsw i32 %17, %18
%20 = call i32 @memset(i8* %16, i32 0, i32 %19)
br label %21
21: ; preds = %78, %47, %46, %4
%22 = load i32, i32* %13
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br i1 %24, label %25, label %79
25: ; preds = %21
%26 = load i32*, i32** %5
%27 = call i64 @feof(i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 1, i32* %13
br label %63
30: ; preds = %25
%31 = load i32*, i32** %5
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%33 = call i32 @file_readline(i32* %31, i8* %32, i32 32768)
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%36 = call i32 @strStrip(i8* %34, i8* %35)
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%38 = call i64 @strlen(i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %30
br label %63
41: ; preds = %30
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 35
br i1 %45, label %46, label %47
46: ; preds = %41
br label %21
47: ; preds = %41
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
store i8* %48, i8** %15
%49 = load i8*, i8** %15
%50 = call i32 @getFloat(i8* %49, i32* null)
%51 = load i32, i32* %10
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [1024 x i32], [1024 x i32]* %11, i64 0, i64 %52
store i32 %50, i32* %53
%54 = load i8*, i8** %15
%55 = call i8* @nextWord(i8* %54)
store i8* %55, i8** %15
%56 = load i8*, i8** %15
%57 = call i32 @getFloat(i8* %56, i32* null)
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [1024 x i32], [1024 x i32]* %12, i64 0, i64 %59
store i32 %57, i32* %60
%61 = load i32, i32* %10
%62 = add nsw i32 %61, 1
store i32 %62, i32* %10
br label %21
63: ; preds = %40, %29
%64 = load i32, i32* %10
%65 = icmp sgt i32 %64, 2
br i1 %65, label %66, label %78
66: ; preds = %63
%67 = load i32, i32* %10
%68 = getelementptr inbounds [1024 x i32], [1024 x i32]* %11, i64 0, i64 0
%69 = getelementptr inbounds [1024 x i32], [1024 x i32]* %12, i64 0, i64 0
%70 = load i8*, i8** %6
%71 = load i32, i32* %7
%72 = load i32, i32* %8
%73 = call i64 @fillPolygon(i32 %67, i32* %68, i32* %69, i8* %70, i32 %71, i32 %72)
%74 = load i32, i32* %14
%75 = sext i32 %74 to i64
%76 = add nsw i64 %75, %73
%77 = trunc i64 %76 to i32
store i32 %77, i32* %14
store i32 0, i32* %10
br label %78
78: ; preds = %66, %63
br label %21
79: ; preds = %21
%80 = load i32, i32* %14
%81 = icmp slt i32 %80, 1
br i1 %81, label %82, label %88
82: ; preds = %79
%83 = load i8*, i8** %6
%84 = load i32, i32* %7
%85 = load i32, i32* %8
%86 = mul nsw i32 %84, %85
%87 = call i32 @memset(i8* %83, i32 1, i32 %86)
br label %88
88: ; preds = %82, %79
ret void
}

LLVM IR (-O2):
define void @fillPolygonsFromFile(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [4096 x i8]
%6 = alloca [1024 x i32]
%7 = alloca [1024 x i32]
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%9 = bitcast [1024 x i32]* %6 to i8*
%10 = bitcast [1024 x i32]* %7 to i8*
%11 = mul nsw i32 %3, %2
%12 = tail call i32 @memset(i8* %1, i32 0, i32 %11)
%13 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 0
%14 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
br label %15
15: ; preds = %47, %4
%16 = phi i32 [ %44, %47 ], [ 0, %4 ]
%17 = phi i32 [ %51, %47 ], [ 0, %4 ]
br label %18
18: ; preds = %15, %43
%19 = phi i32 [ %44, %43 ], [ %16, %15 ]
%20 = phi i64 [ %24, %43 ], [ 0, %15 ]
%21 = shl i64 %20, 32
%22 = ashr exact i64 %21, 32
br label %23
23: ; preds = %18, %36
%24 = phi i64 [ %22, %18 ], [ %42, %36 ]
%25 = phi i32 [ %19, %18 ], [ 0, %36 ]
br label %26
26: ; preds = %23, %32
%27 = phi i32 [ 0, %32 ], [ %25, %23 ]
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %52
29: ; preds = %26
%30 = call i64 @feof(i32* %0)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %29
%33 = call i32 @file_readline(i32* %0, i8* %8, i32 32768)
%34 = call i32 @strStrip(i8* %8, i8* %8)
%35 = load i8, i8* %8
switch i8 %35, label %36 [
i8 0, label %43
i8 35, label %26
]
36: ; preds = %32
%37 = call i32 @getFloat(i8* %8, i32* null)
%38 = getelementptr inbounds [1024 x i32], [1024 x i32]* %6, i64 0, i64 %24
store i32 %37, i32* %38
%39 = call i8* @nextWord(i8* %8)
%40 = call i32 @getFloat(i8* %39, i32* null)
%41 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 %24
store i32 %40, i32* %41
%42 = add i64 %24, 1
br label %23
43: ; preds = %32, %29
%44 = phi i32 [ 0, %32 ], [ 1, %29 ]
%45 = trunc i64 %24 to i32
%46 = icmp sgt i32 %45, 2
br i1 %46, label %47, label %18
47: ; preds = %43
%48 = trunc i64 %24 to i32
%49 = call i64 @fillPolygon(i32 %48, i32* %13, i32* %14, i8* %1, i32 %2, i32 %3)
%50 = trunc i64 %49 to i32
%51 = add i32 %17, %50
br label %15
52: ; preds = %26
%53 = icmp slt i32 %17, 1
br i1 %53, label %54, label %56
54: ; preds = %52
%55 = call i32 @memset(i8* %1, i32 1, i32 %11)
br label %56
56: ; preds = %54, %52
ret void
}