#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 */
typedef char rcommand;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ resh_cleanup();
int /*<<< orphan*/ resh_eval(char *);
int /*<<< orphan*/ resh_init();
char *resh_parse(char *);
char *resh_read(char *);
int main(void) {
  struct rcommand *cmd;
  char *str;
  resh_init();
  for (;;) {
    str = resh_read("fat-dragon; ");
    if (str == NULL)
      break;
    cmd = resh_parse(str);
    if (cmd == NULL)
      break;
    resh_eval(cmd);
    free(cmd);
    free(str);
  }
  resh_cleanup();
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <resh_init@plt>
lea    0xe83(%rip),%rdi
call   1060 <resh_read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1196 <main+0x36>
jmp    11d3 <main+0x73>
mov    -0x18(%rbp),%rdi
call   1080 <resh_parse@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b3 <main+0x53>
jmp    11d3 <main+0x73>
mov    -0x10(%rbp),%rdi
call   1070 <resh_eval@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1176 <main+0x16>
mov    $0x0,%al
call   1040 <resh_cleanup@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <resh_init@plt>
lea    0xe8d(%rip),%rdi
call   1060 <resh_read@plt>
test   %rax,%rax
je     11c8 <main+0x68>
mov    %rax,%r15
lea    0xe79(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1080 <resh_parse@plt>
test   %rax,%rax
je     11c8 <main+0x68>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <resh_eval@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1060 <resh_read@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1190 <main+0x30>
xor    %eax,%eax
call   1040 <resh_cleanup@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rcommand = type opaque
@.str = [13 x i8] c"fat-dragon; \00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.rcommand*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i32 (...) @resh_init()
br label %5
5: ; preds = %17, %0
%6 = call i8* @resh_read(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %5
br label %26
10: ; preds = %5
%11 = load i8*, i8** %3
%12 = call i8* @resh_parse(i8* %11)
%13 = bitcast i8* %12 to %struct.rcommand*
store %struct.rcommand* %13, %struct.rcommand** %2
%14 = load %struct.rcommand*, %struct.rcommand** %2
%15 = icmp eq %struct.rcommand* %14, null
br i1 %15, label %16, label %17
16: ; preds = %10
br label %26
17: ; preds = %10
%18 = load %struct.rcommand*, %struct.rcommand** %2
%19 = bitcast %struct.rcommand* %18 to i8*
%20 = call i32 @resh_eval(i8* %19)
%21 = load %struct.rcommand*, %struct.rcommand** %2
%22 = bitcast %struct.rcommand* %21 to i8*
%23 = call i32 @free(i8* %22)
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
br label %5
26: ; preds = %16, %9
%27 = call i32 (...) @resh_cleanup()
%28 = load i32, i32* @EXIT_SUCCESS
ret i32 %28
}

LLVM IR (-O2):
@.str = [13 x i8] c"fat-dragon; \00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @resh_init()
%2 = tail call i8* @resh_read(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %14, label %4
4: ; preds = %0, %8
%5 = phi i8* [ %12, %8 ], [ %2, %0 ]
%6 = tail call i8* @resh_parse(i8* %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = tail call i32 @resh_eval(i8* %6)
%10 = tail call i32 @free(i8* %6)
%11 = tail call i32 @free(i8* %5)
%12 = tail call i8* @resh_read(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %4
14: ; preds = %8, %4, %0
%15 = tail call i32 (...) @resh_cleanup()
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
}