#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
main(int argc, char **argv) {
  unsigned char data[12];
  int i, n, f, fd;
  if (argc < 2) {
    printf("Uso: Hexador <fichero>\n");
    exit(0);
  }
  if ((fd = open(argv[1], O_RDONLY)) == -1) {
    perror("open");
    exit(1);
  }
  printf("{\n");
  for (f = 0;; f++) {
    n = read(fd, data, 12);
    if (n == 0)
      break;
    if (f)
      printf(",\n");
    for (i = 0; i < n; i++) {
      printf("0x%02X", data[i]);
      if (i != n - 1)
        printf(",");
    }
  }
  printf("\n};\n");
  close(fd);
}


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   $0x2,-0x8(%rbp)
jge    1195 <main+0x35>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    11cd <main+0x6d>
lea    0xe5a(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0xc,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1205 <main+0xa5>
jmp    128c <main+0x12c>
cmpl   $0x0,-0x28(%rbp)
je     121d <main+0xbd>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1279 <main+0x119>
movslq -0x20(%rbp),%rax
movzbl -0x1c(%rbp,%rax,1),%esi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1266 <main+0x106>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126b <main+0x10b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1224 <main+0xc4>
jmp    127e <main+0x11e>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e2 <main+0x82>
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
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
sub    $0x18,%rsp
cmp    $0x1,%edi
jle    127f <main+0xff>
mov    0x8(%rsi),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1292 <main+0x112>
mov    %eax,%r12d
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   1070 <read@plt>
test   %eax,%eax
je     125a <main+0xda>
mov    %eax,%ebp
lea    0xe21(%rip),%rbx
xor    %r13d,%r13d
jmp    120c <main+0x8c>
nopl   0x0(%rax)
add    $0x1,%r13d
mov    %r12d,%edi
lea    0xc(%rsp),%rsi
mov    $0xc,%edx
call   1070 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
je     125a <main+0xda>
test   %r13d,%r13d
je     121d <main+0x9d>
lea    0xdf6(%rip),%rdi
call   1040 <puts@plt>
test   %ebp,%ebp
jle    11f0 <main+0x70>
lea    -0x1(%rbp),%r15d
mov    %ebp,%ebp
xor    %r14d,%r14d
jmp    1239 <main+0xb9>
nopl   0x0(%rax)
add    $0x1,%r14
cmp    %r14,%rbp
je     11f0 <main+0x70>
movzbl 0xc(%rsp,%r14,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %r14,%r15
je     1230 <main+0xb0>
mov    $0x2c,%edi
call   1030 <putchar@plt>
jmp    1230 <main+0xb0>
lea    0xdaf(%rip),%rdi
call   1040 <puts@plt>
mov    %r12d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8e(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xd67(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Uso: Hexador <fichero>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [3 x i8] c"{\0A\00"
@.str.3 = [3 x i8] c",\0A\00"
@.str.4 = [7 x i8] c"0x%02X\00"
@.str.5 = [2 x i8] c",\00"
@.str.6 = [5 x i8] c"\0A};\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [12 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %10
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %16
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %9
br label %28
28: ; preds = %63, %26
%29 = load i32, i32* %10
%30 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 12)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
br label %66
35: ; preds = %28
%36 = load i32, i32* %9
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
store i32 0, i32* %7
br label %41
41: ; preds = %59, %40
%42 = load i32, i32* %7
%43 = load i32, i32* %8
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %62
45: ; preds = %41
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %7
%53 = load i32, i32* %8
%54 = sub nsw i32 %53, 1
%55 = icmp ne i32 %52, %54
br i1 %55, label %56, label %58
56: ; preds = %45
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %58
58: ; preds = %56, %45
br label %59
59: ; preds = %58
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
store i32 %61, i32* %7
br label %41
62: ; preds = %41
br label %63
63: ; preds = %62
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 1
store i32 %65, i32* %9
br label %28
66: ; preds = %34
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%68 = load i32, i32* %10
%69 = call i32 @close(i32 %68)
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.4 = [7 x i8] c"0x%02X\00"
@str = [2 x i8] c"{\00"
@str.7 = [2 x i8] c",\00"
@str.8 = [4 x i8] c"\0A};\00"
@str.9 = [23 x i8] c"Uso: Hexador <fichero>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [12 x i8]
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.9, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%20 = call i32 @read(i32 %13, i8* %4, i32 12)
%21 = icmp eq i32 %20, 0
br i1 %21, label %50, label %22
22: ; preds = %18, %46
%23 = phi i32 [ %48, %46 ], [ %20, %18 ]
%24 = phi i32 [ %47, %46 ], [ 0, %18 ]
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.7, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = icmp sgt i32 %23, 0
br i1 %29, label %30, label %46
30: ; preds = %28
%31 = add nsw i32 %23, -1
%32 = zext i32 %31 to i64
%33 = zext i32 %23 to i64
br label %34
34: ; preds = %30, %43
%35 = phi i64 [ 0, %30 ], [ %44, %43 ]
%36 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = icmp eq i64 %35, %32
br i1 %40, label %43, label %41
41: ; preds = %34
%42 = tail call i32 @putchar(i32 44)
br label %43
43: ; preds = %34, %41
%44 = add nuw nsw i64 %35, 1
%45 = icmp eq i64 %44, %33
br i1 %45, label %46, label %34
46: ; preds = %43, %28
%47 = add nuw nsw i32 %24, 1
%48 = call i32 @read(i32 %13, i8* %4, i32 12)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %22
50: ; preds = %46, %18
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.8, i64 0, i64 0))
%52 = tail call i32 @close(i32 %13)
ret i32 0
}