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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ bind_handler_sigchld();
int /*<<< orphan*/ createFileP(int);
int dup(int /*<<< orphan*/);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
char **parseCommand(char *);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ printf(char *);
char *readCommand();
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
void parallelExec() {
  signal(SIGUSR1, SIG_IGN);
  bind_handler_sigchld();
  printf("Nota: Premere INVIO per terminare\n");
  int termination_flag = 0;
  int count = 0;
  pid_t pidPadre = getpid();
  do {
    printf("\n> ");
    char *str = readCommand();
    if (str != NULL) {
      termination_flag = 1;
      count++;
      if (fork() == 0) {
        int saved_stdout = dup(STDOUT_FILENO);
        char **command = parseCommand(str);
        kill(pidPadre, SIGUSR1);
        createFileP(count);
        if (execvp(command[0], command) == -1) {
          dup2(saved_stdout, STDOUT_FILENO);
          printf("Comando non riconosciuto.\n");
          exit(EXIT_FAILURE);
        }
      } else {
        pause();
        signal(SIGUSR1, SIG_IGN);
      }
    } else {
      termination_flag = 0;
    }
    free(str);
  } while (termination_flag != 0);
}


x86 assembly (clang, -O0):
<parallelExec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
mov    $0x0,%al
call   1080 <bind_handler_sigchld@plt>
lea    0xde3(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,-0xc(%rbp)
lea    0xde2(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   10a0 <readCommand@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1320 <parallelExec+0x130>
movl   $0x1,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1110 <fork@plt>
cmp    $0x0,%rax
jne    12fd <parallelExec+0x10d>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   1090 <dup@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   10e0 <parseCommand@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2d3b(%rip),%rax
mov    (%rax),%esi
call   10c0 <kill@plt>
mov    -0x8(%rbp),%edi
call   1030 <createFileP@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   10f0 <execvp@plt>
cmp    $0xffffffff,%eax
jne    12f8 <parallelExec+0x108>
mov    -0x1c(%rbp),%edi
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
lea    0xd42(%rip),%rdi
call   1070 <printf@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    131b <parallelExec+0x12b>
mov    $0x0,%al
call   10d0 <pause@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
mov    0x2cc4(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
jmp    1327 <parallelExec+0x137>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
cmpl   $0x0,-0x4(%rbp)
jne    123a <parallelExec+0x4a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parallelExec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2dce(%rip),%r14
mov    (%r14),%edi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
call   10c0 <signal@plt>
xor    %eax,%eax
call   1090 <bind_handler_sigchld@plt>
lea    0xdd3(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %eax,0x4(%rsp)
lea    0xdb8(%rip),%rdi
call   1080 <printf@plt>
xor    %eax,%eax
call   10b0 <readCommand@plt>
test   %rax,%rax
je     1321 <parallelExec+0x121>
mov    %rax,%rbx
mov    $0x1,%ebp
lea    0xd94(%rip),%r15
jmp    12aa <parallelExec+0xaa>
xchg   %ax,%ax
xor    %eax,%eax
call   10e0 <pause@plt>
mov    (%r14),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
call   10c0 <signal@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1080 <printf@plt>
xor    %eax,%eax
call   10b0 <readCommand@plt>
mov    %rax,%rbx
add    $0x1,%ebp
test   %rax,%rax
je     1321 <parallelExec+0x121>
xor    %eax,%eax
call   1120 <fork@plt>
test   %rax,%rax
jne    1270 <parallelExec+0x70>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
call   10a0 <dup@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   10f0 <parseCommand@plt>
mov    %rax,%r13
mov    (%r14),%esi
mov    0x4(%rsp),%edi
call   10d0 <kill@plt>
mov    %ebp,%edi
call   1030 <createFileP@plt>
mov    0x0(%r13),%rdi
mov    %r13,%rsi
call   1100 <execvp@plt>
cmp    $0xffffffff,%eax
jne    1288 <parallelExec+0x88>
mov    0x2cf3(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
call   1070 <dup2@plt>
lea    0xd18(%rip),%rdi
call   1050 <puts@plt>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <free@plt>

LLVM IR (-O0):
@SIGUSR1 = global i32 0
@SIG_IGN = global i32 0
@.str = [35 x i8] c"Nota: Premere INVIO per terminare\0A\00"
@.str.1 = [4 x i8] c"\0A> \00"
@STDOUT_FILENO = global i32 0
@.str.2 = [27 x i8] c"Comando non riconosciuto.\0A\00"
@EXIT_FAILURE = global i32 0
define void @parallelExec() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8**
%7 = load i32, i32* @SIGUSR1
%8 = load i32, i32* @SIG_IGN
%9 = call i32 @signal(i32 %7, i32 %8)
%10 = call i32 (...) @bind_handler_sigchld()
%11 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
store i32 0, i32* %2
%12 = call i32 (...) @getpid()
store i32 %12, i32* %3
br label %13
13: ; preds = %57, %0
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = call i8* (...) @readCommand()
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %53
18: ; preds = %13
store i32 1, i32* %1
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
%21 = call i64 (...) @fork()
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %47
23: ; preds = %18
%24 = load i32, i32* @STDOUT_FILENO
%25 = call i32 @dup(i32 %24)
store i32 %25, i32* %5
%26 = load i8*, i8** %4
%27 = call i8** @parseCommand(i8* %26)
store i8** %27, i8*** %6
%28 = load i32, i32* %3
%29 = load i32, i32* @SIGUSR1
%30 = call i32 @kill(i32 %28, i32 %29)
%31 = load i32, i32* %2
%32 = call i32 @createFileP(i32 %31)
%33 = load i8**, i8*** %6
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %6
%37 = call i32 @execvp(i8* %35, i8** %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %46
39: ; preds = %23
%40 = load i32, i32* %5
%41 = load i32, i32* @STDOUT_FILENO
%42 = call i32 @dup2(i32 %40, i32 %41)
%43 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %23
br label %52
47: ; preds = %18
%48 = call i32 (...) @pause()
%49 = load i32, i32* @SIGUSR1
%50 = load i32, i32* @SIG_IGN
%51 = call i32 @signal(i32 %49, i32 %50)
br label %52
52: ; preds = %47, %46
br label %54
53: ; preds = %13
store i32 0, i32* %1
br label %54
54: ; preds = %53, %52
%55 = load i8*, i8** %4
%56 = call i32 @free(i8* %55)
br label %57
57: ; preds = %54
%58 = load i32, i32* %1
%59 = icmp ne i32 %58, 0
br i1 %59, label %13, label %60
60: ; preds = %57
ret void
}

LLVM IR (-O2):
@SIGUSR1 = global i32 0
@SIG_IGN = global i32 0
@.str.1 = [4 x i8] c"\0A> \00"
@STDOUT_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
@str = [34 x i8] c"Nota: Premere INVIO per terminare\00"
@str.3 = [26 x i8] c"Comando non riconosciuto.\00"
define void @parallelExec() {
%1 = load i32, i32* @SIGUSR1
%2 = load i32, i32* @SIG_IGN
%3 = tail call i32 @signal(i32 %1, i32 %2)
%4 = tail call i32 (...) @bind_handler_sigchld()
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i8* (...) @readCommand()
%9 = icmp eq i8* %8, null
br i1 %9, label %42, label %10
10: ; preds = %0, %37
%11 = phi i8* [ %40, %37 ], [ %8, %0 ]
%12 = phi i32 [ %13, %37 ], [ 0, %0 ]
%13 = add nuw nsw i32 %12, 1
%14 = tail call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %32
16: ; preds = %10
%17 = load i32, i32* @STDOUT_FILENO
%18 = tail call i32 @dup(i32 %17)
%19 = tail call i8** @parseCommand(i8* %11)
%20 = load i32, i32* @SIGUSR1
%21 = tail call i32 @kill(i32 %6, i32 %20)
%22 = tail call i32 @createFileP(i32 %13)
%23 = load i8*, i8** %19
%24 = tail call i32 @execvp(i8* %23, i8** %19)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %37
26: ; preds = %16
%27 = load i32, i32* @STDOUT_FILENO
%28 = tail call i32 @dup2(i32 %18, i32 %27)
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.3, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %10
%33 = tail call i32 (...) @pause()
%34 = load i32, i32* @SIGUSR1
%35 = load i32, i32* @SIG_IGN
%36 = tail call i32 @signal(i32 %34, i32 %35)
br label %37
37: ; preds = %16, %32
%38 = tail call i32 @free(i8* %11)
%39 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%40 = tail call i8* (...) @readCommand()
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %10
42: ; preds = %37, %0
%43 = tail call i32 @free(i8* null)
ret void
}