#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__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *, int *,
                  int *, int *);
scalar_t__ intersects_x(int, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int x1, y1;
  int x2, y2;
  int x3, y3;
  int intersections, count = 0;
  FILE *file = fopen("triangles.txt", "r");
  if (file != NULL) {
    while (fscanf(file, "%d,%d,%d,%d,%d,%d", &x1, &y1, &x2, &y2, &x3, &y3) !=
           EOF) {
      intersections = 0;
      if (intersects_x(x1, y1, x2, y2)) {
        intersections++;
      }
      if (intersects_x(x1, y1, x3, y3)) {
        intersections++;
      }
      if (intersects_x(x2, y2, x3, y3)) {
        intersections++;
      }
      if (intersections == 1) {
        count++;
      }
      if (0) {
        if (intersections == 1) {
          printf("(%d, %d), (%d, %d), (%d, %d) contains the center, 1 "
                 "intersection\n",
                 x1, y1, x2, y2, x3, y3);
        } else {
          printf("(%d, %d), (%d, %d), (%d, %d) doesn't contain the center, %d "
                 "intersections\n",
                 x1, y1, x2, y2, x3, y3, intersections);
        }
      }
    }
    fclose(file);
    printf("\nThe number of triangles containing the center is %d\n\n", count);
    return 0;
  } else {
    printf("Couldn't read the file...\n\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     127f <main+0x12f>
jmp    118d <main+0x3d>
mov    -0x30(%rbp),%rdi
lea    0xe78(%rip),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
lea    -0x14(%rbp),%r9
lea    -0x18(%rbp),%r10
lea    -0x1c(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <fscanf@plt>
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
je     1259 <main+0x109>
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1060 <intersects_x@plt>
cmp    $0x0,%rax
je     11f9 <main+0xa9>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1060 <intersects_x@plt>
cmp    $0x0,%rax
je     121d <main+0xcd>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1060 <intersects_x@plt>
cmp    $0x0,%rax
je     1241 <main+0xf1>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    1254 <main+0x104>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118d <main+0x3d>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%esi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1294 <main+0x144>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a0 <main+0x140>
mov    %rax,%r14
lea    0x10(%rsp),%rbx
lea    0x14(%rsp),%r12
lea    0xe72(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rsp,%r9
mov    %rax,%rdi
push   %rbx
push   %r12
call   1060 <fscanf@plt>
add    $0x10,%rsp
mov    0x2e22(%rip),%rcx
mov    $0x0,%ebp
cmp    (%rcx),%rax
je     1284 <main+0x124>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
call   1070 <intersects_x@plt>
mov    %r12,%r15
xor    %r12d,%r12d
test   %rax,%rax
setne  %r12b
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
call   1070 <intersects_x@plt>
lea    0x1(%r12),%r13d
test   %rax,%rax
cmove  %r12d,%r13d
mov    %r15,%r12
mov    0x4(%rsp),%edi
mov    (%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
call   1070 <intersects_x@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%r13d
xor    %eax,%eax
cmp    $0x1,%r13d
sete   %al
add    %eax,%ebp
mov    %r14,%rdi
lea    0xdba(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rsp,%r9
push   %rbx
push   %r15
call   1060 <fscanf@plt>
mov    0x2d71(%rip),%rcx
add    $0x10,%rsp
cmp    (%rcx),%rax
jne    11e0 <main+0x80>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xd8f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
jmp    12b1 <main+0x151>
lea    0xdb2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"triangles.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"%d,%d,%d,%d,%d,%d\00"
@EOF = global i64 0
@.str.3 = [55 x i8] c"\0AThe number of triangles containing the center is %d\0A\0A\00"
@.str.4 = [28 x i8] c"Couldn't read the file...\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %9
%11 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %10
%12 = load i32*, i32** %10
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %62
14: ; preds = %0
br label %15
15: ; preds = %56, %14
%16 = load i32*, i32** %10
%17 = call i64 @fscanf(i32* %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7)
%18 = load i64, i64* @EOF
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %57
20: ; preds = %15
store i32 0, i32* %8
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = call i64 @intersects_x(i32 %21, i32 %22, i32 %23, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %30
30: ; preds = %27, %20
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = call i64 @intersects_x(i32 %31, i32 %32, i32 %33, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %40
40: ; preds = %37, %30
%41 = load i32, i32* %4
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = load i32, i32* %7
%45 = call i64 @intersects_x(i32 %41, i32 %42, i32 %43, i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %40
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %50
50: ; preds = %47, %40
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %56
56: ; preds = %53, %50
br label %15
57: ; preds = %15
%58 = load i32*, i32** %10
%59 = call i32 @fclose(i32* %58)
%60 = load i32, i32* %9
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %60)
store i32 0, i32* %1
br label %64
62: ; preds = %0
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %64
64: ; preds = %62, %57
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
@.str = [14 x i8] c"triangles.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"%d,%d,%d,%d,%d,%d\00"
@EOF = global i64 0
@.str.3 = [55 x i8] c"\0AThe number of triangles containing the center is %d\0A\0A\00"
@str = [27 x i8] c"Couldn't read the file...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %54, label %15
15: ; preds = %0
%16 = call i64 @fscanf(i32* %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %50, label %19
19: ; preds = %15, %19
%20 = phi i32 [ %46, %19 ], [ 0, %15 ]
%21 = load i32, i32* %1
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = call i64 @intersects_x(i32 %21, i32 %22, i32 %23, i32 %24)
%26 = icmp ne i64 %25, 0
%27 = zext i1 %26 to i32
%28 = load i32, i32* %1
%29 = load i32, i32* %2
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = call i64 @intersects_x(i32 %28, i32 %29, i32 %30, i32 %31)
%33 = icmp eq i64 %32, 0
%34 = select i1 %26, i32 2, i32 1
%35 = select i1 %33, i32 %27, i32 %34
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = call i64 @intersects_x(i32 %36, i32 %37, i32 %38, i32 %39)
%41 = icmp ne i64 %40, 0
%42 = zext i1 %41 to i32
%43 = add nuw nsw i32 %35, %42
%44 = icmp eq i32 %43, 1
%45 = zext i1 %44 to i32
%46 = add nuw nsw i32 %20, %45
%47 = call i64 @fscanf(i32* %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6)
%48 = load i64, i64* @EOF
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %19
50: ; preds = %19, %15
%51 = phi i32 [ 0, %15 ], [ %46, %19 ]
%52 = call i32 @fclose(i32* %13)
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %51)
br label %56
54: ; preds = %0
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %56
56: ; preds = %54, %50
%57 = phi i32 [ 0, %50 ], [ 1, %54 ]
ret i32 %57
}