#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main(int argc, char *argv[]) {
  FILE *fp;
  int k, i, j, k2;
  unsigned char x1;
  char s[4096];
  puts("Aldebaro. Nov/24/2016");
  if (argc != 4) {
    printf("Usage: %s <input file> <first byte> <last>\n", argv[0]);
    puts("Example: inspectFile myfile.bin 0 30");
    exit(1);
  }
  sprintf(s, "%s", argv[1]);
  fp = fopen(s, "rb");
  if (fp == NULL) {
    puts("Erro abertura do arquivo");
    exit(1);
  }
  for (i = 0; i < atoi(argv[2]); i++) {
    fread(&x1, sizeof(unsigned char), 1, fp);
  }
  k = 0;
  for (i = atoi(argv[2]); i < atoi(argv[3]); i++, k++) {
    k2 = fread(&x1, sizeof(unsigned char), 1, fp);
    if (k2 != 1) {
      puts("End of file!");
      break;
    }
    printf("%d\t%d (decimal)\t%x (hexa)\t(%c)\n", k, (short int)x1,
           (short int)x1, x1);
  }
  puts("Happy end!");
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x4,-0x8(%rbp)
je     11da <main+0x5a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x1030(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe77(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x1030(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    122d <main+0xad>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1034(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x1034(%rbp),%eax
cmp    %ecx,%eax
jge    127c <main+0xfc>
mov    -0x18(%rbp),%rcx
lea    -0x29(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1234 <main+0xb4>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1038(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x1038(%rbp),%eax
cmp    %ecx,%eax
jge    1326 <main+0x1a6>
mov    -0x18(%rbp),%rcx
lea    -0x29(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
je     12eb <main+0x16b>
lea    0xda5(%rip),%rdi
call   1030 <puts@plt>
jmp    1326 <main+0x1a6>
mov    -0x1c(%rbp),%esi
movzbl -0x29(%rbp),%eax
movswl %ax,%edx
movzbl -0x29(%rbp),%eax
movswl %ax,%ecx
movzbl -0x29(%rbp),%r8d
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1293 <main+0x113>
lea    0xd86(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe63(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x4,%ebx
jne    12b4 <main+0x134>
mov    0x8(%r14),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xea4(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12ce <main+0x14e>
mov    %rax,%r15
mov    0x10(%r14),%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jle    1215 <main+0x95>
xor    %ebp,%ebp
lea    0xf(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
add    $0x1,%ebp
mov    0x10(%r14),%rdi
call   1090 <atoi@plt>
cmp    %eax,%ebp
jl     11f0 <main+0x70>
mov    %eax,%ebx
mov    0x18(%r14),%rdi
call   1090 <atoi@plt>
cmp    %eax,%ebx
jge    128c <main+0x10c>
lea    0xf(%rsp),%r12
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
cmp    $0x1,%eax
jne    1280 <main+0x100>
movzbl 0xf(%rsp),%ecx
lea    0xe3a(%rip),%rdi
mov    %ebp,%esi
mov    %ecx,%edx
mov    %ecx,%r8d
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x1(%rbp),%r13d
mov    0x18(%r14),%rdi
call   1090 <atoi@plt>
lea    (%rbx,%rbp,1),%ecx
add    $0x1,%ecx
mov    %r13d,%ebp
cmp    %eax,%ecx
jl     1230 <main+0xb0>
jmp    128c <main+0x10c>
lea    0xdfc(%rip),%rdi
call   1040 <puts@plt>
lea    0xe1d(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rsi
lea    0xd58(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd76(%rip),%rdi
jmp    12d5 <main+0x155>
lea    0xd95(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Aldebaro. Nov/24/2016\00"
@.str.1 = [44 x i8] c"Usage: %s <input file> <first byte> <last>\0A\00"
@.str.2 = [37 x i8] c"Example: inspectFile myfile.bin 0 30\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [25 x i8] c"Erro abertura do arquivo\00"
@.str.6 = [13 x i8] c"End of file!\00"
@.str.7 = [32 x i8] c"%d\09%d (decimal)\09%x (hexa)\09(%c)\0A\00"
@.str.8 = [11 x i8] c"Happy end!\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
%10 = alloca i32
%11 = alloca i8
%12 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %30, i32** %6
%31 = load i32*, i32** %6
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %23
%34 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %23
store i32 0, i32* %8
br label %37
37: ; preds = %47, %36
%38 = load i32, i32* %8
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 @atoi(i8* %41)
%43 = icmp slt i32 %38, %42
br i1 %43, label %44, label %50
44: ; preds = %37
%45 = load i32*, i32** %6
%46 = call i32 @fread(i8* %11, i32 1, i32 1, i32* %45)
br label %47
47: ; preds = %44
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %37
50: ; preds = %37
store i32 0, i32* %7
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32 @atoi(i8* %53)
store i32 %54, i32* %8
br label %55
55: ; preds = %80, %50
%56 = load i32, i32* %8
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 3
%59 = load i8*, i8** %58
%60 = call i32 @atoi(i8* %59)
%61 = icmp slt i32 %56, %60
br i1 %61, label %62, label %85
62: ; preds = %55
%63 = load i32*, i32** %6
%64 = call i32 @fread(i8* %11, i32 1, i32 1, i32* %63)
store i32 %64, i32* %10
%65 = load i32, i32* %10
%66 = icmp ne i32 %65, 1
br i1 %66, label %67, label %69
67: ; preds = %62
%68 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %85
69: ; preds = %62
%70 = load i32, i32* %7
%71 = load i8, i8* %11
%72 = zext i8 %71 to i16
%73 = sext i16 %72 to i32
%74 = load i8, i8* %11
%75 = zext i8 %74 to i16
%76 = sext i16 %75 to i32
%77 = load i8, i8* %11
%78 = zext i8 %77 to i32
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %70, i32 %73, i32 %76, i32 %78)
br label %80
80: ; preds = %69
%81 = load i32, i32* %8
%82 = add nsw i32 %81, 1
store i32 %82, i32* %8
%83 = load i32, i32* %7
%84 = add nsw i32 %83, 1
store i32 %84, i32* %7
br label %55
85: ; preds = %67, %55
%86 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%87 = load i32*, i32** %6
%88 = call i32 @fclose(i32* %87)
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [22 x i8] c"Aldebaro. Nov/24/2016\00"
@.str.1 = [44 x i8] c"Usage: %s <input file> <first byte> <last>\0A\00"
@.str.2 = [37 x i8] c"Example: inspectFile myfile.bin 0 30\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [25 x i8] c"Erro abertura do arquivo\00"
@.str.6 = [13 x i8] c"End of file!\00"
@.str.7 = [32 x i8] c"%d\09%d (decimal)\09%x (hexa)\09(%c)\0A\00"
@.str.8 = [11 x i8] c"Happy end!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %0, 4
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i8* @strcpy(i8* %5, i8* dereferenceable(1) %15)
%17 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %24, label %19
19: ; preds = %13
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %33, label %27
24: ; preds = %13
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %33, %19
%28 = phi i32 [ %22, %19 ], [ %38, %33 ]
%29 = getelementptr inbounds i8*, i8** %1, i64 3
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = icmp slt i32 %28, %31
br i1 %32, label %40, label %56
33: ; preds = %19, %33
%34 = phi i32 [ %36, %33 ], [ 0, %19 ]
%35 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %17)
%36 = add nuw nsw i32 %34, 1
%37 = load i8*, i8** %20
%38 = call i32 @atoi(i8* %37)
%39 = icmp slt i32 %36, %38
br i1 %39, label %33, label %27
40: ; preds = %27, %47
%41 = phi i32 [ %52, %47 ], [ 0, %27 ]
%42 = phi i32 [ %51, %47 ], [ %28, %27 ]
%43 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %17)
%44 = icmp eq i32 %43, 1
br i1 %44, label %47, label %45
45: ; preds = %40
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %56
47: ; preds = %40
%48 = load i8, i8* %3
%49 = zext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %41, i32 %49, i32 %49, i32 %49)
%51 = add nsw i32 %42, 1
%52 = add nuw nsw i32 %41, 1
%53 = load i8*, i8** %29
%54 = call i32 @atoi(i8* %53)
%55 = icmp slt i32 %51, %54
br i1 %55, label %40, label %56
56: ; preds = %47, %27, %45
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%58 = call i32 @fclose(i32* %17)
ret i32 0
}