#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 == '/') {
        if ((c = getc(fp)) == '/') {
          ct++;
        }
      }
      if (c == EOF) {
        break;
      }
    }
    fclose(fp);
    printf("The file has %d commented 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     1228 <main+0xd8>
jmp    11a5 <main+0x55>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%eax
je     1209 <main+0xb9>
cmpl   $0x2f,-0x14(%rbp)
jne    11ed <main+0x9d>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x2f,%eax
jne    11e8 <main+0x98>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ed <main+0x9d>
mov    -0x14(%rbp),%eax
mov    0x2df1(%rip),%rcx
cmp    (%rcx),%eax
jne    1204 <main+0xb4>
jmp    1209 <main+0xb9>
jmp    11a5 <main+0x55>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%esi
lea    0xe2b(%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     11f5 <main+0xb5>
mov    %rax,%rbx
xor    %ebp,%ebp
mov    0x2e42(%rip),%r14
jmp    11b4 <main+0x74>
nopl   0x0(%rax,%rax,1)
cmp    %ecx,%eax
je     11df <main+0x9f>
mov    %rbx,%rdi
call   1060 <getc@plt>
mov    (%r14),%ecx
cmp    %ecx,%eax
je     11df <main+0x9f>
cmp    $0x2f,%eax
jne    11b0 <main+0x70>
mov    %rbx,%rdi
call   1060 <getc@plt>
xor    %ecx,%ecx
cmp    $0x2f,%eax
sete   %cl
add    %ecx,%ebp
mov    (%r14),%ecx
jmp    11b0 <main+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe59(%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 = [33 x i8] c"The file has %d commented 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 %42
14: ; preds = %2
br label %15
15: ; preds = %36, %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 %37
20: ; preds = %15
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32*, i32** %8
%25 = call i32 @getc(i32* %24)
store i32 %25, i32* %6
%26 = icmp eq i32 %25, 47
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %30
30: ; preds = %27, %23
br label %31
31: ; preds = %30, %20
%32 = load i32, i32* %6
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %31
br label %37
36: ; preds = %31
br label %15
37: ; preds = %35, %15
%38 = load i32*, i32** %8
%39 = call i32 @fclose(i32* %38)
%40 = load i32, i32* %7
%41 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %40)
store i32 0, i32* %3
br label %42
42: ; preds = %37, %2
%43 = load i32, i32* %3
ret i32 %43
}

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 = [33 x i8] c"The file has %d commented 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 %29, label %7
7: ; preds = %2, %20
%8 = phi i32 [ %23, %20 ], [ 0, %2 ]
%9 = tail call i32 @getc(i32* %5)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %25, label %12
12: ; preds = %7
%13 = icmp eq i32 %9, 47
br i1 %13, label %14, label %20
14: ; preds = %12
%15 = tail call i32 @getc(i32* %5)
%16 = icmp eq i32 %15, 47
%17 = zext i1 %16 to i32
%18 = add nsw i32 %8, %17
%19 = load i32, i32* @EOF
br label %20
20: ; preds = %14, %12
%21 = phi i32 [ %10, %12 ], [ %19, %14 ]
%22 = phi i32 [ %9, %12 ], [ %15, %14 ]
%23 = phi i32 [ %8, %12 ], [ %18, %14 ]
%24 = icmp eq i32 %22, %21
br i1 %24, label %25, label %7
25: ; preds = %20, %7
%26 = phi i32 [ %23, %20 ], [ %8, %7 ]
%27 = tail call i32 @fclose(i32* %5)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %29
29: ; preds = %2, %25
ret i32 0
}