#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 fileno(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ parse_command(char *);
int /*<<< orphan*/ print_prompt();
size_t read(int, char *, int);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  char *buff = (char *)malloc(sizeof(char) * 1024);
  size_t bytes_read;
  int fd = fileno(stdin);
  print_prompt();
  while ((bytes_read = read(fd, buff, 1024)) > 0) {
    parse_command(buff);
    memset(buff, 0, 1024);
    print_prompt();
  }
  memset(buff, 0, 1024);
  free(buff);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1070 <fileno@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <print_prompt@plt>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jbe    11f0 <main+0x80>
mov    -0x18(%rbp),%rdi
call   1090 <parse_command@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    $0x0,%al
call   1040 <print_prompt@plt>
jmp    11ac <main+0x3c>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1070 <fileno@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <print_prompt@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     11c4 <main+0x54>
call   1090 <parse_command@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
jmp    1190 <main+0x20>
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i64 @malloc(i32 1024)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %6
%11 = load i32, i32* @stdin
%12 = call i32 @fileno(i32 %11)
store i32 %12, i32* %8
%13 = call i32 (...) @print_prompt()
br label %14
14: ; preds = %19, %2
%15 = load i32, i32* %8
%16 = load i8*, i8** %6
%17 = call i64 @read(i32 %15, i8* %16, i32 1024)
store i64 %17, i64* %7
%18 = icmp ugt i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = call i32 @parse_command(i8* %20)
%22 = load i8*, i8** %6
%23 = call i32 @memset(i8* %22, i32 0, i32 1024)
%24 = call i32 (...) @print_prompt()
br label %14
25: ; preds = %14
%26 = load i8*, i8** %6
%27 = call i32 @memset(i8* %26, i32 0, i32 1024)
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 1024)
%4 = inttoptr i64 %3 to i8*
%5 = load i32, i32* @stdin
%6 = tail call i32 @fileno(i32 %5)
%7 = tail call i32 (...) @print_prompt()
%8 = tail call i64 @read(i32 %6, i8* %4, i32 1024)
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %2, %10
%11 = tail call i32 @parse_command(i8* %4)
%12 = tail call i32 @memset(i8* %4, i32 0, i32 1024)
%13 = tail call i32 (...) @print_prompt()
%14 = tail call i64 @read(i32 %6, i8* %4, i32 1024)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %10
16: ; preds = %10, %2
%17 = tail call i32 @memset(i8* %4, i32 0, i32 1024)
%18 = tail call i32 @free(i8* %4)
ret i32 0
}