#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned char);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  FILE *f;
  unsigned char *scr;
  char nombre[256];
  int i, leido;
  if (argc < 2)
    return 1;
  scr = malloc(65536);
  f = fopen(argv[1], "rb");
  if (!f)
    return 1;
  leido = fread(scr, 1, 65536, f);
  fclose(f);
  strcpy(nombre, argv[1]);
  nombre[strlen(nombre) - 3] = 0;
  strcat(nombre, "hex");
  f = fopen(nombre, "wt");
  for (i = 0; i < leido; i++)
    fprintf(f, "%.2X\n", scr[i]);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11af <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    12c8 <main+0x148>
mov    $0x10000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe34(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ec <main+0x6c>
movl   $0x1,-0x4(%rbp)
jmp    12c8 <main+0x148>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000,%edx
call   1040 <fread@plt>
mov    %eax,-0x128(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x120(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x3,%eax
cltq
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x120(%rbp),%rdi
lea    0xda7(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x124(%rbp)
mov    -0x124(%rbp),%eax
cmp    -0x128(%rbp),%eax
jge    12b8 <main+0x138>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x124(%rbp),%rcx
lea    0xd6f(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1070 <fprintf@plt>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    1273 <main+0xf3>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    $0x1,%ebp
cmp    $0x2,%edi
jl     1264 <main+0xe4>
mov    %rsi,%r14
mov    $0x10000,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    0x8(%r14),%rdi
lea    0xe46(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1264 <main+0xe4>
mov    %rax,%r12
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    0x8(%r14),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x3(%rax,%rbx,1)
lea    0xdf3(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
lea    0xde8(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%r12
test   %r15d,%r15d
jle    125a <main+0xda>
mov    %r15d,%ebx
xor    %ebp,%ebp
lea    0xdcf(%rip),%r14
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbp,1),%edx
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1240 <main+0xc0>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [4 x i8] c"hex\00"
@.str.2 = [3 x i8] c"wt\00"
@.str.3 = [6 x i8] c"%.2X\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [256 x i8]
%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 %14
13: ; preds = %2
store i32 1, i32* %3
br label %61
14: ; preds = %2
%15 = call i8* @malloc(i32 65536)
store i8* %15, i8** %7
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %23, label %22
22: ; preds = %14
store i32 1, i32* %3
br label %61
23: ; preds = %14
%24 = load i8*, i8** %7
%25 = load i32*, i32** %6
%26 = call i32 @fread(i8* %24, i32 1, i32 65536, i32* %25)
store i32 %26, i32* %10
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @strcpy(i8* %29, i8* %32)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = sub nsw i32 %35, 3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %37
store i8 0, i8* %38
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %42, i32** %6
store i32 0, i32* %9
br label %43
43: ; preds = %55, %23
%44 = load i32, i32* %9
%45 = load i32, i32* %10
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %58
47: ; preds = %43
%48 = load i32*, i32** %6
%49 = load i8*, i8** %7
%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 @fprintf(i32* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %53)
br label %55
55: ; preds = %47
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %43
58: ; preds = %43
%59 = load i32*, i32** %6
%60 = call i32 @fclose(i32* %59)
store i32 0, i32* %3
br label %61
61: ; preds = %58, %22, %13
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [4 x i8] c"hex\00"
@.str.2 = [3 x i8] c"wt\00"
@.str.3 = [6 x i8] c"%.2X\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %35, label %6
6: ; preds = %2
%7 = tail call dereferenceable_or_null(65536) i8* @malloc(i32 65536)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %35, label %12
12: ; preds = %6
%13 = tail call i32 @fread(i8* %7, i32 1, i32 65536, i32* %10)
%14 = tail call i32 @fclose(i32* %10)
%15 = load i8*, i8** %8
%16 = call i32 @strcpy(i8* %4, i8* %15)
%17 = call i32 @strlen(i8* %4)
%18 = add nsw i32 %17, -3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp sgt i32 %13, 0
br i1 %23, label %24, label %33
24: ; preds = %12
%25 = zext i32 %13 to i64
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ 0, %24 ], [ %31, %26 ]
%28 = getelementptr inbounds i8, i8* %7, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %29)
%31 = add nuw nsw i64 %27, 1
%32 = icmp eq i64 %31, %25
br i1 %32, label %33, label %26
33: ; preds = %26, %12
%34 = call i32 @fclose(i32* %22)
br label %35
35: ; preds = %6, %2, %33
%36 = phi i32 [ 0, %33 ], [ 1, %2 ], [ 1, %6 ]
ret i32 %36
}