#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  FILE *file;
  char buffer[1];
  int iterator;
  int item_found = 1;
  if (argc != 2) {
    printf("Please provide a file..\n");
    return -1;
  }
  file = fopen(argv[1], "r");
  if (file == NULL) {
    printf("failed to open: %s..\n", argv[0]);
    return -1;
  }
  iterator = 0;
  item_found = 0;
  while (fread(buffer, 1, 1, file) == 1) {
    if (buffer[0] == '\n') {
      printf("\n");
      if (item_found) {
        iterator++;
        item_found = 0;
      }
    } else {
      printf("iterator=%d: value: %d, %c ", iterator, (unsigned char)buffer[0],
             buffer[0]);
      item_found = 1;
    }
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1181 <main+0x41>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125f <main+0x11f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c5 <main+0x85>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125f <main+0x11f>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x19(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    124f <main+0x10f>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    122a <main+0xea>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x24(%rbp)
je     1225 <main+0xe5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    124a <main+0x10a>
mov    -0x20(%rbp),%esi
movzbl -0x19(%rbp),%edx
movsbl -0x19(%rbp),%ecx
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x24(%rbp)
jmp    11d3 <main+0x93>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    121c <main+0xbc>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe7d(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1236 <main+0xd6>
mov    %rax,%r12
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
cmp    $0x1,%eax
jne    122a <main+0xca>
lea    0xf(%rsp),%r14
lea    0xe5c(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    11fe <main+0x9e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl %cl,%edx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%ebx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1050 <fread@plt>
cmp    $0x1,%eax
jne    122a <main+0xca>
movsbl 0xf(%rsp),%ecx
cmp    $0xa,%ecx
jne    11d0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0x1,%ebx
sbb    $0xffffffff,%ebp
xor    %ebx,%ebx
jmp    11e4 <main+0x84>
lea    0xe11(%rip),%rdi
call   1040 <puts@plt>
jmp    1248 <main+0xe8>
mov    %r12,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
jmp    124d <main+0xed>
mov    0x0(%rbp),%rsi
lea    0xdc1(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Please provide a file..\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"failed to open: %s..\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [28 x i8] c"iterator=%d: value: %d, %c \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %58
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i32 -1, i32* %3
br label %58
26: ; preds = %14
store i32 0, i32* %8
store i32 0, i32* %9
br label %27
27: ; preds = %54, %26
%28 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%29 = load i32*, i32** %6
%30 = call i32 @fread(i8* %28, i32 1, i32 1, i32* %29)
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %55
32: ; preds = %27
%33 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %45
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32, i32* %9
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
store i32 0, i32* %9
br label %44
44: ; preds = %41, %37
br label %54
45: ; preds = %32
%46 = load i32, i32* %8
%47 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %49, i32 %52)
store i32 1, i32* %9
br label %54
54: ; preds = %45, %44
br label %27
55: ; preds = %27
%56 = load i32*, i32** %6
%57 = call i32 @fclose(i32* %56)
store i32 0, i32* %3
br label %58
58: ; preds = %55, %21, %12
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"failed to open: %s..\0A\00"
@.str.4 = [28 x i8] c"iterator=%d: value: %d, %c \00"
@str = [24 x i8] c"Please provide a file..\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1 x i8]
%4 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %40
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %11)
%15 = icmp eq i32 %14, 1
br i1 %15, label %19, label %38
16: ; preds = %8
%17 = load i8*, i8** %1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %17)
br label %40
19: ; preds = %13, %33
%20 = phi i32 [ %35, %33 ], [ 0, %13 ]
%21 = phi i32 [ %34, %33 ], [ 0, %13 ]
%22 = load i8, i8* %4
%23 = icmp eq i8 %22, 10
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = tail call i32 @putchar(i32 10)
%26 = icmp ne i32 %20, 0
%27 = zext i1 %26 to i32
%28 = add nsw i32 %21, %27
br label %33
29: ; preds = %19
%30 = sext i8 %22 to i32
%31 = zext i8 %22 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %21, i32 %31, i32 %30)
br label %33
33: ; preds = %24, %29
%34 = phi i32 [ %21, %29 ], [ %28, %24 ]
%35 = phi i32 [ 1, %29 ], [ 0, %24 ]
%36 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %11)
%37 = icmp eq i32 %36, 1
br i1 %37, label %19, label %38
38: ; preds = %33, %13
%39 = tail call i32 @fclose(i32* %11)
br label %40
40: ; preds = %38, %16, %6
%41 = phi i32 [ -1, %6 ], [ -1, %16 ], [ 0, %38 ]
ret i32 %41
}