#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 array_index = 0;
  int bytesRead = 0;
  int i = 0;
  for (i = 0; i < sizeof(file_chars); i++) {
    file_chars[i] = 0;
  }
  for (i = 0; i < sizeof(burst_read); i++) {
    burst_read[i] = 0;
  }
  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;
  } while (read_return != 0);
  if (argc > 1) {
    success_open = open(argv[1], O_CREAT | O_WRONLY, 0777);
    write_return = write(success_open, file_chars, bytesRead);
    printf("DONE\n");
    close(success_open);
  } else {
    write_return = write(1, file_chars, bytesRead);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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,-0x6c(%rbp)
movslq -0x6c(%rbp),%rax
cmp    $0x32,%rax
jae    11bc <main+0x6c>
movslq -0x6c(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1197 <main+0x47>
movl   $0x0,-0x6c(%rbp)
movslq -0x6c(%rbp),%rax
cmp    $0x5,%rax
jae    11e8 <main+0x98>
movslq -0x6c(%rbp),%rax
movb   $0x0,-0x55(%rbp,%rax,1)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11c3 <main+0x73>
jmp    11ed <main+0x9d>
lea    -0x55(%rbp),%rsi
xor    %edi,%edi
mov    $0x5,%edx
call   1060 <read@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     124a <main+0xfa>
movl   $0x0,-0x6c(%rbp)
cmpl   $0x5,-0x6c(%rbp)
jge    1245 <main+0xf5>
movslq -0x6c(%rbp),%rax
mov    -0x55(%rbp,%rax,1),%cl
movslq -0x64(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    %eax,-0x64(%rbp)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1211 <main+0xc1>
jmp    124a <main+0xfa>
mov    -0x68(%rbp),%eax
add    -0x5c(%rbp),%eax
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    11ed <main+0x9d>
cmpl   $0x1,-0x8(%rbp)
jle    12b9 <main+0x169>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
mov    0x2d51(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x68(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x60(%rbp)
lea    0xd59(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    12cd <main+0x17d>
lea    -0x50(%rbp),%rsi
mov    -0x68(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    %eax,-0x60(%rbp)
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movw   $0x0,0x40(%rsp)
movl   $0x0,0x8(%rsp)
movb   $0x0,0xc(%rsp)
xor    %ebx,%ebx
lea    0x8(%rsp),%rsi
xor    %edi,%edi
mov    $0x5,%edx
call   1060 <read@plt>
test   %eax,%eax
je     11dd <main+0x8d>
xor    %ebx,%ebx
lea    0x8(%rsp),%r12
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
add    %eax,%ebx
movslq %ebp,%rbp
movzbl 0xc(%rsp),%eax
mov    %al,0x14(%rsp,%rbp,1)
mov    0x8(%rsp),%eax
mov    %eax,0x10(%rsp,%rbp,1)
add    $0x5,%rbp
xor    %edi,%edi
mov    %r12,%rsi
mov    $0x5,%edx
call   1060 <read@plt>
test   %eax,%eax
jne    11b0 <main+0x60>
cmp    $0x2,%r15d
jl     1228 <main+0xd8>
mov    0x8(%r14),%rdi
mov    0x2e0a(%rip),%rax
mov    0x2ddb(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1ff,%edx
call   1070 <open@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    %ebx,%edx
call   1040 <write@plt>
lea    0xde6(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    1239 <main+0xe9>
lea    0x10(%rsp),%rsi
mov    $0x1,%edi
mov    %ebx,%edx
call   1040 <write@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
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
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* %13
br label %14
14: ; preds = %22, %2
%15 = load i32, i32* %13
%16 = sext i32 %15 to i64
%17 = icmp ult i64 %16, 50
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i32, i32* %13
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %18
%23 = load i32, i32* %13
%24 = add nsw i32 %23, 1
store i32 %24, i32* %13
br label %14
25: ; preds = %14
store i32 0, i32* %13
br label %26
26: ; preds = %34, %25
%27 = load i32, i32* %13
%28 = sext i32 %27 to i64
%29 = icmp ult i64 %28, 5
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = load i32, i32* %13
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %30
%35 = load i32, i32* %13
%36 = add nsw i32 %35, 1
store i32 %36, i32* %13
br label %26
37: ; preds = %26
br label %38
38: ; preds = %65, %37
%39 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%40 = call i32 @read(i32 0, i8* %39, i32 5)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %61
43: ; preds = %38
store i32 0, i32* %13
br label %44
44: ; preds = %57, %43
%45 = load i32, i32* %13
%46 = icmp slt i32 %45, 5
br i1 %46, label %47, label %60
47: ; preds = %44
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 %53
store i8 %51, i8* %54
%55 = load i32, i32* %11
%56 = add nsw i32 %55, 1
store i32 %56, i32* %11
store i32 %56, i32* %11
br label %57
57: ; preds = %47
%58 = load i32, i32* %13
%59 = add nsw i32 %58, 1
store i32 %59, i32* %13
br label %44
60: ; preds = %44
br label %61
61: ; preds = %60, %38
%62 = load i32, i32* %12
%63 = load i32, i32* %9
%64 = add nsw i32 %62, %63
store i32 %64, i32* %12
br label %65
65: ; preds = %61
%66 = load i32, i32* %9
%67 = icmp ne i32 %66, 0
br i1 %67, label %38, label %68
68: ; preds = %65
%69 = load i32, i32* %4
%70 = icmp sgt i32 %69, 1
br i1 %70, label %71, label %86
71: ; preds = %68
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 1
%74 = load i8*, i8** %73
%75 = load i32, i32* @O_CREAT
%76 = load i32, i32* @O_WRONLY
%77 = or i32 %75, %76
%78 = call i32 @open(i8* %74, i32 %77, i32 511)
store i32 %78, i32* %6
%79 = load i32, i32* %6
%80 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%81 = load i32, i32* %12
%82 = call i32 @write(i32 %79, i8* %80, i32 %81)
store i32 %82, i32* %10
%83 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%84 = load i32, i32* %6
%85 = call i32 @close(i32 %84)
br label %90
86: ; preds = %68
%87 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%88 = load i32, i32* %12
%89 = call i32 @write(i32 1, i8* %87, i32 %88)
store i32 %89, i32* %10
br label %90
90: ; preds = %86, %71
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 = call i32 @read(i32 0, i8* %8, i32 5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %2, %11
%12 = phi i32 [ %20, %11 ], [ %9, %2 ]
%13 = phi i32 [ %19, %11 ], [ 0, %2 ]
%14 = phi i64 [ %18, %11 ], [ 0, %2 ]
%15 = shl i64 %14, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr [50 x i8], [50 x i8]* %3, i64 0, i64 %16
%18 = add nsw i64 %16, 5
%19 = add nsw i32 %12, %13
%20 = call i32 @read(i32 0, i8* %8, i32 5)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %11
22: ; preds = %11, %2
%23 = phi i32 [ 0, %2 ], [ %19, %11 ]
%24 = icmp sgt i32 %0, 1
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_CREAT
%29 = load i32, i32* @O_WRONLY
%30 = or i32 %29, %28
%31 = tail call i32 @open(i8* %27, i32 %30, i32 511)
%32 = call i32 @write(i32 %31, i8* %7, i32 %23)
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%34 = tail call i32 @close(i32 %31)
br label %37
35: ; preds = %22
%36 = call i32 @write(i32 1, i8* %7, i32 %23)
br label %37
37: ; preds = %35, %25
ret i32 0
}