#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 int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int run_cmd(int, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
void shell(int fd) {
  char buf[128];
  int quit = 0;
  while (!quit) {
    printf("plmpower> ");
    fflush(stdout);
    if (fgets(buf, sizeof(buf), stdin)) {
      quit = run_cmd(fd, buf);
    } else
      quit = 1;
  }
}


x86 assembly (clang, -O0):
<shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1171 <shell+0x31>
jmp    11d8 <shell+0x98>
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    -0x90(%rbp),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11c9 <shell+0x89>
mov    -0x4(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1060 <run_cmd@plt>
mov    %eax,-0x94(%rbp)
jmp    11d3 <shell+0x93>
movl   $0x1,-0x94(%rbp)
jmp    1158 <shell+0x18>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shell>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %edi,%ebp
lea    0xea8(%rip),%r14
mov    0x2e79(%rip),%r15
mov    0x2e82(%rip),%r12
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <printf@plt>
mov    (%r15),%edi
call   1050 <fflush@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11a4 <shell+0x64>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <run_cmd@plt>
test   %eax,%eax
je     1170 <shell+0x30>
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"plmpower> \00"
@stdout = global i32 0
@stdin = global i32 0
define void @shell(i32 %0) {
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %5
5: ; preds = %22, %1
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
%8 = xor i1 %7, true
br i1 %8, label %9, label %23
9: ; preds = %5
%10 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = call i32 @fflush(i32 %11)
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i64 @fgets(i8* %13, i32 128, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %9
%18 = load i32, i32* %2
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%20 = call i32 @run_cmd(i32 %18, i8* %19)
store i32 %20, i32* %4
br label %22
21: ; preds = %9
store i32 1, i32* %4
br label %22
22: ; preds = %21, %17
br label %5
23: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"plmpower> \00"
@stdout = global i32 0
@stdin = global i32 0
define void @shell(i32 %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %1, %11
%5 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdout
%7 = call i32 @fflush(i32 %6)
%8 = load i32, i32* @stdin
%9 = call i64 @fgets(i8* %3, i32 128, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %4
%12 = call i32 @run_cmd(i32 %0, i8* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %4, label %14
14: ; preds = %4, %11
ret void
}