#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_chars;
typedef int /*<<< orphan*/ burst_read;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int success_open = 0;
  char file_chars[50];
  char burst_read[5];
  int read_return = 0;
  int write_return = 0;
  int write_return_print = 0;
  int array_index = 0;
  int bytesRead = 0;
  int fifoFile = 0;
  int i = 0;
  success_open = open(argv[1], O_CREAT | O_WRONLY, 0777);
  for (i = 0; i < sizeof(file_chars); i++) {
    file_chars[i] = ' ';
  }
  for (i = 0; i < sizeof(burst_read); i++) {
    burst_read[i] = ' ';
  }
  do {
    read_return = read(0, burst_read, 5);
    if (read_return != 0) {
      for (i = 0; i < 5; i++) {
        file_chars[array_index] = burst_read[i];
        array_index = ++array_index;
      };
    }
    bytesRead = bytesRead + read_return;
    write_return_print = write(1, file_chars, bytesRead);
    write_return = write(success_open, file_chars, bytesRead);
    for (i = 0; i < sizeof(file_chars); i++) {
      file_chars[i] = ' ';
    }
    array_index = 0;
    bytesRead = 0;
  } while (read_return != 0);
  printf("DONE\n");
  close(success_open);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
movl   $0x0,-0x70(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    0x2e17(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x74(%rbp)
movslq -0x74(%rbp),%rax
cmp    $0x32,%rax
jae    11f4 <main+0xa4>
movslq -0x74(%rbp),%rax
movb   $0x20,-0x50(%rbp,%rax,1)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11cf <main+0x7f>
movl   $0x0,-0x74(%rbp)
movslq -0x74(%rbp),%rax
cmp    $0x5,%rax
jae    1220 <main+0xd0>
movslq -0x74(%rbp),%rax
movb   $0x20,-0x55(%rbp,%rax,1)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11fb <main+0xab>
jmp    1225 <main+0xd5>
lea    -0x55(%rbp),%rsi
xor    %edi,%edi
mov    $0x5,%edx
call   1060 <read@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     1282 <main+0x132>
movl   $0x0,-0x74(%rbp)
cmpl   $0x5,-0x74(%rbp)
jge    127d <main+0x12d>
movslq -0x74(%rbp),%rax
mov    -0x55(%rbp,%rax,1),%cl
movslq -0x68(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
mov    %eax,-0x68(%rbp)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1249 <main+0xf9>
jmp    1282 <main+0x132>
mov    -0x6c(%rbp),%eax
add    -0x5c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
lea    -0x50(%rbp),%rsi
mov    -0x6c(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    %eax,-0x64(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x6c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x60(%rbp)
movl   $0x0,-0x74(%rbp)
movslq -0x74(%rbp),%rax
cmp    $0x32,%rax
jae    12dd <main+0x18d>
movslq -0x74(%rbp),%rax
movb   $0x20,-0x50(%rbp,%rax,1)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    12b8 <main+0x168>
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    1225 <main+0xd5>
lea    0xd04(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e93(%rip),%rax
mov    0x2e64(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,%r14d
movaps 0xe7c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movw   $0x2020,0x40(%rsp)
movl   $0x20202020,0x8(%rsp)
20
movb   $0x20,0xc(%rsp)
lea    0x8(%rsp),%rsi
xor    %edi,%edi
mov    $0x5,%edx
call   1060 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
je     122f <main+0xdf>
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r15
nopl   0x0(%rax,%rax,1)
movzbl 0xc(%rsp),%eax
mov    %al,0x14(%rsp)
mov    0x8(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
movaps 0xdfc(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movw   $0x2020,0x40(%rsp)
xor    %edi,%edi
mov    %r15,%rsi
mov    $0x5,%edx
call   1060 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11d0 <main+0x80>
lea    0x10(%rsp),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
movaps 0xda9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movw   $0x2020,0x40(%rsp)
lea    0xd9c(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str = [6 x i8] c"DONE\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [50 x i8]
%8 = alloca [5 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_CREAT
%20 = load i32, i32* @O_WRONLY
%21 = or i32 %19, %20
%22 = call i32 @open(i8* %18, i32 %21, i32 511)
store i32 %22, i32* %6
store i32 0, i32* %15
br label %23
23: ; preds = %31, %2
%24 = load i32, i32* %15
%25 = sext i32 %24 to i64
%26 = icmp ult i64 %25, 50
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = load i32, i32* %15
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 %29
store i8 32, i8* %30
br label %31
31: ; preds = %27
%32 = load i32, i32* %15
%33 = add nsw i32 %32, 1
store i32 %33, i32* %15
br label %23
34: ; preds = %23
store i32 0, i32* %15
br label %35
35: ; preds = %43, %34
%36 = load i32, i32* %15
%37 = sext i32 %36 to i64
%38 = icmp ult i64 %37, 5
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = load i32, i32* %15
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 %41
store i8 32, i8* %42
br label %43
43: ; preds = %39
%44 = load i32, i32* %15
%45 = add nsw i32 %44, 1
store i32 %45, i32* %15
br label %35
46: ; preds = %35
br label %47
47: ; preds = %93, %46
%48 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%49 = call i32 @read(i32 0, i8* %48, i32 5)
store i32 %49, i32* %9
%50 = load i32, i32* %9
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %70
52: ; preds = %47
store i32 0, i32* %15
br label %53
53: ; preds = %66, %52
%54 = load i32, i32* %15
%55 = icmp slt i32 %54, 5
br i1 %55, label %56, label %69
56: ; preds = %53
%57 = load i32, i32* %15
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = load i32, i32* %12
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 %62
store i8 %60, i8* %63
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
store i32 %65, i32* %12
br label %66
66: ; preds = %56
%67 = load i32, i32* %15
%68 = add nsw i32 %67, 1
store i32 %68, i32* %15
br label %53
69: ; preds = %53
br label %70
70: ; preds = %69, %47
%71 = load i32, i32* %13
%72 = load i32, i32* %9
%73 = add nsw i32 %71, %72
store i32 %73, i32* %13
%74 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%75 = load i32, i32* %13
%76 = call i32 @write(i32 1, i8* %74, i32 %75)
store i32 %76, i32* %11
%77 = load i32, i32* %6
%78 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%79 = load i32, i32* %13
%80 = call i32 @write(i32 %77, i8* %78, i32 %79)
store i32 %80, i32* %10
store i32 0, i32* %15
br label %81
81: ; preds = %89, %70
%82 = load i32, i32* %15
%83 = sext i32 %82 to i64
%84 = icmp ult i64 %83, 50
br i1 %84, label %85, label %92
85: ; preds = %81
%86 = load i32, i32* %15
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 %87
store i8 32, i8* %88
br label %89
89: ; preds = %85
%90 = load i32, i32* %15
%91 = add nsw i32 %90, 1
store i32 %91, i32* %15
br label %81
92: ; preds = %81
store i32 0, i32* %12
store i32 0, i32* %13
br label %93
93: ; preds = %92
%94 = load i32, i32* %9
%95 = icmp ne i32 %94, 0
br i1 %95, label %47, label %96
96: ; preds = %93
%97 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%98 = load i32, i32* %6
%99 = call i32 @close(i32 %98)
ret i32 0
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@str = [5 x i8] c"DONE\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = alloca [5 x i8]
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_WRONLY
%13 = or i32 %12, %11
%14 = tail call i32 @open(i8* %10, i32 %13, i32 511)
%15 = call i32 @read(i32 0, i8* %8, i32 5)
%16 = icmp eq i32 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %2, %17
%18 = phi i32 [ %21, %17 ], [ %15, %2 ]
%19 = call i32 @write(i32 1, i8* %7, i32 %18)
%20 = call i32 @write(i32 %14, i8* %7, i32 %18)
%21 = call i32 @read(i32 0, i8* %8, i32 5)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %17
23: ; preds = %17, %2
%24 = phi i32 [ %15, %2 ], [ %21, %17 ]
%25 = call i32 @write(i32 1, i8* %7, i32 %24)
%26 = call i32 @write(i32 %14, i8* %7, i32 %24)
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%28 = tail call i32 @close(i32 %14)
ret i32 0
}