#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 EOF;
int fgetc(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ stdin;
char *readFromStdin(int size) {
  char *str = malloc(size);
  int ch;
  int i = 0;
  while (1) {
    ch = fgetc(stdin);
    if (ch == EOF)
      break;
    if (ch == '\n')
      break;
    str[i] = ch;
    i++;
  }
  return str;
}


x86 assembly (clang, -O0):
<readFromStdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%eax
jne    1166 <readFromStdin+0x46>
jmp    1193 <readFromStdin+0x73>
cmpl   $0xa,-0x14(%rbp)
jne    1175 <readFromStdin+0x55>
jmp    1193 <readFromStdin+0x73>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <readFromStdin+0x1e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFromStdin>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
call   1040 <malloc@plt>
mov    %rax,%r14
mov    0x2eb1(%rip),%r15
mov    (%r15),%edi
call   1030 <fgetc@plt>
cmp    $0xa,%eax
je     1179 <readFromStdin+0x59>
mov    0x2e95(%rip),%r12
cmp    (%r12),%eax
je     1179 <readFromStdin+0x59>
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %al,(%rbx)
mov    (%r15),%edi
call   1030 <fgetc@plt>
cmp    $0xa,%eax
je     1179 <readFromStdin+0x59>
add    $0x1,%rbx
cmp    (%r12),%eax
jne    1160 <readFromStdin+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
define i8* @readFromStdin(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = call i8* @malloc(i32 %6)
store i8* %7, i8** %3
store i32 0, i32* %5
br label %8
8: ; preds = %1, %19
%9 = load i32, i32* @stdin
%10 = call i32 @fgetc(i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %8
br label %28
15: ; preds = %8
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %19
18: ; preds = %15
br label %28
19: ; preds = %15
%20 = load i32, i32* %4
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %8
28: ; preds = %18, %14
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
define noalias i8* @readFromStdin(i32 %0) {
%2 = tail call i8* @malloc(i32 %0)
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgetc(i32 %3)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
%7 = icmp eq i32 %4, 10
%8 = or i1 %7, %6
br i1 %8, label %21, label %9
9: ; preds = %1, %9
%10 = phi i64 [ %14, %9 ], [ 0, %1 ]
%11 = phi i32 [ %16, %9 ], [ %4, %1 ]
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds i8, i8* %2, i64 %10
store i8 %12, i8* %13
%14 = add nuw i64 %10, 1
%15 = load i32, i32* @stdin
%16 = tail call i32 @fgetc(i32 %15)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
%19 = icmp eq i32 %16, 10
%20 = or i1 %19, %18
br i1 %20, label %21, label %9
21: ; preds = %9, %1
ret i8* %2
}