#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ cd(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ignoreSignal(int /*<<< orphan*/);
int /*<<< orphan*/ parseCommand(char *, char **, char **);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quit(int /*<<< orphan*/);
int /*<<< orphan*/ readCommand(char *, int);
int /*<<< orphan*/ runCommand(char *, char **);
scalar_t__ strcmp(char *, char *);
int waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char buffer[(70)];
  char *command;
  char *args[(5) + 2];
  pid_t child_pid;
  args[(5) + 1] = NULL;
  ignoreSignal(SIGINT);
  ignoreSignal(SIGTERM);
  while (1) {
    while ((child_pid = waitpid(-1, NULL, WNOHANG)) > 0) {
      printf("Background process %d terminated\n", child_pid);
    }
    printf("minishell>");
    readCommand(buffer, (70));
    parseCommand(buffer, &command, args);
    if (command == NULL) {
      continue;
    }
    if (strcmp(command, "exit") == 0) {
      quit(0);
    } else if (strcmp(command, "cd") == 0) {
      cd(args[1]);
    } else {
      runCommand(command, args);
    }
  }
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x70(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1090 <ignoreSignal@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1090 <ignoreSignal@plt>
jmp    11d2 <main+0x42>
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <waitpid@plt>
mov    %eax,-0xa4(%rbp)
cmp    $0x0,%eax
jle    1211 <main+0x81>
mov    -0xa4(%rbp),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d2 <main+0x42>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x46,%esi
call   1070 <readCommand@plt>
lea    -0x60(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    -0x68(%rbp),%rsi
call   10b0 <parseCommand@plt>
cmpq   $0x0,-0x68(%rbp)
jne    1251 <main+0xc1>
jmp    11cd <main+0x3d>
mov    -0x68(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1277 <main+0xe7>
xor    %edi,%edi
call   1050 <quit@plt>
jmp    12b7 <main+0x127>
mov    -0x68(%rbp),%rdi
lea    0xdb0(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12a2 <main+0x112>
mov    -0x98(%rbp),%rdi
call   1030 <cd@plt>
jmp    12b2 <main+0x122>
mov    -0x68(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1060 <runCommand@plt>
jmp    12b7 <main+0x127>
jmp    11cd <main+0x3d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
movq   $0x0,0x40(%rsp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1090 <ignoreSignal@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1090 <ignoreSignal@plt>
mov    0x2e0b(%rip),%rbp
lea    0xe2c(%rip),%rbx
lea    0xe47(%rip),%r14
lea    0x50(%rsp),%r15
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%r13
jmp    11fc <main+0x6c>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%edx
mov    $0xffffffff,%edi
xor    %esi,%esi
call   10a0 <waitpid@plt>
test   %eax,%eax
jg     11f0 <main+0x60>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    $0x46,%esi
call   1070 <readCommand@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   10b0 <parseCommand@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11fc <main+0x6c>
lea    0xde8(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1274 <main+0xe4>
mov    0x8(%rsp),%rdi
lea    0xdd7(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1280 <main+0xf0>
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1060 <runCommand@plt>
jmp    11fc <main+0x6c>
xor    %edi,%edi
call   1050 <quit@plt>
jmp    11fc <main+0x6c>
mov    0x18(%rsp),%rdi
call   1030 <cd@plt>
jmp    11fc <main+0x6c>

LLVM IR (-O0):
@SIGINT = global i32 0
@SIGTERM = global i32 0
@WNOHANG = global i32 0
@.str = [34 x i8] c"Background process %d terminated\0A\00"
@.str.1 = [11 x i8] c"minishell>\00"
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [3 x i8] c"cd\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [70 x i8]
%7 = alloca i8*
%8 = alloca [7 x i8*]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 6
store i8* null, i8** %10
%11 = load i32, i32* @SIGINT
%12 = call i32 @ignoreSignal(i32 %11)
%13 = load i32, i32* @SIGTERM
%14 = call i32 @ignoreSignal(i32 %13)
br label %15
15: ; preds = %2, %32, %52
br label %16
16: ; preds = %20, %15
%17 = load i32, i32* @WNOHANG
%18 = call i32 @waitpid(i32 -1, i32* null, i32 %17)
store i32 %18, i32* %9
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %9
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %16
23: ; preds = %16
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds [70 x i8], [70 x i8]* %6, i64 0, i64 0
%26 = call i32 @readCommand(i8* %25, i32 70)
%27 = getelementptr inbounds [70 x i8], [70 x i8]* %6, i64 0, i64 0
%28 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 0
%29 = call i32 @parseCommand(i8* %27, i8** %7, i8** %28)
%30 = load i8*, i8** %7
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %23
br label %15
33: ; preds = %23
%34 = load i8*, i8** %7
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @quit(i32 0)
br label %52
39: ; preds = %33
%40 = load i8*, i8** %7
%41 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 1
%45 = load i8*, i8** %44
%46 = call i32 @cd(i8* %45)
br label %51
47: ; preds = %39
%48 = load i8*, i8** %7
%49 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 0
%50 = call i32 @runCommand(i8* %48, i8** %49)
br label %51
51: ; preds = %47, %43
br label %52
52: ; preds = %51, %37
br label %15
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIGTERM = global i32 0
@WNOHANG = global i32 0
@.str = [34 x i8] c"Background process %d terminated\0A\00"
@.str.1 = [11 x i8] c"minishell>\00"
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [3 x i8] c"cd\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [70 x i8]
%4 = alloca i8*
%5 = alloca [7 x i8*]
%6 = getelementptr inbounds [70 x i8], [70 x i8]* %3, i64 0, i64 0
%7 = bitcast i8** %4 to i8*
%8 = bitcast [7 x i8*]* %5 to i8*
%9 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i64 0, i64 6
store i8* null, i8** %9
%10 = load i32, i32* @SIGINT
%11 = tail call i32 @ignoreSignal(i32 %10)
%12 = load i32, i32* @SIGTERM
%13 = tail call i32 @ignoreSignal(i32 %12)
%14 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i64 0, i64 0
%15 = getelementptr inbounds [7 x i8*], [7 x i8*]* %5, i64 0, i64 1
br label %16
16: ; preds = %37, %2
%17 = load i32, i32* @WNOHANG
%18 = call i32 @waitpid(i32 -1, i32* null, i32 %17)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %16, %20
%21 = phi i32 [ %24, %20 ], [ %18, %16 ]
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @WNOHANG
%24 = call i32 @waitpid(i32 -1, i32* null, i32 %23)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %20, label %26
26: ; preds = %20, %16
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @readCommand(i8* %6, i32 70)
%29 = call i32 @parseCommand(i8* %6, i8** %4, i8** %14)
%30 = load i8*, i8** %4
%31 = icmp eq i8* %30, null
br i1 %31, label %37, label %32
32: ; preds = %26
%33 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = call i32 @quit(i32 0)
br label %37
37: ; preds = %35, %45, %42, %26
br label %16
38: ; preds = %32
%39 = load i8*, i8** %4
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i8*, i8** %15
%44 = call i32 @cd(i8* %43)
br label %37
45: ; preds = %38
%46 = load i8*, i8** %4
%47 = call i32 @runCommand(i8* %46, i8** %14)
br label %37
}