#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 atoi(char *);
int /*<<< orphan*/ convert(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ exiterr(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ *stdout;
int main(int ac, char **av) {
  int format;
  FILE *infile;
  FILE *outfile;
  if (ac < 3) {
    puts("FTOHEX format infile [outfile]");
    puts("format 1,2, or 3.  3=raw");
    puts("Copyright (c) 1988-2008 by various authors (see file AUTHORS).");
    exit(1);
  }
  format = atoi(av[1]);
  if (format < 1 || format > 3)
    exiterr("specify infile format 1, 2, or 3");
  infile = fopen(av[2], "r");
  if (infile == NULL)
    exiterr("unable to open input file");
  outfile = (av[3]) ? fopen(av[3], "w") : stdout;
  if (outfile == NULL)
    exiterr("unable to open output file");
  convert(format, infile, outfile);
  fclose(infile);
  fclose(outfile);
  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)
cmpl   $0x3,-0x8(%rbp)
jge    11be <main+0x4e>
lea    0xe69(%rip),%rdi
call   1050 <puts@plt>
lea    0xe7c(%rip),%rdi
call   1050 <puts@plt>
lea    0xe89(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     11e2 <main+0x72>
cmpl   $0x3,-0x14(%rbp)
jle    11ee <main+0x7e>
lea    0xe8e(%rip),%rdi
call   1030 <exiterr@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121d <main+0xad>
lea    0xe82(%rip),%rdi
call   1030 <exiterr@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     1249 <main+0xd9>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xdfb(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
jmp    1257 <main+0xe7>
mov    0x2d90(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1276 <main+0x106>
lea    0xe43(%rip),%rdi
call   1030 <exiterr@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <convert@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jle    1226 <main+0xb6>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
lea    -0x4(%r14),%eax
cmp    $0xfffffffc,%eax
ja     11a2 <main+0x32>
lea    0xeda(%rip),%rdi
call   1030 <exiterr@plt>
mov    0x10(%rbx),%rdi
lea    0xeeb(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11c6 <main+0x56>
lea    0xed9(%rip),%rdi
call   1030 <exiterr@plt>
mov    0x18(%rbx),%rdi
test   %rdi,%rdi
je     1215 <main+0xa5>
lea    0xe60(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
jne    11ef <main+0x7f>
lea    0xeca(%rip),%rdi
call   1030 <exiterr@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <convert@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dc4(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    11ef <main+0x7f>
jmp    11e3 <main+0x73>
lea    0xdd3(%rip),%rdi
call   1050 <puts@plt>
lea    0xde6(%rip),%rdi
call   1050 <puts@plt>
lea    0xdf3(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"FTOHEX format infile [outfile]\00"
@.str.1 = [25 x i8] c"format 1,2, or 3. 3=raw\00"
@.str.2 = [63 x i8] c"Copyright (c) 1988-2008 by various authors (see file AUTHORS).\00"
@.str.3 = [33 x i8] c"specify infile format 1, 2, or 3\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [26 x i8] c"unable to open input file\00"
@.str.6 = [2 x i8] c"w\00"
@stdout = global i32* null
@.str.7 = [27 x i8] c"unable to open output file\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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @puts(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 1
br i1 %22, label %26, label %23
23: ; preds = %16
%24 = load i32, i32* %6
%25 = icmp sgt i32 %24, 3
br i1 %25, label %26, label %28
26: ; preds = %23, %16
%27 = call i32 @exiterr(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = call i32 @exiterr(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35, %28
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 3
%40 = load i8*, i8** %39
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %49
47: ; preds = %37
%48 = load i32*, i32** @stdout
br label %49
49: ; preds = %47, %42
%50 = phi i32* [ %46, %42 ], [ %48, %47 ]
store i32* %50, i32** %8
%51 = load i32*, i32** %8
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @exiterr(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
%56 = load i32, i32* %6
%57 = load i32*, i32** %7
%58 = load i32*, i32** %8
%59 = call i32 @convert(i32 %56, i32* %57, i32* %58)
%60 = load i32*, i32** %7
%61 = call i32 @fclose(i32* %60)
%62 = load i32*, i32** %8
%63 = call i32 @fclose(i32* %62)
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"FTOHEX format infile [outfile]\00"
@.str.1 = [25 x i8] c"format 1,2, or 3. 3=raw\00"
@.str.2 = [63 x i8] c"Copyright (c) 1988-2008 by various authors (see file AUTHORS).\00"
@.str.3 = [33 x i8] c"specify infile format 1, 2, or 3\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [26 x i8] c"unable to open input file\00"
@.str.6 = [2 x i8] c"w\00"
@stdout = global i32* null
@.str.7 = [27 x i8] c"unable to open output file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = add i32 %12, -4
%14 = icmp ult i32 %13, -3
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 @exiterr(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %9, %15
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 @exiterr(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = icmp eq i8* %26, null
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %32
30: ; preds = %24
%31 = load i32*, i32** @stdout
br label %32
32: ; preds = %30, %28
%33 = phi i32* [ %29, %28 ], [ %31, %30 ]
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = tail call i32 @exiterr(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
%38 = tail call i32 @convert(i32 %12, i32* %20, i32* %33)
%39 = tail call i32 @fclose(i32* %20)
%40 = tail call i32 @fclose(i32* %33)
ret i32 0
}