#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 */

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, count, out0, out1;
  char word[2];
  if (argc != 4)
    fprintf(stderr, "Syntax: %s infile evenfile oddfile\n", argv[0]);
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Error opening file\n");
    return 1;
  }
  out0 = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC,
              S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  if (out0 < 0) {
    fprintf(stderr, "Error creating even file\n");
    return 2;
  }
  out1 = open(argv[3], O_WRONLY | O_CREAT | O_TRUNC,
              S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  if (out1 < 0) {
    fprintf(stderr, "Error creating odd file\n");
    return 3;
  }
  do {
    count = read(fd, word, 2);
    if (count > 0)
      write(out0, &word[0], 1);
    if (count > 1)
      write(out1, &word[1], 1);
  } while (count > 0);
  close(fd);
  close(out0);
  close(out1);
  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   $0x4,-0x8(%rbp)
je     118e <main+0x3e>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d6 <main+0x86>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1353 <main+0x203>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
mov    0x2e0a(%rip),%rax
or     (%rax),%esi
mov    0x2df9(%rip),%rax
or     (%rax),%esi
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
mov    0x2dc7(%rip),%rax
or     (%rax),%edx
mov    0x2da6(%rip),%rax
or     (%rax),%edx
mov    0x2d95(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1254 <main+0x104>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1353 <main+0x203>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2d35(%rip),%rax
mov    (%rax),%esi
mov    0x2d8c(%rip),%rax
or     (%rax),%esi
mov    0x2d7b(%rip),%rax
or     (%rax),%esi
mov    0x2d2a(%rip),%rax
mov    (%rax),%edx
mov    0x2d49(%rip),%rax
or     (%rax),%edx
mov    0x2d28(%rip),%rax
or     (%rax),%edx
mov    0x2d17(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12d2 <main+0x182>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    1353 <main+0x203>
jmp    12d7 <main+0x187>
mov    -0x14(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1306 <main+0x1b6>
mov    -0x1c(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmpl   $0x1,-0x18(%rbp)
jle    1325 <main+0x1d5>
mov    -0x20(%rbp),%edi
lea    -0x22(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    132a <main+0x1da>
cmpl   $0x0,-0x18(%rbp)
jg     12d7 <main+0x187>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
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    %rsi,%r14
cmp    $0x4,%edi
je     117d <main+0x2d>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe8a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%r14),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
test   %eax,%eax
js     129d <main+0x14d>
mov    %eax,%r12d
mov    0x2df5(%rip),%rax
mov    0x2e4e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e3b(%rip),%rax
or     (%rax),%esi
mov    0x2dea(%rip),%rax
mov    0x2e0b(%rip),%rbx
mov    (%rbx),%edx
or     (%rax),%edx
mov    0x2de8(%rip),%r15
or     (%r15),%edx
mov    0x10(%r14),%rdi
mov    0x2dd2(%rip),%rbp
or     0x0(%rbp),%edx
xor    %eax,%eax
call   1070 <open@plt>
test   %eax,%eax
js     12d7 <main+0x187>
mov    %eax,%r13d
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    0x2d95(%rip),%rax
or     (%rax),%esi
mov    0x2de4(%rip),%rax
or     (%rax),%esi
mov    0x18(%r14),%rdi
mov    (%rbx),%edx
mov    0x2d8d(%rip),%rax
or     (%rax),%edx
or     (%r15),%edx
or     0x0(%rbp),%edx
xor    %eax,%eax
call   1070 <open@plt>
test   %eax,%eax
js     12f5 <main+0x1a5>
mov    %eax,%r14d
lea    0x6(%rsp),%rsi
mov    %r12d,%edi
mov    $0x2,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    12bb <main+0x16b>
mov    %eax,%ebp
lea    0x7(%rsp),%r15
lea    0x6(%rsp),%rbx
jmp    1276 <main+0x126>
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    12bb <main+0x16b>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%ebp
je     1260 <main+0x110>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1260 <main+0x110>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    1311 <main+0x1c1>
mov    %r12d,%edi
call   1040 <close@plt>
mov    %r13d,%edi
call   1040 <close@plt>
mov    %r14d,%edi
call   1040 <close@plt>
xor    %eax,%eax
jmp    1311 <main+0x1c1>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
lea    0xd51(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%eax
jmp    1311 <main+0x1c1>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x3,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Syntax: %s infile evenfile oddfile\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Error opening file\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.2 = [26 x i8] c"Error creating even file\0A\00"
@.str.3 = [25 x i8] c"Error creating odd 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 [2 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %13, %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 (i8*, i32, ...) @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %103
30: ; preds = %19
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = load i32, i32* @O_WRONLY
%35 = load i32, i32* @O_CREAT
%36 = or i32 %34, %35
%37 = load i32, i32* @O_TRUNC
%38 = or i32 %36, %37
%39 = load i32, i32* @S_IRUSR
%40 = load i32, i32* @S_IWUSR
%41 = or i32 %39, %40
%42 = load i32, i32* @S_IRGRP
%43 = or i32 %41, %42
%44 = load i32, i32* @S_IROTH
%45 = or i32 %43, %44
%46 = call i32 (i8*, i32, ...) @open(i8* %33, i32 %38, i32 %45)
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %30
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %103
52: ; preds = %30
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 3
%55 = load i8*, i8** %54
%56 = load i32, i32* @O_WRONLY
%57 = load i32, i32* @O_CREAT
%58 = or i32 %56, %57
%59 = load i32, i32* @O_TRUNC
%60 = or i32 %58, %59
%61 = load i32, i32* @S_IRUSR
%62 = load i32, i32* @S_IWUSR
%63 = or i32 %61, %62
%64 = load i32, i32* @S_IRGRP
%65 = or i32 %63, %64
%66 = load i32, i32* @S_IROTH
%67 = or i32 %65, %66
%68 = call i32 (i8*, i32, ...) @open(i8* %55, i32 %60, i32 %67)
store i32 %68, i32* %9
%69 = load i32, i32* %9
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %52
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 3, i32* %3
br label %103
74: ; preds = %52
br label %75
75: ; preds = %93, %74
%76 = load i32, i32* %6
%77 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%78 = call i32 @read(i32 %76, i8* %77, i32 2)
store i32 %78, i32* %7
%79 = load i32, i32* %7
%80 = icmp sgt i32 %79, 0
br i1 %80, label %81, label %85
81: ; preds = %75
%82 = load i32, i32* %8
%83 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%84 = call i32 @write(i32 %82, i8* %83, i32 1)
br label %85
85: ; preds = %81, %75
%86 = load i32, i32* %7
%87 = icmp sgt i32 %86, 1
br i1 %87, label %88, label %92
88: ; preds = %85
%89 = load i32, i32* %9
%90 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 1
%91 = call i32 @write(i32 %89, i8* %90, i32 1)
br label %92
92: ; preds = %88, %85
br label %93
93: ; preds = %92
%94 = load i32, i32* %7
%95 = icmp sgt i32 %94, 0
br i1 %95, label %75, label %96
96: ; preds = %93
%97 = load i32, i32* %6
%98 = call i32 @close(i32 %97)
%99 = load i32, i32* %8
%100 = call i32 @close(i32 %99)
%101 = load i32, i32* %9
%102 = call i32 @close(i32 %101)
store i32 0, i32* %3
br label %103
103: ; preds = %96, %71, %49, %27
%104 = load i32, i32* %3
ret i32 %104
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Syntax: %s infile evenfile oddfile\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Error opening file\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.2 = [26 x i8] c"Error creating even file\0A\00"
@.str.3 = [25 x i8] c"Error creating odd file\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %6, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %77
19: ; preds = %10
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_WRONLY
%23 = load i32, i32* @O_CREAT
%24 = or i32 %23, %22
%25 = load i32, i32* @O_TRUNC
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IRUSR
%28 = load i32, i32* @S_IWUSR
%29 = or i32 %28, %27
%30 = load i32, i32* @S_IRGRP
%31 = or i32 %29, %30
%32 = load i32, i32* @S_IROTH
%33 = or i32 %31, %32
%34 = tail call i32 (i8*, i32, ...) @open(i8* %21, i32 %26, i32 %33)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %19
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %77
39: ; preds = %19
%40 = getelementptr inbounds i8*, i8** %1, i64 3
%41 = load i8*, i8** %40
%42 = load i32, i32* @O_WRONLY
%43 = load i32, i32* @O_CREAT
%44 = or i32 %43, %42
%45 = load i32, i32* @O_TRUNC
%46 = or i32 %44, %45
%47 = load i32, i32* @S_IRUSR
%48 = load i32, i32* @S_IWUSR
%49 = or i32 %48, %47
%50 = load i32, i32* @S_IRGRP
%51 = or i32 %49, %50
%52 = load i32, i32* @S_IROTH
%53 = or i32 %51, %52
%54 = tail call i32 (i8*, i32, ...) @open(i8* %41, i32 %46, i32 %53)
%55 = icmp slt i32 %54, 0
br i1 %55, label %61, label %56
56: ; preds = %39
%57 = call i32 @read(i32 %14, i8* %4, i32 2)
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %73
59: ; preds = %56
%60 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
br label %64
61: ; preds = %39
%62 = load i32, i32* @stderr
%63 = tail call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %77
64: ; preds = %59, %70
%65 = phi i32 [ %57, %59 ], [ %71, %70 ]
%66 = call i32 @write(i32 %34, i8* %4, i32 1)
%67 = icmp eq i32 %65, 1
br i1 %67, label %70, label %68
68: ; preds = %64
%69 = call i32 @write(i32 %54, i8* %60, i32 1)
br label %70
70: ; preds = %64, %68
%71 = call i32 @read(i32 %14, i8* %4, i32 2)
%72 = icmp sgt i32 %71, 0
br i1 %72, label %64, label %73
73: ; preds = %70, %56
%74 = tail call i32 @close(i32 %14)
%75 = tail call i32 @close(i32 %34)
%76 = tail call i32 @close(i32 %54)
br label %77
77: ; preds = %73, %61, %36, %16
%78 = phi i32 [ 1, %16 ], [ 2, %36 ], [ 3, %61 ], [ 0, %73 ]
ret i32 %78
}