#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 uint16_t;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
size_t fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  FILE *infile = stdin;
  FILE *outfile = stdout;
  if (argc >= 2) {
    infile = fopen(argv[1], "rb");
    if (!infile) {
      fprintf(stderr, "Error opening input: %s\n", argv[1]);
      exit(1);
    }
  }
  if (argc >= 3) {
    outfile = fopen(argv[2], "w");
    if (!outfile) {
      fprintf(stderr, "Error opening output: %s\n", argv[2]);
      exit(1);
    }
  }
  uint16_t buf;
  size_t bytes;
  while ((bytes = fread(&buf, sizeof(buf), 1, infile)) > 0) {
    fprintf(outfile, "%04x\n", buf);
  }
  exit(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    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11ce <main+0x8e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe75(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c9 <main+0x89>
mov    0x2e32(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11ce <main+0x8e>
cmpl   $0x3,-0x8(%rbp)
jl     122a <main+0xea>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe35(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1225 <main+0xe5>
mov    0x2dd6(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    122a <main+0xea>
jmp    122f <main+0xef>
mov    -0x18(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jbe    126e <main+0x12e>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    122f <main+0xef>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e81(%rip),%rax
mov    (%rax),%r14
cmp    $0x2,%edi
jl     118f <main+0x4f>
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
lea    0xe99(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
jne    1202 <main+0xc2>
mov    0x2e5c(%rip),%rax
movslq (%rax),%rdi
mov    0x8(%r15),%rdx
lea    0xe79(%rip),%rsi
jmp    123b <main+0xfb>
mov    0x2e52(%rip),%rax
mov    (%rax),%r12
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11fb <main+0xbb>
lea    0xe7c(%rip),%r15
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x4(%rsp),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    11d0 <main+0x90>
xor    %edi,%edi
call   1060 <exit@plt>
mov    %rax,%r12
cmp    $0x3,%ebx
jb     1199 <main+0x59>
mov    0x10(%r15),%rdi
lea    0xe07(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1199 <main+0x59>
mov    0x2dab(%rip),%rax
movslq (%rax),%rdi
mov    0x10(%r15),%rdx
lea    0xde3(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32* null
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Error opening input: %s\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [26 x i8] c"Error opening output: %s\0A\00"
@.str.4 = [6 x i8] c"%04x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32*, i32** @stdin
store i32* %10, i32** %6
%11 = load i32*, i32** @stdout
store i32* %11, i32** %7
%12 = load i32, i32* %4
%13 = icmp sge i32 %12, 2
br i1 %13, label %14, label %31
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %30, label %21
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i32*
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %14
br label %31
31: ; preds = %30, %2
%32 = load i32, i32* %4
%33 = icmp sge i32 %32, 3
br i1 %33, label %34, label %51
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %7
%39 = load i32*, i32** %7
%40 = icmp ne i32* %39, null
br i1 %40, label %50, label %41
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = sext i32 %42 to i64
%44 = inttoptr i64 %43 to i32*
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %34
br label %51
51: ; preds = %50, %31
br label %52
52: ; preds = %56, %51
%53 = load i32*, i32** %6
%54 = call i64 @fread(i32* %8, i32 4, i32 1, i32* %53)
store i64 %54, i64* %9
%55 = icmp ugt i64 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = load i32*, i32** %7
%58 = load i32, i32* %8
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %58)
br label %52
60: ; preds = %52
%61 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Error opening input: %s\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [26 x i8] c"Error opening output: %s\0A\00"
@.str.4 = [6 x i8] c"%04x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = load i32*, i32** @stdin
%5 = load i32*, i32** @stdout
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %33
7: ; preds = %2
%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 %12, label %19
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i32*
%16 = load i8*, i8** %8
%17 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %7
%20 = icmp ugt i32 %0, 2
br i1 %20, label %21, label %33
21: ; preds = %19
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %33
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i32*
%30 = load i8*, i8** %22
%31 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %2, %21, %19
%34 = phi i32* [ %10, %21 ], [ %10, %19 ], [ %4, %2 ]
%35 = phi i32* [ %24, %21 ], [ %5, %19 ], [ %5, %2 ]
%36 = bitcast i32* %3 to i8*
%37 = call i64 @fread(i32* %3, i32 4, i32 1, i32* %34)
%38 = icmp eq i64 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %33, %39
%40 = load i32, i32* %3
%41 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%42 = call i64 @fread(i32* %3, i32 4, i32 1, i32* %34)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %39
44: ; preds = %39, %33
%45 = tail call i32 @exit(i32 0)
unreachable
}