#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 errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  const char hex[] = "0123456789ABCDEF";
  char buf[16];
  char line[80];
  int i, j, k;
  unsigned addr = 0;
  FILE *fi = stdin, *fo = stdout;
  errno = 0;
  for (i = 0; i < 80; i++)
    line[i] = ' ';
  if (argc > 1 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-h") ||
                   !strcmp(argv[1], "--help"))) {
    fprintf(stderr, "Usage: tohex [infile [outfile]]\n\n"
                    "  'infile' and 'outfile' default to stdin and stdout.\n\n"
                    "  Use 'tohex - outfile' to use stdin for infile while\n"
                    "  still specifying an output file.\n\n");
    exit(1);
  }
  if (argc > 1 && argv[1][0] != '-') {
    fi = fopen(argv[1], "rb");
    if (!fi) {
      perror("fopen()");
      fprintf(stderr, "Couldn't open '%s' for reading.\n", argv[1]);
      exit(1);
    }
  }
  if (argc > 2) {
    fo = fopen(argv[2], "w");
    if (!fo) {
      perror("fopen()");
      fprintf(stderr, "Couldn't open '%s' for reading.\n", argv[2]);
      exit(1);
    }
  }
  while (!feof(fi)) {
    if (!(i = fread(buf, 1, 16, fi)))
      break;
    line[52] = '#';
    line[79] = '\n';
    for (j = i; j < 16; j++) {
      k = 1 + j * 3 + 2 * (j > 7);
      line[k] = ' ';
      line[k + 1] = ' ';
      line[k + 2] = ' ';
      line[54 + j] = ' ';
    }
    for (j = 0; j < i; j++) {
      k = 1 + j * 3 + 2 * (j > 7);
      line[k] = hex[(buf[j] >> 4) & 0x0f];
      line[k + 1] = hex[buf[j] & 0x0f];
      line[54 + j] = (buf[j] >= 32) && (buf[j] < 127) ? buf[j] : '.';
    }
    for (j = 0; j < 8; j++)
      line[78 - j] = hex[(addr >> (j * 4)) & 0xF];
    fwrite(line, 1, 80, fo);
    addr += 16;
  }
  return errno;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe60(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe5d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe5b(%rip),%al
mov    %al,-0x20(%rbp)
movl   $0x0,-0xa0(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2dee(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xb0(%rbp)
mov    0x2de5(%rip),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x94(%rbp)
cmpl   $0x50,-0x94(%rbp)
jge    122b <main+0xab>
movslq -0x94(%rbp),%rax
movb   $0x20,-0x90(%rbp,%rax,1)
20
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11fb <main+0x7b>
cmpl   $0x1,-0x8(%rbp)
jle    12ad <main+0x12d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdcd(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     128c <main+0x10c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb3(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     128c <main+0x10c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd99(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    12ad <main+0x12d>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
jle    132e <main+0x1ae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     132e <main+0x1ae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jne    1329 <main+0x1a9>
lea    0xdd9(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    132e <main+0x1ae>
cmpl   $0x2,-0x8(%rbp)
jle    139b <main+0x21b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdb6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xb0(%rbp)
cmpq   $0x0,-0xb0(%rbp)
jne    1396 <main+0x216>
lea    0xd6c(%rip),%rdi
call   1080 <perror@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    139b <main+0x21b>
jmp    13a0 <main+0x220>
mov    -0xa8(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    13c1 <main+0x241>
jmp    1628 <main+0x4a8>
lea    -0x40(%rbp),%rdi
mov    -0xa8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1030 <fread@plt>
mov    %eax,-0x94(%rbp)
cmp    $0x0,%eax
jne    13ef <main+0x26f>
jmp    1628 <main+0x4a8>
movb   $0x23,-0x5c(%rbp)
movb   $0xa,-0x41(%rbp)
mov    -0x94(%rbp),%eax
mov    %eax,-0x98(%rbp)
cmpl   $0x10,-0x98(%rbp)
jge    1491 <main+0x311>
imul   $0x3,-0x98(%rbp),%eax
add    $0x1,%eax
cmpl   $0x7,-0x98(%rbp)
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x9c(%rbp)
movslq -0x9c(%rbp),%rax
movb   $0x20,-0x90(%rbp,%rax,1)
20
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x20,-0x90(%rbp,%rax,1)
20
mov    -0x9c(%rbp),%eax
add    $0x2,%eax
cltq
movb   $0x20,-0x90(%rbp,%rax,1)
20
mov    -0x98(%rbp),%eax
add    $0x36,%eax
cltq
movb   $0x20,-0x90(%rbp,%rax,1)
20
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    1403 <main+0x283>
movl   $0x0,-0x98(%rbp)
mov    -0x98(%rbp),%eax
cmp    -0x94(%rbp),%eax
jge    159e <main+0x41e>
imul   $0x3,-0x98(%rbp),%eax
add    $0x1,%eax
cmpl   $0x7,-0x98(%rbp)
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x9c(%rbp)
movslq -0x98(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
sar    $0x4,%eax
and    $0xf,%eax
cltq
mov    -0x30(%rbp,%rax,1),%cl
movslq -0x9c(%rbp),%rax
mov    %cl,-0x90(%rbp,%rax,1)
movslq -0x98(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
and    $0xf,%eax
cltq
mov    -0x30(%rbp,%rax,1),%cl
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x90(%rbp,%rax,1)
movslq -0x98(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jl     1560 <main+0x3e0>
movslq -0x98(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x7f,%eax
jge    1560 <main+0x3e0>
movslq -0x98(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
mov    %eax,-0xb4(%rbp)
jmp    1570 <main+0x3f0>
mov    $0x2e,%eax
mov    %eax,-0xb4(%rbp)
jmp    1570 <main+0x3f0>
mov    -0xb4(%rbp),%eax
mov    %al,%cl
mov    -0x98(%rbp),%eax
add    $0x36,%eax
cltq
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    149b <main+0x31b>
movl   $0x0,-0x98(%rbp)
cmpl   $0x8,-0x98(%rbp)
jge    15f7 <main+0x477>
mov    -0xa0(%rbp),%eax
mov    -0x98(%rbp),%ecx
shl    $0x2,%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %eax,%eax
mov    -0x30(%rbp,%rax,1),%cl
mov    $0x4e,%eax
sub    -0x98(%rbp),%eax
cltq
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    15a8 <main+0x428>
lea    -0x90(%rbp),%rdi
mov    -0xb0(%rbp),%rcx
mov    $0x1,%esi
mov    $0x50,%edx
call   10a0 <fwrite@plt>
mov    -0xa0(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0xa0(%rbp)
jmp    13a0 <main+0x220>
mov    0x29a1(%rip),%rax
mov    (%rax),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    0x2e53(%rip),%rax
mov    (%rax),%r15
mov    0x2e29(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
mov    0x2e22(%rip),%rax
movl   $0x0,(%rax)
movaps 0xe45(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
cmp    $0x2,%edi
jl     1271 <main+0xf1>
mov    %rsi,%rbx
mov    %edi,%r12d
mov    0x8(%rsi),%rbp
lea    0xe33(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1445 <main+0x2c5>
lea    0xe1f(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1445 <main+0x2c5>
lea    0xe0b(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1445 <main+0x2c5>
cmpb   $0x2d,0x0(%rbp)
je     124d <main+0xcd>
lea    0xea8(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     1466 <main+0x2e6>
cmp    $0x3,%r12d
jb     1271 <main+0xf1>
mov    0x10(%rbx),%rdi
lea    0xeaf(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1481 <main+0x301>
mov    %r15,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1295 <main+0x115>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
lea    0xd71(%rip),%r13
mov    $0x2e,%r12d
jmp    1357 <main+0x1d7>
nopw   0x0(%rax,%rax,1)
movb   $0x30,0x5e(%rsp)
mov    %r14d,%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    (%rax,%r13,1),%al
mov    %al,0x5d(%rsp)
mov    %r14d,%eax
shr    $0x8,%eax
and    $0xf,%eax
mov    (%rax,%r13,1),%al
mov    %al,0x5c(%rsp)
mov    %r14d,%eax
shr    $0xc,%eax
and    $0xf,%eax
mov    (%rax,%r13,1),%al
mov    %al,0x5b(%rsp)
mov    %r14d,%eax
shr    $0x10,%eax
and    $0xf,%eax
mov    (%rax,%r13,1),%al
mov    %al,0x5a(%rsp)
mov    %r14d,%eax
shr    $0x14,%eax
and    $0xf,%eax
mov    (%rax,%r13,1),%al
mov    %al,0x59(%rsp)
mov    %r14d,%eax
shr    $0x18,%eax
and    $0xf,%eax
mov    (%rax,%r13,1),%al
mov    %al,0x58(%rsp)
mov    %r14d,%eax
shr    $0x1c,%rax
mov    (%rax,%r13,1),%al
mov    %al,0x57(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x50,%edx
mov    0x8(%rsp),%rcx
call   10a0 <fwrite@plt>
add    $0x10,%r14d
mov    %r15,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    127d <main+0xfd>
lea    0x60(%rsp),%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     127d <main+0xfd>
mov    %eax,%r8d
movb   $0x23,0x44(%rsp)
movb   $0xa,0x5f(%rsp)
cmp    $0xf,%r8d
jg     13e6 <main+0x266>
movslq %r8d,%rcx
lea    (%rcx,%rcx,2),%edx
add    $0x3,%edx
lea    0x46(%rsp),%rax
lea    (%rax,%rcx,1),%rsi
xor    %edi,%edi
nopl   (%rax)
lea    (%rcx,%rdi,1),%rbx
xor    %ebp,%ebp
cmp    $0x8,%rbx
setge  %bpl
lea    (%rdx,%rbp,2),%ebx
lea    (%rdx,%rbp,2),%ebp
add    $0xfffffffe,%ebp
movslq %ebp,%rbp
movw   $0x2020,0x10(%rsp,%rbp,1)
movslq %ebx,%rbp
movb   $0x20,0x10(%rsp,%rbp,1)
movb   $0x20,(%rsi,%rdi,1)
add    $0x3,%edx
add    $0x1,%rdi
lea    (%rdi,%r8,1),%ebp
cmp    $0x10,%ebp
jne    13a0 <main+0x220>
test   %r8d,%r8d
jle    12b0 <main+0x130>
mov    $0x1,%ecx
xor    %edx,%edx
nopl   (%rax)
xor    %esi,%esi
cmp    $0x8,%rdx
setae  %sil
lea    (%rcx,%rsi,2),%edi
movzbl 0x60(%rsp,%rdx,1),%ebx
mov    %rbx,%rbp
shr    $0x4,%rbp
movzbl 0x0(%rbp,%r13,1),%eax
mov    %al,0x10(%rsp,%rdi,1)
mov    %ebx,%eax
and    $0xf,%eax
movzbl (%rax,%r13,1),%eax
lea    (%rcx,%rsi,2),%esi
add    $0x1,%esi
mov    %al,0x10(%rsp,%rsi,1)
lea    -0x7f(%rbx),%eax
cmp    $0xa1,%al
cmovb  %r12d,%ebx
mov    %bl,0x46(%rsp,%rdx,1)
add    $0x1,%rdx
add    $0x3,%ecx
cmp    %rdx,%r8
jne    13f0 <main+0x270>
jmp    12b0 <main+0x130>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
lea    0xbd9(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xc77(%rip),%rdi
call   1080 <perror@plt>
mov    0x2b5f(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
jmp    149a <main+0x31a>
lea    0xc5c(%rip),%rdi
call   1080 <perror@plt>
mov    0x2b44(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xc4b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.hex = [17 x i8] c"0123456789ABCDEF\00"
@stdin = global i32* null
@stdout = global i32* null
@errno = global i32 0
@.str = [3 x i8] c"-?\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [7 x i8] c"--help\00"
@stderr = global i32 0
@.str.3 = [179 x i8] c"Usage: tohex [infile [outfile]]\0A\0A 'infile' and 'outfile' default to stdin and stdout.\0A\0A Use 'tohex - outfile' to use stdin for infile while\0A still specifying an output file.\0A\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [8 x i8] c"fopen()\00"
@.str.6 = [33 x i8] c"Couldn't open '%s' for reading.\0A\00"
@.str.7 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [17 x i8]
%7 = alloca [16 x i8]
%8 = alloca [80 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = bitcast [17 x i8]* %6 to i8*
store i32 0, i32* %12
%16 = load i32*, i32** @stdin
store i32* %16, i32** %13
%17 = load i32*, i32** @stdout
store i32* %17, i32** %14
store i32 0, i32* @errno
store i32 0, i32* %9
br label %18
18: ; preds = %25, %2
%19 = load i32, i32* %9
%20 = icmp slt i32 %19, 80
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %23
store i8 32, i8* %24
br label %25
25: ; preds = %21
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
store i32 %27, i32* %9
br label %18
28: ; preds = %18
%29 = load i32, i32* %4
%30 = icmp sgt i32 %29, 1
br i1 %30, label %31, label %53
31: ; preds = %28
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %49
37: ; preds = %31
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @strcmp(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %37
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 @strcmp(i8* %46, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%48 = icmp ne i32 %47, 0
br i1 %48, label %53, label %49
49: ; preds = %43, %37, %31
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([179 x i8], [179 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %43, %28
%54 = load i32, i32* %4
%55 = icmp sgt i32 %54, 1
br i1 %55, label %56, label %80
56: ; preds = %53
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = getelementptr inbounds i8, i8* %59, i64 0
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 45
br i1 %63, label %64, label %80
64: ; preds = %56
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %68, i32** %13
%69 = load i32*, i32** %13
%70 = icmp ne i32* %69, null
br i1 %70, label %79, label %71
71: ; preds = %64
%72 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%73 = load i32, i32* @stderr
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 1
%76 = load i8*, i8** %75
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %76)
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %64
br label %80
80: ; preds = %79, %56, %53
%81 = load i32, i32* %4
%82 = icmp sgt i32 %81, 2
br i1 %82, label %83, label %99
83: ; preds = %80
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 2
%86 = load i8*, i8** %85
%87 = call i32* @fopen(i8* %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %87, i32** %14
%88 = load i32*, i32** %14
%89 = icmp ne i32* %88, null
br i1 %89, label %98, label %90
90: ; preds = %83
%91 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%92 = load i32, i32* @stderr
%93 = load i8**, i8*** %5
%94 = getelementptr inbounds i8*, i8** %93, i64 2
%95 = load i8*, i8** %94
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %95)
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %83
br label %99
99: ; preds = %98, %80
br label %100
100: ; preds = %235, %99
%101 = load i32*, i32** %13
%102 = call i32 @feof(i32* %101)
%103 = icmp ne i32 %102, 0
%104 = xor i1 %103, true
br i1 %104, label %105, label %241
105: ; preds = %100
%106 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%107 = load i32*, i32** %13
%108 = call i32 @fread(i8* %106, i32 1, i32 16, i32* %107)
store i32 %108, i32* %9
%109 = icmp ne i32 %108, 0
br i1 %109, label %111, label %110
110: ; preds = %105
br label %241
111: ; preds = %105
%112 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 52
store i8 35, i8* %112
%113 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 79
store i8 10, i8* %113
%114 = load i32, i32* %9
store i32 %114, i32* %10
br label %115
115: ; preds = %142, %111
%116 = load i32, i32* %10
%117 = icmp slt i32 %116, 16
br i1 %117, label %118, label %145
118: ; preds = %115
%119 = load i32, i32* %10
%120 = mul nsw i32 %119, 3
%121 = add nsw i32 1, %120
%122 = load i32, i32* %10
%123 = icmp sgt i32 %122, 7
%124 = zext i1 %123 to i32
%125 = mul nsw i32 2, %124
%126 = add nsw i32 %121, %125
store i32 %126, i32* %11
%127 = load i32, i32* %11
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %128
store i8 32, i8* %129
%130 = load i32, i32* %11
%131 = add nsw i32 %130, 1
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %132
store i8 32, i8* %133
%134 = load i32, i32* %11
%135 = add nsw i32 %134, 2
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %136
store i8 32, i8* %137
%138 = load i32, i32* %10
%139 = add nsw i32 54, %138
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %140
store i8 32, i8* %141
br label %142
142: ; preds = %118
%143 = load i32, i32* %10
%144 = add nsw i32 %143, 1
store i32 %144, i32* %10
br label %115
145: ; preds = %115
store i32 0, i32* %10
br label %146
146: ; preds = %212, %145
%147 = load i32, i32* %10
%148 = load i32, i32* %9
%149 = icmp slt i32 %147, %148
br i1 %149, label %150, label %215
150: ; preds = %146
%151 = load i32, i32* %10
%152 = mul nsw i32 %151, 3
%153 = add nsw i32 1, %152
%154 = load i32, i32* %10
%155 = icmp sgt i32 %154, 7
%156 = zext i1 %155 to i32
%157 = mul nsw i32 2, %156
%158 = add nsw i32 %153, %157
store i32 %158, i32* %11
%159 = load i32, i32* %10
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %160
%162 = load i8, i8* %161
%163 = sext i8 %162 to i32
%164 = ashr i32 %163, 4
%165 = and i32 %164, 15
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 %166
%168 = load i8, i8* %167
%169 = load i32, i32* %11
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %170
store i8 %168, i8* %171
%172 = load i32, i32* %10
%173 = sext i32 %172 to i64
%174 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %173
%175 = load i8, i8* %174
%176 = sext i8 %175 to i32
%177 = and i32 %176, 15
%178 = sext i32 %177 to i64
%179 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 %178
%180 = load i8, i8* %179
%181 = load i32, i32* %11
%182 = add nsw i32 %181, 1
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %183
store i8 %180, i8* %184
%185 = load i32, i32* %10
%186 = sext i32 %185 to i64
%187 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %186
%188 = load i8, i8* %187
%189 = sext i8 %188 to i32
%190 = icmp sge i32 %189, 32
br i1 %190, label %191, label %204
191: ; preds = %150
%192 = load i32, i32* %10
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %193
%195 = load i8, i8* %194
%196 = sext i8 %195 to i32
%197 = icmp slt i32 %196, 127
br i1 %197, label %198, label %204
198: ; preds = %191
%199 = load i32, i32* %10
%200 = sext i32 %199 to i64
%201 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %200
%202 = load i8, i8* %201
%203 = sext i8 %202 to i32
br label %205
204: ; preds = %191, %150
br label %205
205: ; preds = %204, %198
%206 = phi i32 [ %203, %198 ], [ 46, %204 ]
%207 = trunc i32 %206 to i8
%208 = load i32, i32* %10
%209 = add nsw i32 54, %208
%210 = sext i32 %209 to i64
%211 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %210
store i8 %207, i8* %211
br label %212
212: ; preds = %205
%213 = load i32, i32* %10
%214 = add nsw i32 %213, 1
store i32 %214, i32* %10
br label %146
215: ; preds = %146
store i32 0, i32* %10
br label %216
216: ; preds = %232, %215
%217 = load i32, i32* %10
%218 = icmp slt i32 %217, 8
br i1 %218, label %219, label %235
219: ; preds = %216
%220 = load i32, i32* %12
%221 = load i32, i32* %10
%222 = mul nsw i32 %221, 4
%223 = lshr i32 %220, %222
%224 = and i32 %223, 15
%225 = zext i32 %224 to i64
%226 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 %225
%227 = load i8, i8* %226
%228 = load i32, i32* %10
%229 = sub nsw i32 78, %228
%230 = sext i32 %229 to i64
%231 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %230
store i8 %227, i8* %231
br label %232
232: ; preds = %219
%233 = load i32, i32* %10
%234 = add nsw i32 %233, 1
store i32 %234, i32* %10
br label %216
235: ; preds = %216
%236 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%237 = load i32*, i32** %14
%238 = call i32 @fwrite(i8* %236, i32 1, i32 80, i32* %237)
%239 = load i32, i32* %12
%240 = add i32 %239, 16
store i32 %240, i32* %12
br label %100
241: ; preds = %110, %100
%242 = load i32, i32* @errno
ret i32 %242
}

LLVM IR (-O2):
@__const.main.hex = [17 x i8] c"0123456789ABCDEF\00"
@stdin = global i32* null
@stdout = global i32* null
@errno = global i32 0
@.str = [3 x i8] c"-?\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [7 x i8] c"--help\00"
@stderr = global i32 0
@.str.3 = [179 x i8] c"Usage: tohex [infile [outfile]]\0A\0A 'infile' and 'outfile' default to stdin and stdout.\0A\0A Use 'tohex - outfile' to use stdin for infile while\0A still specifying an output file.\0A\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [8 x i8] c"fopen()\00"
@.str.6 = [33 x i8] c"Couldn't open '%s' for reading.\0A\00"
@.str.7 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%8 = load i32*, i32** @stdin
%9 = load i32*, i32** @stdout
store i32 0, i32* @errno
%10 = icmp sgt i32 %0, 1
br i1 %10, label %11, label %52
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %11
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19, %16, %11
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([179 x i8], [179 x i8]* @.str.3, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %19
%27 = load i8, i8* %13
%28 = icmp eq i8 %27, 45
br i1 %28, label %38, label %29
29: ; preds = %26
%30 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %12
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %35)
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %29, %26
%39 = phi i32* [ %30, %29 ], [ %8, %26 ]
%40 = icmp ugt i32 %0, 2
br i1 %40, label %41, label %52
41: ; preds = %38
%42 = getelementptr inbounds i8*, i8** %1, i64 2
%43 = load i8*, i8** %42
%44 = tail call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %52
46: ; preds = %41
%47 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %42
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %49)
%51 = tail call i32 @exit(i32 1)
unreachable
52: ; preds = %2, %41, %38
%53 = phi i32* [ %39, %41 ], [ %39, %38 ], [ %8, %2 ]
%54 = phi i32* [ %44, %41 ], [ %9, %38 ], [ %9, %2 ]
%55 = tail call i32 @feof(i32* %53)
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %170
57: ; preds = %52
%58 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 52
%59 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 79
%60 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 78
%61 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 77
%62 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 76
%63 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 75
%64 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 74
%65 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 73
%66 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 72
%67 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 71
br label %68
68: ; preds = %57, %101
%69 = phi i32 [ 0, %57 ], [ %137, %101 ]
%70 = call i32 @fread(i8* %6, i32 1, i32 16, i32* %53)
%71 = icmp eq i32 %70, 0
br i1 %71, label %170, label %72
72: ; preds = %68
store i8 35, i8* %58
store i8 10, i8* %59
%73 = icmp slt i32 %70, 16
br i1 %73, label %74, label %78
74: ; preds = %72
%75 = sext i32 %70 to i64
br label %80
76: ; preds = %80
%77 = icmp sgt i32 %70, 0
br i1 %77, label %78, label %101
78: ; preds = %72, %76
%79 = zext i32 %70 to i64
br label %140
80: ; preds = %74, %80
%81 = phi i64 [ %75, %74 ], [ %98, %80 ]
%82 = icmp sgt i64 %81, 7
%83 = select i1 %82, i32 2, i32 0
%84 = trunc i64 %81 to i32
%85 = mul i32 %84, 3
%86 = add i32 %85, 1
%87 = add nsw i32 %86, %83
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %88
store i8 32, i8* %89
%90 = add nsw i32 %87, 1
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %91
store i8 32, i8* %92
%93 = add nsw i32 %87, 2
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %94
store i8 32, i8* %95
%96 = add nsw i64 %81, 54
%97 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %96
store i8 32, i8* %97
%98 = add nsw i64 %81, 1
%99 = trunc i64 %98 to i32
%100 = icmp eq i32 %99, 16
br i1 %100, label %76, label %80
101: ; preds = %140, %76
store i8 48, i8* %60
%102 = lshr exact i32 %69, 4
%103 = and i32 %102, 15
%104 = zext i32 %103 to i64
%105 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.main.hex, i64 0, i64 %104
%106 = load i8, i8* %105
store i8 %106, i8* %61
%107 = lshr i32 %69, 8
%108 = and i32 %107, 15
%109 = zext i32 %108 to i64
%110 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.main.hex, i64 0, i64 %109
%111 = load i8, i8* %110
store i8 %111, i8* %62
%112 = lshr i32 %69, 12
%113 = and i32 %112, 15
%114 = zext i32 %113 to i64
%115 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.main.hex, i64 0, i64 %114
%116 = load i8, i8* %115
store i8 %116, i8* %63
%117 = lshr i32 %69, 16
%118 = and i32 %117, 15
%119 = zext i32 %118 to i64
%120 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.main.hex, i64 0, i64 %119
%121 = load i8, i8* %120
store i8 %121, i8* %64
%122 = lshr i32 %69, 20
%123 = and i32 %122, 15
%124 = zext i32 %123 to i64
%125 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.main.hex, i64 0, i64 %124
%126 = load i8, i8* %125
store i8 %126, i8* %65
%127 = lshr i32 %69, 24
%128 = and i32 %127, 15
%129 = zext i32 %128 to i64
%130 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.main.hex, i64 0, i64 %129
%131 = load i8, i8* %130
store i8 %131, i8* %66
%132 = lshr i32 %69, 28
%133 = zext i32 %132 to i64
%134 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.main.hex, i64 0, i64 %133
%135 = load i8, i8* %134
store i8 %135, i8* %67
%136 = call i32 @fwrite(i8* %7, i32 1, i32 80, i32* %54)
%137 = add i32 %69, 16
%138 = tail call i32 @feof(i32* %53)
%139 = icmp eq i32 %138, 0
br i1 %139, label %68, label %170
140: ; preds = %78, %140
%141 = phi i64 [ 0, %78 ], [ %168, %140 ]
%142 = icmp ugt i64 %141, 7
%143 = select i1 %142, i32 2, i32 0
%144 = trunc i64 %141 to i32
%145 = mul i32 %144, 3
%146 = add i32 %145, 1
%147 = add nuw nsw i32 %146, %143
%148 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %141
%149 = load i8, i8* %148
%150 = lshr i8 %149, 4
%151 = zext i8 %150 to i64
%152 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.main.hex, i64 0, i64 %151
%153 = load i8, i8* %152
%154 = zext i32 %147 to i64
%155 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %154
store i8 %153, i8* %155
%156 = and i8 %149, 15
%157 = zext i8 %156 to i64
%158 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.main.hex, i64 0, i64 %157
%159 = load i8, i8* %158
%160 = add nuw nsw i32 %147, 1
%161 = zext i32 %160 to i64
%162 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %161
store i8 %159, i8* %162
%163 = add i8 %149, -127
%164 = icmp ult i8 %163, -95
%165 = select i1 %164, i8 46, i8 %149
%166 = add nuw nsw i64 %141, 54
%167 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %166
store i8 %165, i8* %167
%168 = add nuw nsw i64 %141, 1
%169 = icmp eq i64 %168, %79
br i1 %169, label %101, label %140
170: ; preds = %101, %68, %52
%171 = load i32, i32* @errno
ret i32 %171
}