#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc == 1) {
    printf("Programa para verificacao de tipo de arquivo.\n");
    printf("Uso: projeto nomeArquivo\n");
    return 0;
  }
  int i;
  for (i = 1; i < argc; i++) {
    printf("[%d] %s\n", i, argv[i]);
    FILE *f = NULL;
    f = fopen(argv[i], "r");
    if (f == NULL) {
      printf("Erro ao abrir o arquivo '%s'\n", argv[i]);
      return 1;
    }
    int c, count = 0;
    c = fgetc(f);
    while (c != EOF) {
      count++;
      c = fgetc(f);
      printf("%d\n", c);
    }
    fclose(f);
    f = NULL;
  }
  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)
cmpl   $0x1,-0x8(%rbp)
jne    1188 <main+0x48>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1283 <main+0x143>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127c <main+0x13c>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120d <main+0xcd>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1283 <main+0x143>
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%eax
je     125d <main+0x11d>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1220 <main+0xe0>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118f <main+0x4f>
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   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    117f <main+0x2f>
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1238 <main+0xe8>
xor    %eax,%eax
cmp    $0x2,%edi
jl     1238 <main+0xe8>
mov    %rsi,%r14
mov    %edi,%eax
mov    %rax,(%rsp)
mov    $0x1,%ebx
mov    0x2e49(%rip),%r12
lea    0xe83(%rip),%r13
jmp    11c2 <main+0x72>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <fclose@plt>
add    $0x1,%rbx
cmp    (%rsp),%rbx
jae    1178 <main+0x28>
mov    (%r14,%rbx,8),%rdx
lea    0xe33(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14,%rbx,8),%rdi
lea    0xe28(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     121f <main+0xcf>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <fgetc@plt>
cmp    (%r12),%eax
je     11b0 <main+0x60>
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1060 <fgetc@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    (%r12),%r15d
jne    1200 <main+0xb0>
jmp    11b0 <main+0x60>
mov    %ebx,%eax
mov    (%r14,%rax,8),%rsi
lea    0xddf(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Programa para verificacao de tipo de arquivo.\0A\00"
@.str.1 = [26 x i8] c"Uso: projeto nomeArquivo\0A\00"
@.str.2 = [9 x i8] c"[%d] %s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [30 x i8] c"Erro ao abrir o arquivo '%s'\0A\00"
@EOF = global i32 0
@.str.5 = [4 x i8] c"%d\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %64
15: ; preds = %2
store i32 1, i32* %6
br label %16
16: ; preds = %60, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %63
20: ; preds = %16
%21 = load i32, i32* %6
%22 = load i8**, i8*** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %21, i8* %26)
store i32* null, i32** %7
%28 = load i8**, i8*** %5
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %33, i32** %7
%34 = load i32*, i32** %7
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %43
36: ; preds = %20
%37 = load i8**, i8*** %5
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %41)
store i32 1, i32* %3
br label %64
43: ; preds = %20
store i32 0, i32* %9
%44 = load i32*, i32** %7
%45 = call i32 @fgetc(i32* %44)
store i32 %45, i32* %8
br label %46
46: ; preds = %50, %43
%47 = load i32, i32* %8
%48 = load i32, i32* @EOF
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %57
50: ; preds = %46
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
%53 = load i32*, i32** %7
%54 = call i32 @fgetc(i32* %53)
store i32 %54, i32* %8
%55 = load i32, i32* %8
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %55)
br label %46
57: ; preds = %46
%58 = load i32*, i32** %7
%59 = call i32 @fclose(i32* %58)
store i32* null, i32** %7
br label %60
60: ; preds = %57
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %16
63: ; preds = %16
store i32 0, i32* %3
br label %64
64: ; preds = %63, %36, %12
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str.2 = [9 x i8] c"[%d] %s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [30 x i8] c"Erro ao abrir o arquivo '%s'\0A\00"
@EOF = global i32 0
@.str.5 = [4 x i8] c"%d\0A\00"
@str = [46 x i8] c"Programa para verificacao de tipo de arquivo.\00"
@str.6 = [25 x i8] c"Uso: projeto nomeArquivo\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %38
6: ; preds = %4
%7 = zext i32 %0 to i64
br label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
br label %38
11: ; preds = %6, %34
%12 = phi i64 [ 1, %6 ], [ %36, %34 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = trunc i64 %12 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %15, i8* %14)
%17 = load i8*, i8** %13
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %11
%21 = and i64 %12, 4294967295
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %23)
br label %38
25: ; preds = %11
%26 = tail call i32 @fgetc(i32* %18)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %34, label %29
29: ; preds = %25, %29
%30 = tail call i32 @fgetc(i32* %18)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %30, %32
br i1 %33, label %34, label %29
34: ; preds = %29, %25
%35 = tail call i32 @fclose(i32* %18)
%36 = add nuw nsw i64 %12, 1
%37 = icmp ult i64 %36, %7
br i1 %37, label %11, label %38
38: ; preds = %34, %4, %20, %8
%39 = phi i32 [ 0, %8 ], [ 1, %20 ], [ 0, %4 ], [ 0, %34 ]
ret i32 %39
}