#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 uint32_t;

/* Variables and functions */
unsigned char *asciihex2hexbytes(int *, unsigned char *);
int /*<<< orphan*/ exit(int);
scalar_t__ open_file(char *, int *, unsigned char **);
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ puts(char *);
int main(int argc, char *argv[]) {
  if (!argv[1]) {
    puts("Usage: ./a.out <filename>");
    exit(1);
  }
  unsigned char *buf;
  uint32_t inlen;
  if (open_file(argv[1], &inlen, (unsigned char **)&buf)) {
    puts("error loading file content");
    return 1;
  }
  for (int i = 0; i < inlen; i++)
    printf("%02hhx", buf[i]);
  puts("");
  buf = asciihex2hexbytes(&inlen, buf);
  for (int i = 0; i < inlen; i++)
    printf("%02hhx", buf[i]);
  puts("");
  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)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    118b <main+0x3b>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <open_file@plt>
cmp    $0x0,%rax
je     11c2 <main+0x72>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1264 <main+0x114>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11fb <main+0xab>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
lea    0xe51(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c9 <main+0x79>
lea    0xe17(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
call   1070 <asciihex2hexbytes@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1251 <main+0x101>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
lea    0xdfb(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    121f <main+0xcf>
lea    0xdc1(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     1253 <main+0xf3>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1050 <open_file@plt>
test   %rax,%rax
je     119e <main+0x3e>
lea    0xe8b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    124b <main+0xeb>
cmpl   $0x0,0xc(%rsp)
jle    11cf <main+0x6f>
xor    %ebx,%ebx
lea    0xe87(%rip),%r14
xchg   %ax,%ax
mov    0x10(%rsp),%rax
movzbl (%rax,%rbx,1),%esi
mov    %r14,%rdi
call   1060 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11b0 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdi
call   1080 <asciihex2hexbytes@plt>
mov    %rax,0x10(%rsp)
cmpl   $0x0,0xc(%rsp)
jle    123f <main+0xdf>
movzbl (%rax),%esi
lea    0xe37(%rip),%rdi
call   1060 <printf@plt>
cmpl   $0x2,0xc(%rsp)
jl     123f <main+0xdf>
mov    $0x1,%ebx
lea    0xe1f(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
movzbl (%rax,%rbx,1),%esi
mov    %r14,%rdi
call   1060 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1220 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xda6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Usage: ./a.out <filename>\00"
@.str.1 = [27 x i8] c"error loading file content\00"
@.str.2 = [7 x i8] c"%02hhx\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%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 i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @open_file(i8* %20, i32* %7, i8** %6)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %60
25: ; preds = %17
store i32 0, i32* %8
br label %26
26: ; preds = %37, %25
%27 = load i32, i32* %8
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = load i8*, i8** %6
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %35)
br label %37
37: ; preds = %30
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %26
40: ; preds = %26
%41 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%42 = load i8*, i8** %6
%43 = call i8* @asciihex2hexbytes(i32* %7, i8* %42)
store i8* %43, i8** %6
store i32 0, i32* %9
br label %44
44: ; preds = %55, %40
%45 = load i32, i32* %9
%46 = load i32, i32* %7
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %58
48: ; preds = %44
%49 = load i8*, i8** %6
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %53)
br label %55
55: ; preds = %48
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %44
58: ; preds = %44
%59 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %60
60: ; preds = %58, %23
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [26 x i8] c"Usage: ./a.out <filename>\00"
@.str.1 = [27 x i8] c"error loading file content\00"
@.str.2 = [7 x i8] c"%02hhx\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = bitcast i8** %3 to i8*
%13 = bitcast i32* %4 to i8*
%14 = call i64 @open_file(i8* %6, i32* %4, i8** %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %32, label %21
19: ; preds = %11
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %54
21: ; preds = %32, %16
%22 = call i32 @putchar(i32 10)
%23 = load i8*, i8** %3
%24 = call i8* @asciihex2hexbytes(i32* %4, i8* %23)
store i8* %24, i8** %3
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %21
%28 = load i8, i8* %24
%29 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %28)
%30 = load i32, i32* %4
%31 = icmp sgt i32 %30, 1
br i1 %31, label %44, label %42
32: ; preds = %16, %32
%33 = phi i64 [ %38, %32 ], [ 0, %16 ]
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 %33
%36 = load i8, i8* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %36)
%38 = add nuw nsw i64 %33, 1
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %38, %40
br i1 %41, label %32, label %21
42: ; preds = %44, %27, %21
%43 = call i32 @putchar(i32 10)
br label %54
44: ; preds = %27, %44
%45 = phi i64 [ %50, %44 ], [ 1, %27 ]
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 %45
%48 = load i8, i8* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %48)
%50 = add nuw nsw i64 %45, 1
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = icmp slt i64 %50, %52
br i1 %53, label %44, label %42
54: ; preds = %42, %19
%55 = phi i32 [ 1, %19 ], [ 0, %42 ]
ret i32 %55
}