#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*/ fail(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  FILE *in = stdin;
  FILE *out = stdout;
  unsigned long itr = 0;
  unsigned char *stack;
  int word_size, bytes_read, i;
  if ((argc < 2) | (argc > 4))
    fail(argv[0], "see usage");
  word_size = atoi(argv[1]);
  if (argc > 2) {
    in = fopen(argv[2], "rb");
    if (!in)
      fail(argv[0], "failed to open infile");
  }
  if (argc > 3) {
    out = fopen(argv[3], "wb");
    if (!out)
      fail(argv[0], "failed to open outfile");
  }
  stack = (unsigned char *)malloc(word_size);
  if (!stack)
    fail(argv[0], "failed to allocate byte stack");
  while (word_size == (bytes_read = fread(stack, 1, word_size, in))) {
    for (i = word_size - 1; i >= 0; i--) {
      if (1 != fwrite(stack + i, 1, 1, out))
        fprintf(stderr, "Failed to write a byte :(\n");
    }
  }
  fclose(in);
  fclose(out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x4,-0x8(%rbp)
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
je     11f1 <main+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe14(%rip),%rsi
call   1040 <fail@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1246 <main+0xc6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdf0(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1241 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdd1(%rip),%rsi
call   1040 <fail@plt>
jmp    1246 <main+0xc6>
cmpl   $0x3,-0x8(%rbp)
jle    128b <main+0x10b>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xdc4(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1286 <main+0x106>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xda5(%rip),%rsi
call   1040 <fail@plt>
jmp    128b <main+0x10b>
mov    -0x34(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12b5 <main+0x135>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd8d(%rip),%rsi
call   1040 <fail@plt>
jmp    12ba <main+0x13a>
mov    -0x34(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
mov    %ecx,-0x38(%rbp)
cmp    %ecx,%eax
jne    134f <main+0x1cf>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jl     134a <main+0x1ca>
mov    -0x30(%rbp),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     1337 <main+0x1b7>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
lea    0xd29(%rip),%rsi
call   1060 <fprintf@plt>
jmp    133c <main+0x1bc>
mov    -0x3c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3c(%rbp)
jmp    12ee <main+0x16e>
jmp    12ba <main+0x13a>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2e4e(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
mov    0x2e27(%rip),%rax
mov    (%rax),%rbx
lea    -0x5(%rbp),%eax
cmp    $0xfffffffc,%eax
ja     11c3 <main+0x43>
mov    (%r15),%rdi
lea    0xe42(%rip),%rsi
call   1040 <fail@plt>
mov    0x8(%r15),%rdi
call   1090 <atoi@plt>
mov    %eax,%r12d
cmp    $0x3,%ebp
jl     1234 <main+0xb4>
mov    0x10(%r15),%rdi
lea    0xe2b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     11f5 <main+0x75>
cmp    $0x4,%ebp
jae    1209 <main+0x89>
jmp    1234 <main+0xb4>
mov    (%r15),%rdi
lea    0xe0e(%rip),%rsi
call   1040 <fail@plt>
cmp    $0x4,%ebp
jb     1234 <main+0xb4>
mov    0x18(%r15),%rdi
lea    0xe0f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1223 <main+0xa3>
mov    %rax,%rbx
jmp    1234 <main+0xb4>
mov    (%r15),%rdi
lea    0xdf9(%rip),%rsi
call   1040 <fail@plt>
xor    %ebx,%ebx
mov    %r12d,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1253 <main+0xd3>
mov    (%r15),%rdi
lea    0xdef(%rip),%rsi
call   1040 <fail@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    0x8(%rsp),%rcx
call   1030 <fread@plt>
cmp    %eax,%r12d
jne    12f5 <main+0x175>
mov    %r12d,%eax
add    $0x1,%rax
mov    %rax,0x10(%rsp)
mov    0x2d54(%rip),%r14
lea    0xdd0(%rip),%r15
jmp    12aa <main+0x12a>
nopl   (%rax)
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    0x8(%rsp),%rcx
call   1030 <fread@plt>
cmp    %eax,%r12d
jne    12f5 <main+0x175>
test   %r12d,%r12d
jle    1290 <main+0x110>
mov    0x10(%rsp),%r13
jmp    12ca <main+0x14a>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%r13
cmp    $0x1,%r13
jle    1290 <main+0x110>
lea    -0x2(%r13),%edi
add    %rbp,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
cmp    $0x1,%eax
je     12c0 <main+0x140>
mov    (%r14),%edi
mov    %r15,%rsi
call   1060 <fprintf@plt>
jmp    12c0 <main+0x140>
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32* null
@.str = [10 x i8] c"see usage\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"failed to open infile\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [23 x i8] c"failed to open outfile\00"
@.str.5 = [30 x i8] c"failed to allocate byte stack\00"
@stderr = global i32 0
@.str.6 = [27 x i8] c"Failed to write a byte :(\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 i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32*, i32** @stdin
store i32* %13, i32** %6
%14 = load i32*, i32** @stdout
store i32* %14, i32** %7
store i64 0, i64* %8
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
%17 = zext i1 %16 to i32
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 4
%20 = zext i1 %19 to i32
%21 = or i32 %17, %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @fail(i8* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %23, %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %10
%33 = load i32, i32* %4
%34 = icmp sgt i32 %33, 2
br i1 %34, label %35, label %48
35: ; preds = %28
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %39, i32** %6
%40 = load i32*, i32** %6
%41 = icmp ne i32* %40, null
br i1 %41, label %47, label %42
42: ; preds = %35
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 0
%45 = load i8*, i8** %44
%46 = call i32 @fail(i8* %45, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %42, %35
br label %48
48: ; preds = %47, %28
%49 = load i32, i32* %4
%50 = icmp sgt i32 %49, 3
br i1 %50, label %51, label %64
51: ; preds = %48
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 3
%54 = load i8*, i8** %53
%55 = call i32* @fopen(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %55, i32** %7
%56 = load i32*, i32** %7
%57 = icmp ne i32* %56, null
br i1 %57, label %63, label %58
58: ; preds = %51
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = call i32 @fail(i8* %61, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %63
63: ; preds = %58, %51
br label %64
64: ; preds = %63, %48
%65 = load i32, i32* %10
%66 = call i64 @malloc(i32 %65)
%67 = inttoptr i64 %66 to i8*
store i8* %67, i8** %9
%68 = load i8*, i8** %9
%69 = icmp ne i8* %68, null
br i1 %69, label %75, label %70
70: ; preds = %64
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 0
%73 = load i8*, i8** %72
%74 = call i32 @fail(i8* %73, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %75
75: ; preds = %70, %64
br label %76
76: ; preds = %104, %75
%77 = load i32, i32* %10
%78 = load i8*, i8** %9
%79 = load i32, i32* %10
%80 = load i32*, i32** %6
%81 = call i32 @fread(i8* %78, i32 1, i32 %79, i32* %80)
store i32 %81, i32* %11
%82 = icmp eq i32 %77, %81
br i1 %82, label %83, label %105
83: ; preds = %76
%84 = load i32, i32* %10
%85 = sub nsw i32 %84, 1
store i32 %85, i32* %12
br label %86
86: ; preds = %101, %83
%87 = load i32, i32* %12
%88 = icmp sge i32 %87, 0
br i1 %88, label %89, label %104
89: ; preds = %86
%90 = load i8*, i8** %9
%91 = load i32, i32* %12
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %90, i64 %92
%94 = load i32*, i32** %7
%95 = call i32 @fwrite(i8* %93, i32 1, i32 1, i32* %94)
%96 = icmp ne i32 1, %95
br i1 %96, label %97, label %100
97: ; preds = %89
%98 = load i32, i32* @stderr
%99 = call i32 @fprintf(i32 %98, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %100
100: ; preds = %97, %89
br label %101
101: ; preds = %100
%102 = load i32, i32* %12
%103 = add nsw i32 %102, -1
store i32 %103, i32* %12
br label %86
104: ; preds = %86
br label %76
105: ; preds = %76
%106 = load i32*, i32** %6
%107 = call i32 @fclose(i32* %106)
%108 = load i32*, i32** %7
%109 = call i32 @fclose(i32* %108)
%110 = load i32, i32* %3
ret i32 %110
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@.str = [10 x i8] c"see usage\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"failed to open infile\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [23 x i8] c"failed to open outfile\00"
@.str.5 = [30 x i8] c"failed to allocate byte stack\00"
@stderr = global i32 0
@.str.6 = [27 x i8] c"Failed to write a byte :(\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32*, i32** @stdin
%4 = load i32*, i32** @stdout
%5 = add i32 %0, -5
%6 = icmp ult i32 %5, -3
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 @fail(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = icmp sgt i32 %0, 2
br i1 %14, label %15, label %33
15: ; preds = %10
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %1
%22 = tail call i32 @fail(i8* %21, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %15, %20
%24 = icmp ugt i32 %0, 3
br i1 %24, label %25, label %33
25: ; preds = %23
%26 = getelementptr inbounds i8*, i8** %1, i64 3
%27 = load i8*, i8** %26
%28 = tail call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i8*, i8** %1
%32 = tail call i32 @fail(i8* %31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %10, %25, %30, %23
%34 = phi i32* [ %18, %25 ], [ %18, %30 ], [ %18, %23 ], [ %3, %10 ]
%35 = phi i32* [ %28, %25 ], [ null, %30 ], [ %4, %23 ], [ %4, %10 ]
%36 = tail call i64 @malloc(i32 %13)
%37 = inttoptr i64 %36 to i8*
%38 = icmp eq i64 %36, 0
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = load i8*, i8** %1
%41 = tail call i32 @fail(i8* %40, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %42
42: ; preds = %39, %33
%43 = tail call i32 @fread(i8* %37, i32 1, i32 %13, i32* %34)
%44 = icmp eq i32 %13, %43
br i1 %44, label %45, label %64
45: ; preds = %42
%46 = icmp sgt i32 %13, 0
%47 = zext i32 %13 to i64
br label %51
48: ; preds = %62, %51
%49 = tail call i32 @fread(i8* %37, i32 1, i32 %13, i32* %34)
%50 = icmp eq i32 %13, %49
br i1 %50, label %51, label %64
51: ; preds = %45, %48
br i1 %46, label %52, label %48
52: ; preds = %51, %62
%53 = phi i64 [ %54, %62 ], [ %47, %51 ]
%54 = add nsw i64 %53, -1
%55 = and i64 %54, 4294967295
%56 = getelementptr inbounds i8, i8* %37, i64 %55
%57 = tail call i32 @fwrite(i8* %56, i32 1, i32 1, i32* %35)
%58 = icmp eq i32 %57, 1
br i1 %58, label %62, label %59
59: ; preds = %52
%60 = load i32, i32* @stderr
%61 = tail call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %62
62: ; preds = %52, %59
%63 = icmp sgt i64 %53, 1
br i1 %63, label %52, label %48
64: ; preds = %48, %42
%65 = tail call i32 @fclose(i32* %34)
%66 = tail call i32 @fclose(i32* %35)
ret i32 0
}