#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*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
int main(int argc, const char *argv[]) {
  FILE *ofp;
  char *mode = "r";
  char outFileName[512];
  ofp = fopen("/Users/Nocturne/Desktop/TTT-Pre-Internship-Exercises/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;
    int y;
    int numOfLines = 0;
    int numOfComments = 0;
    int numOfCommentblocks = 0;
    while ((x = fgetc(ofp)) != EOF) {
      y = fgetc(ofp);
      if (x == '\n')
        numOfLines++;
      if (x == '/' & y == '/')
        numOfComments++;
      if (x == '/' && y == '*')
        numOfCommentblocks++;
    }
    printf("This ObjC file has about %d lines, %d comments, and %d comment "
           "blocks.",
           numOfLines, numOfComments, numOfCommentblocks);
  }
  fclose(ofp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bd <main+0x5d>
lea    0xecf(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x0,-0x22c(%rbp)
movl   $0x0,-0x230(%rbp)
movl   $0x0,-0x234(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x224(%rbp)
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%eax
je     128b <main+0x12b>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x228(%rbp)
cmpl   $0xa,-0x224(%rbp)
jne    1224 <main+0xc4>
mov    -0x22c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x22c(%rbp)
cmpl   $0x2f,-0x224(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x2f,-0x228(%rbp)
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     125d <main+0xfd>
mov    -0x230(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x230(%rbp)
cmpl   $0x2f,-0x224(%rbp)
jne    1286 <main+0x126>
cmpl   $0x2a,-0x228(%rbp)
jne    1286 <main+0x126>
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
jmp    11db <main+0x7b>
mov    -0x22c(%rbp),%esi
mov    -0x230(%rbp),%edx
mov    -0x234(%rbp),%ecx
lea    0xdf4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe90(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1231 <main+0xd1>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e4f(%rip),%r13
xor    %r12d,%r12d
mov    $0x0,%ebp
mov    $0x0,%r15d
cmp    0x0(%r13),%eax
je     1204 <main+0xa4>
mov    %eax,%ebx
xor    %r15d,%r15d
xor    %ebp,%ebp
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%ebx
sete   %cl
add    %ecx,%r12d
cmp    $0x2f,%ebx
sete   %cl
cmp    $0x2f,%eax
sete   %dl
and    %cl,%dl
movzbl %dl,%edx
add    %edx,%ebp
cmp    $0x2a,%eax
sete   %al
and    %cl,%al
movzbl %al,%eax
add    %eax,%r15d
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%eax
jne    11c0 <main+0x60>
lea    0xe8d(%rip),%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe41(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [119 x i8] c"/Users/Nocturne/Desktop/TTT-Pre-Internship-Exercises/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 = [71 x i8] c"This ObjC file has about %d lines, %d comments, and %d comment blocks.\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 [512 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = 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
%14 = load i8*, i8** %7
%15 = call i32* @fopen(i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
br label %23
23: ; preds = %57, %22
%24 = load i32*, i32** %6
%25 = call i32 @fgetc(i32* %24)
store i32 %25, i32* %9
%26 = load i32, i32* @EOF
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %58
28: ; preds = %23
%29 = load i32*, i32** %6
%30 = call i32 @fgetc(i32* %29)
store i32 %30, i32* %10
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, 10
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %11
br label %36
36: ; preds = %33, %28
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, 47
%39 = zext i1 %38 to i32
%40 = load i32, i32* %10
%41 = icmp eq i32 %40, 47
%42 = zext i1 %41 to i32
%43 = and i32 %39, %42
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %36
%46 = load i32, i32* %12
%47 = add nsw i32 %46, 1
store i32 %47, i32* %12
br label %48
48: ; preds = %45, %36
%49 = load i32, i32* %9
%50 = icmp eq i32 %49, 47
br i1 %50, label %51, label %57
51: ; preds = %48
%52 = load i32, i32* %10
%53 = icmp eq i32 %52, 42
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* %13
%56 = add nsw i32 %55, 1
store i32 %56, i32* %13
br label %57
57: ; preds = %54, %51, %48
br label %23
58: ; preds = %23
%59 = load i32, i32* %11
%60 = load i32, i32* %12
%61 = load i32, i32* %13
%62 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0), i32 %59, i32 %60, i32 %61)
br label %63
63: ; preds = %58
%64 = load i32*, i32** %6
%65 = call i32 @fclose(i32* %64)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [119 x i8] c"/Users/Nocturne/Desktop/TTT-Pre-Internship-Exercises/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 = [71 x i8] c"This ObjC file has about %d lines, %d comments, and %d comment blocks.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([119 x i8], [119 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 %34, 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, %13
%14 = phi i32 [ %31, %13 ], [ %6, %5 ]
%15 = phi i32 [ %30, %13 ], [ 0, %5 ]
%16 = phi i32 [ %26, %13 ], [ 0, %5 ]
%17 = phi i32 [ %21, %13 ], [ 0, %5 ]
%18 = tail call i32 @fgetc(i32* %3)
%19 = icmp eq i32 %14, 10
%20 = zext i1 %19 to i32
%21 = add nuw nsw i32 %17, %20
%22 = icmp eq i32 %14, 47
%23 = icmp eq i32 %18, 47
%24 = and i1 %22, %23
%25 = zext i1 %24 to i32
%26 = add nuw nsw i32 %16, %25
%27 = icmp eq i32 %18, 42
%28 = and i1 %22, %27
%29 = zext i1 %28 to i32
%30 = add nuw nsw i32 %15, %29
%31 = tail call i32 @fgetc(i32* %3)
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %13
34: ; preds = %13, %5
%35 = phi i32 [ 0, %5 ], [ %21, %13 ]
%36 = phi i32 [ 0, %5 ], [ %26, %13 ]
%37 = phi i32 [ 0, %5 ], [ %30, %13 ]
%38 = tail call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %36, i32 %37)
%39 = tail call i32 @fclose(i32* %3)
ret i32 0
}