#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int c;
  int ct = 0;
  FILE *fp;
  const char filename[] =
      "/Users/seanreed/iosProjects/week1-cont/week1-cont/problem_12_alt.txt";
  if ((fp = fopen(filename, "r"))) {
    while ((c = getc(fp)) != EOF) {
      if (c == '\n') {
        ct++;
      }
    }
    fclose(fp);
    printf("The file has %d lines\n", ct);
    return 0;
  }
}


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,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe88(%rip),%rsi
mov    $0x45,%edx
call   1050 <memcpy@plt>
lea    -0x70(%rbp),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f7 <main+0xa7>
jmp    11a5 <main+0x55>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%eax
je     11d8 <main+0x88>
cmpl   $0xa,-0x14(%rbp)
jne    11d3 <main+0x83>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a5 <main+0x55>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%esi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
movaps 0xee1(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xec5(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xea9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x7478742e746c61,%rax
mov    %rax,0x3d(%rsp)
lea    0xeb8(%rip),%rsi
mov    %rsp,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11ed <main+0xad>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <getc@plt>
mov    0x2e3c(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%eax
je     11d7 <main+0x97>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1060 <getc@plt>
cmp    (%r14),%eax
jne    11c0 <main+0x80>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe61(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.filename = [69 x i8] c"/Users/seanreed/iosProjects/week1-cont/week1-cont/problem_12_alt.txt\00"
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.1 = [23 x i8] c"The file has %d lines\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca [69 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%10 = bitcast [69 x i8]* %9 to i8*
%11 = getelementptr inbounds [69 x i8], [69 x i8]* %9, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %32
14: ; preds = %2
br label %15
15: ; preds = %26, %14
%16 = load i32*, i32** %8
%17 = call i32 @getc(i32* %16)
store i32 %17, i32* %6
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %15
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %26
26: ; preds = %23, %20
br label %15
27: ; preds = %15
%28 = load i32*, i32** %8
%29 = call i32 @fclose(i32* %28)
%30 = load i32, i32* %7
%31 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %30)
store i32 0, i32* %3
br label %32
32: ; preds = %27, %2
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@__const.main.filename = [69 x i8] c"/Users/seanreed/iosProjects/week1-cont/week1-cont/problem_12_alt.txt\00"
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.1 = [23 x i8] c"The file has %d lines\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [69 x i8]
%4 = getelementptr inbounds [69 x i8], [69 x i8]* %3, i64 0, i64 0
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %24, label %7
7: ; preds = %2
%8 = tail call i32 @getc(i32* %5)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %20, label %11
11: ; preds = %7, %11
%12 = phi i32 [ %17, %11 ], [ %8, %7 ]
%13 = phi i32 [ %16, %11 ], [ 0, %7 ]
%14 = icmp eq i32 %12, 10
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %13, %15
%17 = tail call i32 @getc(i32* %5)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %11
20: ; preds = %11, %7
%21 = phi i32 [ 0, %7 ], [ %16, %11 ]
%22 = tail call i32 @fclose(i32* %5)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %24
24: ; preds = %2, %20
ret i32 0
}