#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 ssize_t;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int, ...);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, unsigned char *, int);
int main(int argc, char **argv) {
  int fi, f1, f2;
  ssize_t s1, s2;
  fi = open(argv[1], O_RDONLY);
  f1 = open("out.lo", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  f2 = open("out.hi", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  if (-1 == f1 || -1 == f2) {
    fprintf(stderr, "failed to open output files\n");
    return -1;
  }
  if (-1 == fi) {
    fprintf(stderr, "failed to open input file\n");
    return -1;
  }
  do {
    unsigned char b[4];
    s1 = read(fi, b, 4);
    if (s1 == 4) {
      write(f1, b, 2);
      write(f2, b + 2, 2);
    }
  } while (s1);
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
mov    0x2e77(%rip),%rax
or     (%rax),%esi
mov    0x2e66(%rip),%rax
or     (%rax),%esi
lea    0xe6d(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    0x2e46(%rip),%rax
or     (%rax),%esi
mov    0x2e35(%rip),%rax
or     (%rax),%esi
lea    0xe43(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x18(%rbp),%eax
je     11ef <main+0xaf>
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    1210 <main+0xd0>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129e <main+0x15e>
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    123f <main+0xff>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129e <main+0x15e>
jmp    1244 <main+0x104>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jne    1288 <main+0x148>
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
add    $0x2,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
jmp    128d <main+0x14d>
cmpl   $0x0,-0x20(%rbp)
jne    1244 <main+0x104>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1060 <open@plt>
mov    0x2e52(%rip),%r15
mov    0x2e8b(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r15),%esi
mov    %eax,%r13d
mov    0x2e73(%rip),%rbx
or     (%rbx),%esi
lea    0xe7a(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%r14d
mov    0x0(%rbp),%esi
or     (%r15),%esi
or     (%rbx),%esi
lea    0xe63(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1060 <open@plt>
lea    0xe57(%rip),%rsi
cmp    $0xffffffff,%r14d
je     1228 <main+0xe8>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
je     1228 <main+0xe8>
cmp    $0xffffffff,%r13d
je     1221 <main+0xe1>
lea    0x6(%rsp),%r15
lea    0x4(%rsp),%rbp
jmp    11e4 <main+0xa4>
nopw   0x0(%rax,%rax,1)
test   %ebx,%ebx
je     121d <main+0xdd>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,%ebx
cmp    $0x4,%eax
jne    11e0 <main+0xa0>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
jmp    11e0 <main+0xa0>
xor    %eax,%eax
jmp    123b <main+0xfb>
lea    0xe03(%rip),%rsi
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [7 x i8] c"out.lo\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [7 x i8] c"out.hi\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"failed to open output files\0A\00"
@.str.3 = [27 x i8] c"failed to open input file\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 i32
%10 = alloca i32
%11 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = call i32 (i8*, i32, ...) @open(i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* @O_WRONLY
%18 = load i32, i32* @O_CREAT
%19 = or i32 %17, %18
%20 = load i32, i32* @O_TRUNC
%21 = or i32 %19, %20
%22 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %21, i32 438)
store i32 %22, i32* %7
%23 = load i32, i32* @O_WRONLY
%24 = load i32, i32* @O_CREAT
%25 = or i32 %23, %24
%26 = load i32, i32* @O_TRUNC
%27 = or i32 %25, %26
%28 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 438)
store i32 %28, i32* %8
%29 = load i32, i32* %7
%30 = icmp eq i32 -1, %29
br i1 %30, label %34, label %31
31: ; preds = %2
%32 = load i32, i32* %8
%33 = icmp eq i32 -1, %32
br i1 %33, label %34, label %37
34: ; preds = %31, %2
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %63
37: ; preds = %31
%38 = load i32, i32* %6
%39 = icmp eq i32 -1, %38
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %63
43: ; preds = %37
br label %44
44: ; preds = %59, %43
%45 = load i32, i32* %6
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%47 = call i32 @read(i32 %45, i8* %46, i32 4)
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = icmp eq i32 %48, 4
br i1 %49, label %50, label %58
50: ; preds = %44
%51 = load i32, i32* %7
%52 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%53 = call i32 @write(i32 %51, i8* %52, i32 2)
%54 = load i32, i32* %8
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%56 = getelementptr inbounds i8, i8* %55, i64 2
%57 = call i32 @write(i32 %54, i8* %56, i32 2)
br label %58
58: ; preds = %50, %44
br label %59
59: ; preds = %58
%60 = load i32, i32* %9
%61 = icmp ne i32 %60, 0
br i1 %61, label %44, label %62
62: ; preds = %59
store i32 0, i32* %3
br label %63
63: ; preds = %62, %40, %34
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [7 x i8] c"out.lo\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [7 x i8] c"out.hi\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"failed to open output files\0A\00"
@.str.3 = [27 x i8] c"failed to open input file\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 (i8*, i32, ...) @open(i8* %5, i32 %6)
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %12, i32 438)
%14 = load i32, i32* @O_WRONLY
%15 = load i32, i32* @O_CREAT
%16 = or i32 %15, %14
%17 = load i32, i32* @O_TRUNC
%18 = or i32 %16, %17
%19 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 438)
%20 = icmp eq i32 %13, -1
%21 = icmp eq i32 %19, -1
%22 = or i1 %20, %21
br i1 %22, label %36, label %23
23: ; preds = %2
%24 = icmp eq i32 %7, -1
br i1 %24, label %36, label %25
25: ; preds = %23
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
br label %28
28: ; preds = %25, %34
%29 = call i32 @read(i32 %7, i8* %26, i32 4)
%30 = icmp eq i32 %29, 4
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = call i32 @write(i32 %13, i8* %26, i32 2)
%33 = call i32 @write(i32 %19, i8* %27, i32 2)
br label %34
34: ; preds = %31, %28
%35 = icmp eq i32 %29, 0
br i1 %35, label %40, label %28
36: ; preds = %23, %2
%37 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), %2 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), %23 ]
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* %37)
br label %40
40: ; preds = %34, %36
%41 = phi i32 [ -1, %36 ], [ 0, %34 ]
ret i32 %41
}