#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ install_signal_handlers();
scalar_t__ pause();
int /*<<< orphan*/ sched_create_shell(char *, int *, int *);
int /*<<< orphan*/ shell_request_loop(int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait_for_ready_children(int);
int main(int argc, char *argv[]) {
  int nproc;
  static int request_fd, return_fd;
  sched_create_shell("shell", &request_fd, &return_fd);
  nproc = 0;
  wait_for_ready_children(nproc);
  install_signal_handlers();
  if (nproc == 0) {
    fprintf(stderr, "Scheduler: No tasks. Exiting...\n");
    exit(1);
  }
  shell_request_loop(request_fd, return_fd);
  while (pause())
    ;
  fprintf(stderr, "Internal error: Reached unreachable point\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
lea    0x2ec8(%rip),%rsi
lea    0x2ec5(%rip),%rdx
call   1050 <sched_create_shell@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <wait_for_ready_children@plt>
mov    $0x0,%al
call   1070 <install_signal_handlers@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11df <main+0x6f>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2e77(%rip),%edi
mov    0x2e75(%rip),%esi
call   1030 <shell_request_loop@plt>
mov    $0x0,%al
call   1080 <pause@plt>
cmp    $0x0,%rax
je     1206 <main+0x96>
jmp    11f0 <main+0x80>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xea8(%rip),%rdi
lea    0x2eed(%rip),%rsi
lea    0x2eea(%rip),%rdx
call   1040 <sched_create_shell@plt>
xor    %edi,%edi
call   1030 <wait_for_ready_children@plt>
xor    %eax,%eax
call   1060 <install_signal_handlers@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@main.request_fd = internal global i32 0
@main.return_fd = internal global i32 0
@.str = [6 x i8] c"shell\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Scheduler: No tasks. Exiting...\0A\00"
@.str.2 = [43 x i8] c"Internal error: Reached unreachable point\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @sched_create_shell(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* @main.request_fd, i32* @main.return_fd)
store i32 0, i32* %6
%8 = load i32, i32* %6
%9 = call i32 @wait_for_ready_children(i32 %8)
%10 = call i32 (...) @install_signal_handlers()
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* @main.request_fd
%19 = load i32, i32* @main.return_fd
%20 = call i32 @shell_request_loop(i32 %18, i32 %19)
br label %21
21: ; preds = %24, %17
%22 = call i64 (...) @pause()
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
br label %21
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@main.request_fd = internal global i32 0
@main.return_fd = internal global i32 0
@.str = [6 x i8] c"shell\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Scheduler: No tasks. Exiting...\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @sched_create_shell(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* @main.request_fd, i32* @main.return_fd)
%4 = tail call i32 @wait_for_ready_children(i32 0)
%5 = tail call i32 (...) @install_signal_handlers()
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
}