#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  FILE *infile, *outfileL, *outfileR;
  if (argc != 4)
    exit(EXIT_FAILURE);
  infile = fopen(argv[1], "rb");
  outfileL = fopen(argv[2], "wb");
  outfileR = fopen(argv[3], "wb");
  if (!infile || !outfileL || !outfileR)
    exit(EXIT_FAILURE);
  do {
    unsigned char c[2];
    unsigned char l, r;
    size_t s;
    s = fread(c, 1, 2, infile);
    if (s != 2) {
      if (feof(infile))
        break;
      perror("fwrite");
      exit(EXIT_FAILURE);
    }
    l = ((c[0] & 0x0f) << 4) | (c[1] & 0x0f);
    r = (c[0] & 0xf0) | ((c[1] & 0xf0) >> 4);
    s = fwrite(&l, 1, 1, outfileL);
    if (s != 1) {
      perror("fwrite");
      exit(EXIT_FAILURE);
    }
    s = fwrite(&r, 1, 1, outfileR);
    if (s != 1) {
      perror("fwrite");
      exit(EXIT_FAILURE);
    }
  } while (!feof(infile));
  fclose(infile);
  fclose(outfileL);
  fclose(outfileR);
  printf("ok\n");
}


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)
cmpl   $0x4,-0x8(%rbp)
je     11ae <main+0x2e>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe43(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe2e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe16(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1217 <main+0x97>
cmpq   $0x0,-0x20(%rbp)
je     1217 <main+0x97>
cmpq   $0x0,-0x28(%rbp)
jne    1225 <main+0xa5>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    122a <main+0xaa>
lea    -0x2a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <fread@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x2,-0x38(%rbp)
je     1282 <main+0x102>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     1268 <main+0xe8>
jmp    134c <main+0x1cc>
lea    0xd97(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movzbl -0x2a(%rbp),%eax
and    $0xf,%eax
shl    $0x4,%eax
movzbl -0x29(%rbp),%ecx
and    $0xf,%ecx
or     %ecx,%eax
mov    %al,-0x2b(%rbp)
movzbl -0x2a(%rbp),%eax
and    $0xf0,%eax
movzbl -0x29(%rbp),%ecx
and    $0xf0,%ecx
sar    $0x4,%ecx
or     %ecx,%eax
mov    %al,-0x2c(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x2b(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x1,-0x38(%rbp)
je     12f0 <main+0x170>
lea    0xd29(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x1,-0x38(%rbp)
je     132d <main+0x1ad>
lea    0xcec(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1332 <main+0x1b2>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    122a <main+0xaa>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xc9f(%rip),%rdi
call   1050 <printf@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
push   %rax
cmp    $0x4,%edi
jne    12d9 <main+0x159>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe5e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    0x10(%rbp),%rdi
lea    0xe4e(%rip),%r15
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    0x18(%rbp),%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
test   %r12,%r12
je     12d9 <main+0x159>
test   %r14,%r14
je     12d9 <main+0x159>
mov    %rax,%r15
test   %rax,%rax
je     12d9 <main+0x159>
lea    0x5(%rsp),%r13
lea    0x4(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x6(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
cmp    $0x2,%rax
jne    128b <main+0x10b>
movzbl 0x6(%rsp),%eax
movzbl 0x7(%rsp),%ebx
mov    %eax,%edx
shl    $0x4,%dl
mov    %ebx,%ecx
and    $0xf,%cl
or     %dl,%cl
mov    %cl,0x5(%rsp)
and    $0xf0,%al
shr    $0x4,%bl
or     %al,%bl
mov    %bl,0x4(%rsp)
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10a0 <fwrite@plt>
cmp    $0x1,%rax
jne    12cd <main+0x14d>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   10a0 <fwrite@plt>
cmp    $0x1,%rax
jne    12cd <main+0x14d>
mov    %r12,%rdi
call   1060 <feof@plt>
test   %rax,%rax
je     1200 <main+0x80>
jmp    1298 <main+0x118>
mov    %r12,%rdi
call   1060 <feof@plt>
test   %rax,%rax
je     12cd <main+0x14d>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
lea    0xd56(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd32(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [7 x i8] c"fwrite\00"
@.str.3 = [4 x i8] c"ok\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 [2 x i8]
%10 = alloca i8
%11 = alloca i8
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 4
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %7
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %8
%31 = load i32*, i32** %6
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %39
33: ; preds = %18
%34 = load i32*, i32** %7
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32*, i32** %8
%38 = icmp ne i32* %37, null
br i1 %38, label %42, label %39
39: ; preds = %36, %33, %18
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %36
br label %43
43: ; preds = %99, %42
%44 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%45 = load i32*, i32** %6
%46 = call i64 @fread(i8* %44, i32 1, i32 2, i32* %45)
store i64 %46, i64* %12
%47 = load i64, i64* %12
%48 = icmp ne i64 %47, 2
br i1 %48, label %49, label %58
49: ; preds = %43
%50 = load i32*, i32** %6
%51 = call i64 @feof(i32* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %49
br label %104
54: ; preds = %49
%55 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %43
%59 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = and i32 %61, 15
%63 = shl i32 %62, 4
%64 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 1
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = and i32 %66, 15
%68 = or i32 %63, %67
%69 = trunc i32 %68 to i8
store i8 %69, i8* %10
%70 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = and i32 %72, 240
%74 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 1
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = and i32 %76, 240
%78 = ashr i32 %77, 4
%79 = or i32 %73, %78
%80 = trunc i32 %79 to i8
store i8 %80, i8* %11
%81 = load i32*, i32** %7
%82 = call i64 @fwrite(i8* %10, i32 1, i32 1, i32* %81)
store i64 %82, i64* %12
%83 = load i64, i64* %12
%84 = icmp ne i64 %83, 1
br i1 %84, label %85, label %89
85: ; preds = %58
%86 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%87 = load i32, i32* @EXIT_FAILURE
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %58
%90 = load i32*, i32** %8
%91 = call i64 @fwrite(i8* %11, i32 1, i32 1, i32* %90)
store i64 %91, i64* %12
%92 = load i64, i64* %12
%93 = icmp ne i64 %92, 1
br i1 %93, label %94, label %98
94: ; preds = %89
%95 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%96 = load i32, i32* @EXIT_FAILURE
%97 = call i32 @exit(i32 %96)
unreachable
98: ; preds = %89
br label %99
99: ; preds = %98
%100 = load i32*, i32** %6
%101 = call i64 @feof(i32* %100)
%102 = icmp ne i64 %101, 0
%103 = xor i1 %102, true
br i1 %103, label %43, label %104
104: ; preds = %99, %53
%105 = load i32*, i32** %6
%106 = call i32 @fclose(i32* %105)
%107 = load i32*, i32** %7
%108 = call i32 @fclose(i32* %107)
%109 = load i32*, i32** %8
%110 = call i32 @fclose(i32* %109)
%111 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%112 = load i32, i32* %3
ret i32 %112
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [7 x i8] c"fwrite\00"
@str = [3 x i8] c"ok\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i8]
%4 = alloca i8
%5 = alloca i8
%6 = icmp eq i32 %0, 4
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i32* %13, null
%21 = icmp ne i32* %16, null
%22 = and i1 %20, %21
%23 = icmp ne i32* %19, null
%24 = and i1 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %10
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
br label %31
28: ; preds = %10
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %25, %64
%32 = call i64 @fread(i8* %26, i32 1, i32 2, i32* %13)
%33 = icmp eq i64 %32, 2
br i1 %33, label %41, label %34
34: ; preds = %31
%35 = tail call i64 @feof(i32* %13)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %63
37: ; preds = %34
%38 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %31
%42 = load i8, i8* %26
%43 = shl i8 %42, 4
%44 = load i8, i8* %27
%45 = and i8 %44, 15
%46 = or i8 %45, %43
store i8 %46, i8* %4
%47 = and i8 %42, -16
%48 = lshr i8 %44, 4
%49 = or i8 %48, %47
store i8 %49, i8* %5
%50 = call i64 @fwrite(i8* %4, i32 1, i32 1, i32* %16)
%51 = icmp eq i64 %50, 1
br i1 %51, label %56, label %52
52: ; preds = %41
%53 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = tail call i32 @exit(i32 %54)
unreachable
56: ; preds = %41
%57 = call i64 @fwrite(i8* %5, i32 1, i32 1, i32* %19)
%58 = icmp eq i64 %57, 1
br i1 %58, label %64, label %59
59: ; preds = %56
%60 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%61 = load i32, i32* @EXIT_FAILURE
%62 = tail call i32 @exit(i32 %61)
unreachable
63: ; preds = %34
br label %67
64: ; preds = %56
%65 = tail call i64 @feof(i32* %13)
%66 = icmp eq i64 %65, 0
br i1 %66, label %31, label %67
67: ; preds = %64, %63
%68 = tail call i32 @fclose(i32* %13)
%69 = tail call i32 @fclose(i32* %16)
%70 = tail call i32 @fclose(i32* %19)
%71 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
ret i32 0
}