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

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int read_return = 0;
  int i = 0;
  int array_index = 0;
  char read_all[30];
  char read_burst[5];
  printf("Write a string(Press ctrl+D to stop reading): \n");
  do {
    read_return = read(0, read_burst, 5);
    if (read_return != 0) {
      for (i = 0; i < 5; i++) {
        read_all[array_index] = read_burst[i];
        array_index = ++array_index;
      };
    }
  } while (read_return != 0);
  printf("You wrote: \n");
  for (i = 0; i < 3; i++) {
    write(1, read_all, sizeof(read_all));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x45(%rbp),%rsi
xor    %edi,%edi
mov    $0x5,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c4 <main+0x94>
movl   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    11bf <main+0x8f>
movslq -0x18(%rbp),%rax
mov    -0x45(%rbp,%rax,1),%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118b <main+0x5b>
jmp    11c4 <main+0x94>
jmp    11c9 <main+0x99>
cmpl   $0x0,-0x14(%rbp)
jne    1167 <main+0x37>
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    1211 <main+0xe1>
lea    -0x40(%rbp),%rsi
mov    $0x1,%edi
mov    $0x1e,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e6 <main+0xb6>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
lea    0xb(%rsp),%rsi
xor    %edi,%edi
mov    $0x5,%edx
call   1050 <read@plt>
test   %eax,%eax
je     118b <main+0x5b>
xor    %ebx,%ebx
lea    0xb(%rsp),%r14
nop
movslq %ebx,%rbx
movzbl 0xf(%rsp),%eax
mov    %al,0x14(%rsp,%rbx,1)
mov    0xb(%rsp),%eax
mov    %eax,0x10(%rsp,%rbx,1)
add    $0x5,%rbx
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x5,%edx
call   1050 <read@plt>
test   %eax,%eax
jne    1160 <main+0x30>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1e,%edx
call   1040 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1e,%edx
call   1040 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1e,%edx
call   1040 <write@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Write a string(Press ctrl+D to stop reading): \0A\00"
@.str.1 = [13 x i8] c"You wrote: \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 [30 x i8]
%10 = alloca [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%11 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %36, %2
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%14 = call i32 @read(i32 0, i8* %13, i32 5)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %35
17: ; preds = %12
store i32 0, i32* %7
br label %18
18: ; preds = %31, %17
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 5
br i1 %20, label %21, label %34
21: ; preds = %18
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 %27
store i8 %25, i8* %28
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
store i32 %30, i32* %8
br label %31
31: ; preds = %21
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %18
34: ; preds = %18
br label %35
35: ; preds = %34, %12
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 0
br i1 %38, label %12, label %39
39: ; preds = %36
%40 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %41
41: ; preds = %47, %39
%42 = load i32, i32* %7
%43 = icmp slt i32 %42, 3
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%46 = call i32 @write(i32 1, i8* %45, i32 30)
br label %47
47: ; preds = %44
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %41
50: ; preds = %41
ret i32 0
}

LLVM IR (-O2):
@str = [47 x i8] c"Write a string(Press ctrl+D to stop reading): \00"
@str.2 = [12 x i8] c"You wrote: \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [30 x i8]
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%9 = call i32 @read(i32 0, i8* %7, i32 5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %2, %11
%12 = phi i64 [ %16, %11 ], [ 0, %2 ]
%13 = shl i64 %12, 32
%14 = ashr exact i64 %13, 32
%15 = getelementptr [30 x i8], [30 x i8]* %3, i64 0, i64 %14
%16 = add nsw i64 %14, 5
%17 = call i32 @read(i32 0, i8* %7, i32 5)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %11
19: ; preds = %11, %2
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.2, i64 0, i64 0))
%21 = call i32 @write(i32 1, i8* %6, i32 30)
%22 = call i32 @write(i32 1, i8* %6, i32 30)
%23 = call i32 @write(i32 1, i8* %6, i32 30)
ret i32 0
}