#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 */
char EOF;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ malloc(int);
int read(int, char *, int);
int /*<<< orphan*/ stdout;
char *createString(int fd) {
  char *buffer = (char *)malloc(sizeof(char) * 512);
  int bytesRead = 1;
  char single;
  int i = 0;
  fflush(stdout);
  while (1 == 1) {
    bytesRead = read(fd, &single, 1);
    if (bytesRead > 0) {
      buffer[i] = single;
      i++;
    }
    if (single == '\n') {
      buffer[i] = '\n';
      break;
    }
    if (single == EOF) {
      buffer[i] = '\n';
      break;
    }
  }
  return buffer;
}


x86 assembly (clang, -O0):
<createString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x200,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x4(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    119a <createString+0x6a>
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
jne    11b8 <createString+0x88>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
jmp    11e4 <createString+0xb4>
movsbl -0x15(%rbp),%eax
mov    0x2e25(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11df <createString+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
jmp    11e4 <createString+0xb4>
jmp    1165 <createString+0x35>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
mov    $0x200,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %ebx,%ebx
lea    0xf(%rsp),%r15
mov    0x2e81(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
movzbl 0xf(%rsp),%ecx
test   %eax,%eax
jle    1192 <createString+0x62>
movslq %ebx,%rbx
mov    %cl,(%r14,%rbx,1)
add    $0x1,%ebx
cmp    $0xa,%cl
je     119d <createString+0x6d>
cmp    (%r12),%cl
jne    1170 <createString+0x40>
movslq %ebx,%rax
movb   $0xa,(%r14,%rax,1)
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@EOF = global i8 0
define i8* @createString(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %2
%7 = call i64 @malloc(i32 512)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %3
store i32 1, i32* %4
store i32 0, i32* %6
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
br label %11
11: ; preds = %1, %44
%12 = load i32, i32* %2
%13 = call i32 @read(i32 %12, i8* %5, i32 1)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i8, i8* %5
%18 = load i8*, i8** %3
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 %17, i8* %21
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %24
24: ; preds = %16, %11
%25 = load i8, i8* %5
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i8*, i8** %3
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 10, i8* %32
br label %45
33: ; preds = %24
%34 = load i8, i8* %5
%35 = sext i8 %34 to i32
%36 = load i8, i8* @EOF
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %35, %37
br i1 %38, label %39, label %44
39: ; preds = %33
%40 = load i8*, i8** %3
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 10, i8* %43
br label %45
44: ; preds = %33
br label %11
45: ; preds = %39, %28
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
@stdout = global i32 0
@EOF = global i8 0
define i8* @createString(i32 %0) {
%2 = alloca i8
%3 = tail call i64 @malloc(i32 512)
%4 = inttoptr i64 %3 to i8*
%5 = load i32, i32* @stdout
%6 = tail call i32 @fflush(i32 %5)
br label %7
7: ; preds = %16, %1
%8 = phi i32 [ 0, %1 ], [ %17, %16 ]
%9 = call i32 @read(i32 %0, i8* %2, i32 1)
%10 = icmp sgt i32 %9, 0
%11 = load i8, i8* %2
br i1 %10, label %12, label %16
12: ; preds = %7
%13 = sext i32 %8 to i64
%14 = getelementptr inbounds i8, i8* %4, i64 %13
store i8 %11, i8* %14
%15 = add nsw i32 %8, 1
br label %16
16: ; preds = %7, %12
%17 = phi i32 [ %15, %12 ], [ %8, %7 ]
%18 = icmp eq i8 %11, 10
%19 = load i8, i8* @EOF
%20 = icmp eq i8 %11, %19
%21 = select i1 %18, i1 true, i1 %20
br i1 %21, label %22, label %7
22: ; preds = %16
%23 = sext i32 %17 to i64
%24 = getelementptr inbounds i8, i8* %4, i64 %23
store i8 10, i8* %24
ret i8* %4
}