#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
int main(int argc, const char *argv[]) {
  FILE *ofp;
  char *mode = "r";
  ofp = fopen("/Users/Nocturne/Desktop/Julio Reyes/Week 1 - "
              "Introduction/C/ReadAFileObjC/ReadAFileObjC/AppDelegate.m",
              mode);
  if (ofp == NULL) {
    perror("Error while opening the file.\n");
    exit(EXIT_FAILURE);
  } else {
    int x = 0;
    int y = 0;
    int numOfLines = 1;
    int numOfComments = 0;
    int numOfCommentblocks = 0;
    while ((x = fgetc(ofp)) != EOF) {
      if (x == '\n')
        numOfLines++;
      if (x == '/') {
        y = fgetc(ofp);
        if (y == '/')
          numOfComments++;
      }
    }
    fseek(ofp, 0, 0);
    while ((x = fgetc(ofp)) != EOF) {
      if (x == '/') {
        y = fgetc(ofp);
        if (y == '*')
          numOfCommentblocks++;
      }
    }
    printf("This ObjC file has about %d lines, %d comments, and %d comment "
           "blocks. \n",
           numOfLines, numOfComments, numOfCommentblocks);
  }
  fclose(ofp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ca <main+0x5a>
lea    0xeb1(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%eax
je     124e <main+0xde>
cmpl   $0xa,-0x24(%rbp)
jne    121b <main+0xab>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x2f,-0x24(%rbp)
jne    1249 <main+0xd9>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x2f,-0x28(%rbp)
jne    1244 <main+0xd4>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1249 <main+0xd9>
jmp    11ed <main+0x7d>
mov    -0x18(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d7a(%rip),%rcx
cmp    (%rcx),%eax
je     12a9 <main+0x139>
cmpl   $0x2f,-0x24(%rbp)
jne    12a4 <main+0x134>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x2a,-0x28(%rbp)
jne    129f <main+0x12f>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12a4 <main+0x134>
jmp    125b <main+0xeb>
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
lea    0xdce(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe80(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     127a <main+0x10a>
mov    %rax,%r13
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e3f(%rip),%rbx
mov    $0x1,%ebp
mov    $0x0,%r15d
cmp    (%rbx),%eax
jne    1203 <main+0x93>
mov    %r13,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <fseek@plt>
mov    %r13,%rdi
call   1050 <fgetc@plt>
cmp    (%rbx),%eax
mov    $0x0,%r14d
jne    124b <main+0xdb>
lea    0xeaa(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1040 <printf@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
xor    %r15d,%r15d
jmp    1225 <main+0xb5>
nopl   (%rax)
mov    %r12b,%bl
add    %ebx,%ebp
mov    %r13,%rdi
call   1050 <fgetc@plt>
mov    %r14,%rbx
cmp    (%r14),%eax
je     11b8 <main+0x48>
mov    %rbx,%r14
xor    %ebx,%ebx
cmp    $0xa,%eax
sete   %r12b
cmp    $0x2f,%eax
jne    1210 <main+0xa0>
mov    %r13,%rdi
call   1050 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0x2f,%eax
sete   %cl
add    %ecx,%r15d
jmp    1210 <main+0xa0>
xor    %r14d,%r14d
jmp    1260 <main+0xf0>
mov    %r13,%rdi
call   1050 <fgetc@plt>
cmp    (%rbx),%eax
je     11d6 <main+0x66>
cmp    $0x2f,%eax
jne    1250 <main+0xe0>
mov    %r13,%rdi
call   1050 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0x2a,%eax
sete   %cl
add    %ecx,%r14d
jmp    1250 <main+0xe0>
lea    0xde7(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [102 x i8] c"/Users/Nocturne/Desktop/Julio Reyes/Week 1 - Introduction/C/ReadAFileObjC/ReadAFileObjC/AppDelegate.m\00"
@.str.2 = [31 x i8] c"Error while opening the file.\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
@.str.3 = [73 x i8] c"This ObjC file has about %d lines, %d comments, and %d comment blocks. \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %7
%13 = load i8*, i8** %7
%14 = call i32* @fopen(i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
store i32 0, i32* %8
store i32 0, i32* %9
store i32 1, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %22
22: ; preds = %45, %21
%23 = load i32*, i32** %6
%24 = call i32 @fgetc(i32* %23)
store i32 %24, i32* %8
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %46
27: ; preds = %22
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %10
%32 = add nsw i32 %31, 1
store i32 %32, i32* %10
br label %33
33: ; preds = %30, %27
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, 47
br i1 %35, label %36, label %45
36: ; preds = %33
%37 = load i32*, i32** %6
%38 = call i32 @fgetc(i32* %37)
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = icmp eq i32 %39, 47
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %44
44: ; preds = %41, %36
br label %45
45: ; preds = %44, %33
br label %22
46: ; preds = %22
%47 = load i32*, i32** %6
%48 = call i32 @fseek(i32* %47, i32 0, i32 0)
br label %49
49: ; preds = %66, %46
%50 = load i32*, i32** %6
%51 = call i32 @fgetc(i32* %50)
store i32 %51, i32* %8
%52 = load i32, i32* @EOF
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %67
54: ; preds = %49
%55 = load i32, i32* %8
%56 = icmp eq i32 %55, 47
br i1 %56, label %57, label %66
57: ; preds = %54
%58 = load i32*, i32** %6
%59 = call i32 @fgetc(i32* %58)
store i32 %59, i32* %9
%60 = load i32, i32* %9
%61 = icmp eq i32 %60, 42
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i32, i32* %12
%64 = add nsw i32 %63, 1
store i32 %64, i32* %12
br label %65
65: ; preds = %62, %57
br label %66
66: ; preds = %65, %54
br label %49
67: ; preds = %49
%68 = load i32, i32* %10
%69 = load i32, i32* %11
%70 = load i32, i32* %12
%71 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.3, i64 0, i64 0), i32 %68, i32 %69, i32 %70)
br label %72
72: ; preds = %67
%73 = load i32*, i32** %6
%74 = call i32 @fclose(i32* %73)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [102 x i8] c"/Users/Nocturne/Desktop/Julio Reyes/Week 1 - Introduction/C/ReadAFileObjC/ReadAFileObjC/AppDelegate.m\00"
@.str.2 = [31 x i8] c"Error while opening the file.\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
@.str.3 = [73 x i8] c"This ObjC file has about %d lines, %d comments, and %d comment blocks. \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i32 @fgetc(i32* %3)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %31, label %13
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %5, %26
%14 = phi i32 [ %28, %26 ], [ %6, %5 ]
%15 = phi i32 [ %27, %26 ], [ 0, %5 ]
%16 = phi i32 [ %19, %26 ], [ 1, %5 ]
%17 = icmp eq i32 %14, 10
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %16, %18
%20 = icmp eq i32 %14, 47
br i1 %20, label %21, label %26
21: ; preds = %13
%22 = tail call i32 @fgetc(i32* %3)
%23 = icmp eq i32 %22, 47
%24 = zext i1 %23 to i32
%25 = add nsw i32 %15, %24
br label %26
26: ; preds = %21, %13
%27 = phi i32 [ %15, %13 ], [ %25, %21 ]
%28 = tail call i32 @fgetc(i32* %3)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %13
31: ; preds = %26, %5
%32 = phi i32 [ 1, %5 ], [ %19, %26 ]
%33 = phi i32 [ 0, %5 ], [ %27, %26 ]
%34 = tail call i32 @fseek(i32* %3, i32 0, i32 0)
%35 = tail call i32 @fgetc(i32* %3)
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %52, label %38
38: ; preds = %31, %47
%39 = phi i32 [ %49, %47 ], [ %35, %31 ]
%40 = phi i32 [ %48, %47 ], [ 0, %31 ]
%41 = icmp eq i32 %39, 47
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = tail call i32 @fgetc(i32* %3)
%44 = icmp eq i32 %43, 42
%45 = zext i1 %44 to i32
%46 = add nsw i32 %40, %45
br label %47
47: ; preds = %42, %38
%48 = phi i32 [ %40, %38 ], [ %46, %42 ]
%49 = tail call i32 @fgetc(i32* %3)
%50 = load i32, i32* @EOF
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %38
52: ; preds = %47, %31
%53 = phi i32 [ 0, %31 ], [ %48, %47 ]
%54 = tail call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %33, i32 %53)
%55 = tail call i32 @fclose(i32* %3)
ret i32 0
}