#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;
char fgetc(int /*<<< orphan*/);
scalar_t__ malloc(int);
scalar_t__ realloc(char *, long);
int /*<<< orphan*/ stdin;
char *read_command() {
  long i = 0;
  char *cmd;
  cmd = (char *)malloc(256 * sizeof(char));
  char c = fgetc(stdin);
  int newline = 0;
  while (newline == 0) {
    while (c != '\n' && c != EOF && i < 256) {
      cmd[i] = c;
      i++;
      c = fgetc(stdin);
    }
    if (c == '\n' || c == EOF) {
      newline = 1;
      cmd[i] = 0;
    } else {
      cmd = (char *)realloc(cmd, i * sizeof(char) + 256);
    }
  }
  return cmd;
}


x86 assembly (clang, -O0):
<read_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    124c <read_command+0x11c>
jmp    1175 <read_command+0x45>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     11b0 <read_command+0x80>
movsbl -0x11(%rbp),%ecx
mov    0x2e4e(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x19(%rbp)
je     11b0 <read_command+0x80>
cmpq   $0x100,-0x8(%rbp)
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11c0 <read_command+0x90>
jmp    11f0 <read_command+0xc0>
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %al,-0x11(%rbp)
jmp    1175 <read_command+0x45>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
je     1213 <read_command+0xe3>
movsbl -0x11(%rbp),%eax
mov    0x2dd8(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    122b <read_command+0xfb>
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1247 <read_command+0x117>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
shl    $0x0,%rsi
add    $0x100,%rsi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
jmp    1166 <read_command+0x36>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_command>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    0x2e9c(%rip),%r15
mov    (%r15),%edi
call   1030 <fgetc@plt>
cmp    $0xa,%al
jne    116b <read_command+0x3b>
xor    %ebx,%ebx
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
xor    %ebx,%ebx
mov    0x2e6a(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
movzbl (%r12),%eax
cmp    %al,%bpl
je     11ab <read_command+0x7b>
cmp    $0xff,%rbx
jg     11ab <read_command+0x7b>
mov    %bpl,(%r14,%rbx,1)
add    $0x1,%rbx
mov    (%r15),%edi
call   1030 <fgetc@plt>
mov    %eax,%ebp
cmp    $0xa,%al
jne    1180 <read_command+0x50>
jmp    115a <read_command+0x2a>
cmp    %al,%bpl
je     115a <read_command+0x2a>
lea    0x100(%rbx),%rsi
mov    %r14,%rdi
call   1050 <realloc@plt>
mov    %rax,%r14
cmp    $0xa,%bpl
jne    1180 <read_command+0x50>
jmp    115a <read_command+0x2a>

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i8 0
define i8* @read_command() {
%1 = alloca i64
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
store i64 0, i64* %1
%5 = call i64 @malloc(i32 256)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %2
%7 = load i32, i32* @stdin
%8 = call signext i8 @fgetc(i32 %7)
store i8 %8, i8* %3
store i32 0, i32* %4
br label %9
9: ; preds = %58, %0
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %59
12: ; preds = %9
br label %13
13: ; preds = %28, %12
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 10
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = load i8, i8* @EOF
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %19, %21
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i64, i64* %1
%25 = icmp slt i64 %24, 256
br label %26
26: ; preds = %23, %17, %13
%27 = phi i1 [ false, %17 ], [ false, %13 ], [ %25, %23 ]
br i1 %27, label %28, label %37
28: ; preds = %26
%29 = load i8, i8* %3
%30 = load i8*, i8** %2
%31 = load i64, i64* %1
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8 %29, i8* %32
%33 = load i64, i64* %1
%34 = add nsw i64 %33, 1
store i64 %34, i64* %1
%35 = load i32, i32* @stdin
%36 = call signext i8 @fgetc(i32 %35)
store i8 %36, i8* %3
br label %13
37: ; preds = %26
%38 = load i8, i8* %3
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 10
br i1 %40, label %47, label %41
41: ; preds = %37
%42 = load i8, i8* %3
%43 = sext i8 %42 to i32
%44 = load i8, i8* @EOF
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %43, %45
br i1 %46, label %47, label %51
47: ; preds = %41, %37
store i32 1, i32* %4
%48 = load i8*, i8** %2
%49 = load i64, i64* %1
%50 = getelementptr inbounds i8, i8* %48, i64 %49
store i8 0, i8* %50
br label %58
51: ; preds = %41
%52 = load i8*, i8** %2
%53 = load i64, i64* %1
%54 = mul i64 %53, 1
%55 = add i64 %54, 256
%56 = call i64 @realloc(i8* %52, i64 %55)
%57 = inttoptr i64 %56 to i8*
store i8* %57, i8** %2
br label %58
58: ; preds = %51, %47
br label %9
59: ; preds = %9
%60 = load i8*, i8** %2
ret i8* %60
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i8 0
define i8* @read_command() {
%1 = tail call i64 @malloc(i32 256)
%2 = load i32, i32* @stdin
%3 = tail call signext i8 @fgetc(i32 %2)
%4 = inttoptr i64 %1 to i8*
%5 = icmp eq i8 %3, 10
br i1 %5, label %32, label %6
6: ; preds = %0, %25
%7 = phi i8* [ %28, %25 ], [ %4, %0 ]
%8 = phi i64 [ %12, %25 ], [ 0, %0 ]
%9 = phi i8 [ %11, %25 ], [ %3, %0 ]
br label %10
10: ; preds = %6, %17
%11 = phi i8 [ %21, %17 ], [ %9, %6 ]
%12 = phi i64 [ %19, %17 ], [ %8, %6 ]
%13 = load i8, i8* @EOF
%14 = icmp ne i8 %11, %13
%15 = icmp slt i64 %12, 256
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %17, label %23
17: ; preds = %10
%18 = getelementptr inbounds i8, i8* %7, i64 %12
store i8 %11, i8* %18
%19 = add nsw i64 %12, 1
%20 = load i32, i32* @stdin
%21 = tail call signext i8 @fgetc(i32 %20)
%22 = icmp eq i8 %21, 10
br i1 %22, label %32, label %10
23: ; preds = %10
%24 = icmp eq i8 %11, %13
br i1 %24, label %32, label %25
25: ; preds = %23
%26 = add i64 %12, 256
%27 = tail call i64 @realloc(i8* %7, i64 %26)
%28 = inttoptr i64 %27 to i8*
%29 = icmp eq i8 %11, 10
br i1 %29, label %30, label %6
30: ; preds = %25
%31 = inttoptr i64 %27 to i8*
br label %32
32: ; preds = %30, %23, %17, %0
%33 = phi i8* [ %4, %0 ], [ %7, %17 ], [ %31, %30 ], [ %7, %23 ]
%34 = phi i64 [ 0, %0 ], [ %19, %17 ], [ %12, %23 ], [ %12, %30 ]
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8 0, i8* %35
ret i8* %33
}