#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
char getchar();
scalar_t__ malloc(int);
char *realloc(char *, int);
char *read_input() {
  char in_char;
  int string_size = 80 * sizeof(char);
  int count = 0;
  char *string = (char *)malloc(string_size);
  assert(string != NULL);
  for (in_char = getchar(); in_char != '\n'; in_char = getchar()) {
    if (count >= string_size) {
      string_size += 256;
      string = realloc(string, string_size);
      assert(string != NULL);
    }
    string[count] = in_char;
    count++;
  }
  string[count] = '\0';
  return string;
}


x86 assembly (clang, -O0):
<read_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x50,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0xa,%eax
je     11ea <read_input+0xaa>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     11c4 <read_input+0x84>
mov    -0x8(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x1(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x1(%rbp)
jmp    117e <read_input+0x3e>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_input>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x50,%r14d
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     11c4 <read_input+0x84>
mov    %eax,%ebx
xor    %ebp,%ebp
jmp    1195 <read_input+0x55>
nopl   0x0(%rax,%rax,1)
mov    %bl,(%r15,%rbp,1)
add    $0x1,%rbp
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %eax,%ebx
cmp    $0xa,%al
je     11c2 <read_input+0x82>
movslq %r14d,%rax
cmp    %rax,%rbp
jl     1180 <read_input+0x40>
add    $0x100,%r14d
mov    %r15,%rdi
mov    %r14d,%esi
call   1060 <realloc@plt>
mov    %rax,%r15
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
jmp    1180 <read_input+0x40>
mov    %ebp,%ebp
movb   $0x0,(%r15,%rbp,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @read_input() {
%1 = tail call i64 @malloc(i32 80)
%2 = inttoptr i64 %1 to i8*
%3 = icmp ne i64 %1, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call signext i8 (...) @getchar()
%7 = icmp eq i8 %6, 10
br i1 %7, label %30, label %8
8: ; preds = %0, %21
%9 = phi i64 [ %25, %21 ], [ 0, %0 ]
%10 = phi i8* [ %23, %21 ], [ %2, %0 ]
%11 = phi i32 [ %22, %21 ], [ 80, %0 ]
%12 = phi i8 [ %26, %21 ], [ %6, %0 ]
%13 = sext i32 %11 to i64
%14 = icmp slt i64 %9, %13
br i1 %14, label %21, label %15
15: ; preds = %8
%16 = add nsw i32 %11, 256
%17 = tail call i8* @realloc(i8* %10, i32 %16)
%18 = icmp ne i8* %17, null
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
br label %21
21: ; preds = %15, %8
%22 = phi i32 [ %16, %15 ], [ %11, %8 ]
%23 = phi i8* [ %17, %15 ], [ %10, %8 ]
%24 = getelementptr inbounds i8, i8* %23, i64 %9
store i8 %12, i8* %24
%25 = add nuw i64 %9, 1
%26 = tail call signext i8 (...) @getchar()
%27 = icmp eq i8 %26, 10
br i1 %27, label %28, label %8
28: ; preds = %21
%29 = and i64 %25, 4294967295
br label %30
30: ; preds = %28, %0
%31 = phi i64 [ 0, %0 ], [ %29, %28 ]
%32 = phi i8* [ %2, %0 ], [ %23, %28 ]
%33 = getelementptr inbounds i8, i8* %32, i64 %31
store i8 0, i8* %33
ret i8* %32
}