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

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 %36, label %6
6: ; preds = %2
%7 = tail call i64 @malloc(i32 65536)
%8 = inttoptr i64 %7 to i8*
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %36, label %13
13: ; preds = %6
%14 = tail call i32 @fread(i8* %8, i32 1, i32 65536, i32* %11)
%15 = tail call i32 @fclose(i32* %11)
%16 = load i8*, i8** %9
%17 = call i32 @strcpy(i8* %4, i8* %16)
%18 = call i32 @strlen(i8* %4)
%19 = add nsw i32 %18, -3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp sgt i32 %14, 0
br i1 %24, label %25, label %34
25: ; preds = %13
%26 = zext i32 %14 to i64
br label %27
27: ; preds = %25, %27
%28 = phi i64 [ 0, %25 ], [ %32, %27 ]
%29 = getelementptr inbounds i8, i8* %8, i64 %28
%30 = load i8, i8* %29
%31 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %30)
%32 = add nuw nsw i64 %28, 1
%33 = icmp eq i64 %32, %26
br i1 %33, label %34, label %27
34: ; preds = %27, %13
%35 = call i32 @fclose(i32* %23)
br label %36
36: ; preds = %6, %2, %34
%37 = phi i32 [ 0, %34 ], [ 1, %2 ], [ 1, %6 ]
ret i32 %37
}