#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 */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
long strtol(char *, char **, int);
int main(int argc, char **argv) {
  char line[16 + 1];
  char *next;
  FILE *inFile;
  long s1, s2, s3;
  int numTriangles = 0;
  if (argc != 2) {
    fprintf(stderr, "Usage:\n\tDay3 <input filename>\n\n");
    return EXIT_FAILURE;
  }
  inFile = fopen(argv[1], "r");
  if (inFile == NULL) {
    fprintf(stderr, "Error opening file: %s\n\n", strerror(errno));
    return EXIT_FAILURE;
  }
  while (fgets(line, 16 + 1, inFile) != NULL) {
    s1 = strtol(line, &next, 10);
    s2 = strtol(next, &next, 10);
    s3 = strtol(next, &next, 10);
    if (s1 == 0 || s2 == 0 || s3 == 0) {
      fprintf(stderr, "Error parsing numbers: %s\n\n", strerror(errno));
      fprintf(stderr, "Line: %s\n", line);
      fclose(inFile);
      return EXIT_FAILURE;
    }
    if (s1 + s2 > s3 && s2 + s3 > s1 && s3 + s1 > s2)
      numTriangles++;
  }
  fclose(inFile);
  printf("Number of possible triangles: %d\n", numTriangles);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bf <main+0x4f>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1370 <main+0x200>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe52(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1221 <main+0xb1>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x60(%rbp),%edi
mov    %rax,%rdx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1370 <main+0x200>
jmp    1226 <main+0xb6>
lea    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    $0x11,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     134c <main+0x1dc>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     12a5 <main+0x135>
cmpq   $0x0,-0x50(%rbp)
je     12a5 <main+0x135>
cmpq   $0x0,-0x58(%rbp)
jne    1308 <main+0x198>
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1370 <main+0x200>
mov    -0x48(%rbp),%rax
add    -0x50(%rbp),%rax
cmp    -0x58(%rbp),%rax
jle    1347 <main+0x1d7>
mov    -0x50(%rbp),%rax
add    -0x58(%rbp),%rax
cmp    -0x48(%rbp),%rax
jle    1347 <main+0x1d7>
mov    -0x58(%rbp),%rax
add    -0x48(%rbp),%rax
cmp    -0x50(%rbp),%rax
jle    1347 <main+0x1d7>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1226 <main+0xb6>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x5c(%rbp),%esi
lea    0xd02(%rip),%rdi
call   1040 <printf@plt>
mov    0x2c5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x2,%edi
jne    1288 <main+0x118>
mov    0x8(%rsi),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a1 <main+0x131>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0x11,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     1265 <main+0xf5>
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
test   %rbx,%rbx
je     12cd <main+0x15d>
test   %rbp,%rbp
je     12cd <main+0x15d>
test   %rax,%rax
je     12cd <main+0x15d>
lea    (%rbx,%rbp,1),%rcx
cmp    %rax,%rcx
setg   %cl
lea    (%rax,%rbp,1),%rdx
cmp    %rbx,%rdx
setg   %dl
and    %cl,%dl
add    %rbx,%rax
cmp    %rbp,%rax
setg   %al
and    %dl,%al
movzbl %al,%eax
add    %eax,%r13d
mov    %r15,%rdi
mov    $0x11,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11d0 <main+0x60>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xded(%rip),%rdi
mov    %r13d,%esi
call   1040 <printf@plt>
mov    0x2d45(%rip),%rax
jmp    131d <main+0x1ad>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1316 <main+0x1a6>
mov    0x2d38(%rip),%rax
mov    (%rax),%ebx
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd63(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1316 <main+0x1a6>
mov    0x2d0c(%rip),%rbp
mov    0x0(%rbp),%ebx
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd4f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd55(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Usage:\0A\09Day3 <input filename>\0A\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Error opening file: %s\0A\0A\00"
@errno = global i32 0
@.str.3 = [28 x i8] c"Error parsing numbers: %s\0A\0A\00"
@.str.4 = [10 x i8] c"Line: %s\0A\00"
@.str.5 = [34 x i8] c"Number of possible triangles: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [17 x i8]
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %12
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %92
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %8
%24 = load i32*, i32** %8
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %32
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %3
br label %92
32: ; preds = %19
br label %33
33: ; preds = %85, %32
%34 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 0
%35 = load i32*, i32** %8
%36 = call i32* @fgets(i8* %34, i32 17, i32* %35)
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %86
38: ; preds = %33
%39 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 0
%40 = call i64 @strtol(i8* %39, i8** %7, i32 10)
store i64 %40, i64* %9
%41 = load i8*, i8** %7
%42 = call i64 @strtol(i8* %41, i8** %7, i32 10)
store i64 %42, i64* %10
%43 = load i8*, i8** %7
%44 = call i64 @strtol(i8* %43, i8** %7, i32 10)
store i64 %44, i64* %11
%45 = load i64, i64* %9
%46 = icmp eq i64 %45, 0
br i1 %46, label %53, label %47
47: ; preds = %38
%48 = load i64, i64* %10
%49 = icmp eq i64 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = load i64, i64* %11
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %64
53: ; preds = %50, %47, %38
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = load i32, i32* @stderr
%59 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 0
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %59)
%61 = load i32*, i32** %8
%62 = call i32 @fclose(i32* %61)
%63 = load i32, i32* @EXIT_FAILURE
store i32 %63, i32* %3
br label %92
64: ; preds = %50
%65 = load i64, i64* %9
%66 = load i64, i64* %10
%67 = add nsw i64 %65, %66
%68 = load i64, i64* %11
%69 = icmp sgt i64 %67, %68
br i1 %69, label %70, label %85
70: ; preds = %64
%71 = load i64, i64* %10
%72 = load i64, i64* %11
%73 = add nsw i64 %71, %72
%74 = load i64, i64* %9
%75 = icmp sgt i64 %73, %74
br i1 %75, label %76, label %85
76: ; preds = %70
%77 = load i64, i64* %11
%78 = load i64, i64* %9
%79 = add nsw i64 %77, %78
%80 = load i64, i64* %10
%81 = icmp sgt i64 %79, %80
br i1 %81, label %82, label %85
82: ; preds = %76
%83 = load i32, i32* %12
%84 = add nsw i32 %83, 1
store i32 %84, i32* %12
br label %85
85: ; preds = %82, %76, %70, %64
br label %33
86: ; preds = %33
%87 = load i32*, i32** %8
%88 = call i32 @fclose(i32* %87)
%89 = load i32, i32* %12
%90 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %89)
%91 = load i32, i32* @EXIT_SUCCESS
store i32 %91, i32* %3
br label %92
92: ; preds = %86, %53, %26, %15
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Usage:\0A\09Day3 <input filename>\0A\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Error opening file: %s\0A\0A\00"
@errno = global i32 0
@.str.3 = [28 x i8] c"Error parsing numbers: %s\0A\0A\00"
@.str.4 = [10 x i8] c"Line: %s\0A\00"
@.str.5 = [34 x i8] c"Number of possible triangles: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [17 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %61
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = call i32* @fgets(i8* %5, i32 17, i32* %14)
%18 = icmp eq i32* %17, null
br i1 %18, label %57, label %24
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = tail call i8* @strerror(i32 %21)
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %61
24: ; preds = %16, %44
%25 = phi i32 [ %54, %44 ], [ 0, %16 ]
%26 = call i64 @strtol(i8* %5, i8** %4, i32 10)
%27 = load i8*, i8** %4
%28 = call i64 @strtol(i8* %27, i8** %4, i32 10)
%29 = load i8*, i8** %4
%30 = call i64 @strtol(i8* %29, i8** %4, i32 10)
%31 = icmp eq i64 %26, 0
%32 = icmp eq i64 %28, 0
%33 = select i1 %31, i1 true, i1 %32
%34 = icmp eq i64 %30, 0
%35 = select i1 %33, i1 true, i1 %34
br i1 %35, label %36, label %44
36: ; preds = %24
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%43 = call i32 @fclose(i32* %14)
br label %61
44: ; preds = %24
%45 = add nsw i64 %28, %26
%46 = icmp sgt i64 %45, %30
%47 = add nsw i64 %30, %28
%48 = icmp sgt i64 %47, %26
%49 = select i1 %46, i1 %48, i1 false
%50 = add nsw i64 %30, %26
%51 = icmp sgt i64 %50, %28
%52 = select i1 %49, i1 %51, i1 false
%53 = zext i1 %52 to i32
%54 = add nuw nsw i32 %25, %53
%55 = call i32* @fgets(i8* %5, i32 17, i32* %14)
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %24
57: ; preds = %44, %16
%58 = phi i32 [ 0, %16 ], [ %54, %44 ]
%59 = call i32 @fclose(i32* %14)
%60 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %58)
br label %61
61: ; preds = %57, %36, %19, %8
%62 = phi i32* [ @EXIT_FAILURE, %8 ], [ @EXIT_FAILURE, %19 ], [ @EXIT_FAILURE, %36 ], [ @EXIT_SUCCESS, %57 ]
%63 = load i32, i32* %62
ret i32 %63
}