#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*/ exit(int);
int /*<<< orphan*/ fgets(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ malloc_usable_size(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_result(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ replace_char(char *, char, char);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int shell() {
  char *source;
  source = (char *)malloc(100 * sizeof(char));
  if (source == NULL) {
    perror("malloc");
    exit(1);
  }
  while (1) {
    printf("> ");
    fgets(source, malloc_usable_size(source), stdin);
    replace_char(source, '\n', '\0');
    if (!strcmp(source, "quit")) {
      break;
    } else {
      print_result(source);
    }
  }
  free(source);
  return 0;
}


x86 assembly (clang, -O0):
<shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11d7 <shell+0x37>
lea    0xe38(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    11dc <shell+0x3c>
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <malloc_usable_size@plt>
mov    -0x10(%rbp),%rdi
mov    %eax,%esi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
call   1070 <fgets@plt>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   10a0 <replace_char@plt>
mov    -0x8(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    123b <shell+0x9b>
jmp    1249 <shell+0xa9>
mov    -0x8(%rbp),%rdi
call   1050 <print_result@plt>
jmp    11dc <shell+0x3c>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shell>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x64,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     122c <shell+0x8c>
mov    %rax,%rbx
lea    0xe46(%rip),%r14
mov    0x2e20(%rip),%r12
lea    0xe3b(%rip),%r15
nop
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <malloc_usable_size@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   10a0 <replace_char@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1216 <shell+0x76>
mov    %rbx,%rdi
call   1050 <print_result@plt>
jmp    11d0 <shell+0x30>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdcd(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"quit\00"
define i32 @shell() {
%1 = alloca i8*
%2 = call i64 @malloc(i32 100)
%3 = inttoptr i64 %2 to i8*
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
br label %10
10: ; preds = %9, %26
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = load i8*, i8** %1
%13 = load i8*, i8** %1
%14 = call i32 @malloc_usable_size(i8* %13)
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %12, i32 %14, i32 %15)
%17 = load i8*, i8** %1
%18 = call i32 @replace_char(i8* %17, i8 signext 10, i8 signext 0)
%19 = load i8*, i8** %1
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %10
br label %27
23: ; preds = %10
%24 = load i8*, i8** %1
%25 = call i32 @print_result(i8* %24)
br label %26
26: ; preds = %23
br label %10
27: ; preds = %22
%28 = load i8*, i8** %1
%29 = call i32 @free(i8* %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [3 x i8] c"> \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"quit\00"
define i32 @shell() {
%1 = tail call i64 @malloc(i32 100)
%2 = inttoptr i64 %1 to i8*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0, %15
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @malloc_usable_size(i8* %2)
%10 = load i32, i32* @stdin
%11 = tail call i32 @fgets(i8* %2, i32 %9, i32 %10)
%12 = tail call i32 @replace_char(i8* %2, i8 signext 10, i8 signext 0)
%13 = tail call i32 @strcmp(i8* %2, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %7
%16 = tail call i32 @print_result(i8* %2)
br label %7
17: ; preds = %7
%18 = tail call i32 @free(i8* %2)
ret i32 0
}