#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*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int trx2usr(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
extern int main(int argc, char *argv[]) {
  FILE *in;
  FILE *out;
  int ret;
  if (argc != 3) {
    fprintf(stderr, "Usage: trx2usr <trx input> <usr output>\n");
    exit(2);
  }
  in = fopen(argv[1], "rb");
  if (!in) {
    fprintf(stderr, "Cannot open \"%s\": %s\n", argv[1], strerror(errno));
    exit(1);
  }
  out = fopen(argv[2], "wb");
  if (!out) {
    fprintf(stderr, "Cannot create \"%s\": %s\n", argv[2], strerror(errno));
    exit(1);
  }
  ret = trx2usr(in, out);
  fclose(in);
  fclose(out);
  if (ret) {
    unlink(argv[2]);
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b1 <main+0x41>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe69(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121c <main+0xac>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe17(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1287 <main+0x117>
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <trx2usr@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x24(%rbp)
je     12c0 <main+0x150>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <unlink@plt>
mov    -0x24(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11ed <main+0x7d>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe9f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     120e <main+0x9e>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1232 <main+0xc2>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <trx2usr@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
test   %r15d,%r15d
je     11df <main+0x6f>
mov    0x10(%r14),%rdi
call   1030 <unlink@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%rbp
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdfc(%rip),%rsi
jmp    1254 <main+0xe4>
mov    0x2da7(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%r14),%rbp
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdf1(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: trx2usr <trx input> <usr output>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"Cannot open \22%s\22: %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [24 x i8] c"Cannot create \22%s\22: %s\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 2)
unreachable
15: ; preds = %2
%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.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %31, label %22
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %15
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %35, i32** %7
%36 = load i32*, i32** %7
%37 = icmp ne i32* %36, null
br i1 %37, label %47, label %38
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %42, i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %31
%48 = load i32*, i32** %6
%49 = load i32*, i32** %7
%50 = call i32 @trx2usr(i32* %48, i32* %49)
store i32 %50, i32* %8
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %47
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
%60 = load i8*, i8** %59
%61 = call i32 @unlink(i8* %60)
br label %62
62: ; preds = %57, %47
%63 = load i32, i32* %8
ret i32 %63
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: trx2usr <trx input> <usr output>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"Cannot open \22%s\22: %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [24 x i8] c"Cannot create \22%s\22: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 2)
unreachable
8: ; preds = %2
%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.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %20
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %9
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %15, i8* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %8
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %32
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %21
%28 = load i32, i32* @errno
%29 = tail call i8* @strerror(i32 %28)
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %27, i8* %29)
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %20
%33 = tail call i32 @trx2usr(i32* %11, i32* %23)
%34 = tail call i32 @fclose(i32* %11)
%35 = tail call i32 @fclose(i32* %23)
%36 = icmp eq i32 %33, 0
br i1 %36, label %40, label %37
37: ; preds = %32
%38 = load i8*, i8** %21
%39 = tail call i32 @unlink(i8* %38)
br label %40
40: ; preds = %37, %32
ret i32 %33
}