#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 EXIT_SUCCESS;
scalar_t__ WCOREDUMP(int);
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ abort();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exec_ps_cmd();
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid;
  pid_t wpid;
  int status;
  pid = fork();
  if (pid < 0) {
    fprintf(stderr, "%s: fork() fallita\n", strerror(errno));
    exit(13);
  }
  if (pid == 0) {
    printf("PID %ld: Processo figlio parte - Il processo padre %ld\n",
           (long)getpid(), (long)getppid());
    exec_ps_cmd();
  } else {
    printf("PID %ld: Processo figlio partito - Il processo padre %ld\n",
           (long)getpid(), (long)pid);
    wpid = waitpid(-1, &status, 0);
    if (wpid == -1) {
      fprintf(stderr, "%s: wait()\n", strerror(errno));
      return 1;
    }
    if (wpid != pid)
      abort();
    else {
      if (WIFEXITED(status)) {
        printf("Uscita $? = %d\n", WEXITSTATUS(status));
      } else if (WIFSIGNALED(status)) {
        printf("Signal: %d%s\n", WTERMSIG(status),
               WCOREDUMP(status) ? " with core  file." : "");
      } else {
        printf("Stopped\n");
      }
    }
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1250 <main+0x60>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xdbf(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xd,%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    128d <main+0x9d>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   10e0 <getppid@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <exec_ps_cmd@plt>
jmp    13b1 <main+0x1c1>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %rax,%rsi
movslq -0x14(%rbp),%rdx
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   10c0 <waitpid@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12fe <main+0x10e>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xd99(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bd <main+0x1cd>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1311 <main+0x121>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x1c(%rbp),%edi
call   10d0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1340 <main+0x150>
mov    -0x1c(%rbp),%edi
call   10b0 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13a7 <main+0x1b7>
mov    -0x1c(%rbp),%edi
call   1080 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1394 <main+0x1a4>
mov    -0x1c(%rbp),%edi
call   10a0 <WTERMSIG@plt>
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <WCOREDUMP@plt>
mov    -0x30(%rbp),%esi
mov    %rax,%rcx
lea    0xd1f(%rip),%rdx
lea    0xd37(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
lea    0xd1a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13a2 <main+0x1b2>
lea    0xd27(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13a7 <main+0x1b7>
jmp    13ac <main+0x1bc>
jmp    13b1 <main+0x1c1>
mov    0x2c18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
js     1338 <main+0x138>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %rax,%r14
test   %ebx,%ebx
je     127d <main+0x7d>
mov    %ebx,%edx
lea    0xe20(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x4(%rsp),%rsi
mov    $0xffffffff,%edi
xor    %edx,%edx
call   10d0 <waitpid@plt>
cmp    $0xffffffff,%eax
je     12aa <main+0xaa>
cmp    %ebx,%eax
jne    136a <main+0x16a>
mov    0x4(%rsp),%edi
call   10e0 <WIFEXITED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     12df <main+0xdf>
call   10c0 <WEXITSTATUS@plt>
lea    0xe20(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    129f <main+0x9f>
xor    %eax,%eax
call   10f0 <getppid@plt>
lea    0xd89(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1030 <exec_ps_cmd@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
jmp    12d7 <main+0xd7>
mov    0x2d2f(%rip),%rax
mov    (%rax),%ebx
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xdbe(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
call   1090 <WIFSIGNALED@plt>
test   %rax,%rax
je     1327 <main+0x127>
mov    0x4(%rsp),%edi
call   10b0 <WTERMSIG@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
call   1080 <WCOREDUMP@plt>
test   %rax,%rax
lea    0xd8a(%rip),%rax
lea    0xda2(%rip),%rdx
cmove  %rax,%rdx
lea    0xd89(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    129f <main+0x9f>
lea    0xd94(%rip),%rdi
call   1050 <puts@plt>
jmp    129f <main+0x9f>
mov    0x2ca1(%rip),%rax
mov    (%rax),%ebx
mov    0x2c90(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xcaa(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    $0xd,%edi
call   1100 <exit@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"%s: fork() fallita\0A\00"
@errno = global i32 0
@.str.1 = [56 x i8] c"PID %ld: Processo figlio parte - Il processo padre %ld\0A\00"
@.str.2 = [58 x i8] c"PID %ld: Processo figlio partito - Il processo padre %ld\0A\00"
@.str.3 = [12 x i8] c"%s: wait()\0A\00"
@.str.4 = [16 x i8] c"Uscita $? = %d\0A\00"
@.str.5 = [14 x i8] c"Signal: %d%s\0A\00"
@.str.6 = [18 x i8] c" with core file.\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [9 x i8] c"Stopped\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @fork()
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 13)
unreachable
18: ; preds = %2
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = call i64 (...) @getpid()
%23 = call i64 (...) @getppid()
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i64 %22, i64 %23)
%25 = call i32 (...) @exec_ps_cmd()
br label %71
26: ; preds = %18
%27 = call i64 (...) @getpid()
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i64 %27, i64 %29)
%31 = call i32 @waitpid(i32 -1, i32* %8, i32 0)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %39
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %37)
store i32 1, i32* %3
br label %73
39: ; preds = %26
%40 = load i32, i32* %7
%41 = load i32, i32* %6
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 (...) @abort()
unreachable
45: ; preds = %39
%46 = load i32, i32* %8
%47 = call i64 @WIFEXITED(i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load i32, i32* %8
%51 = call i32 @WEXITSTATUS(i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %51)
br label %69
53: ; preds = %45
%54 = load i32, i32* %8
%55 = call i64 @WIFSIGNALED(i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %66
57: ; preds = %53
%58 = load i32, i32* %8
%59 = call i32 @WTERMSIG(i32 %58)
%60 = load i32, i32* %8
%61 = call i64 @WCOREDUMP(i32 %60)
%62 = icmp ne i64 %61, 0
%63 = zext i1 %62 to i64
%64 = select i1 %62, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %59, i8* %64)
br label %68
66: ; preds = %53
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %68
68: ; preds = %66, %57
br label %69
69: ; preds = %68, %49
br label %70
70: ; preds = %69
br label %71
71: ; preds = %70, %21
%72 = load i32, i32* @EXIT_SUCCESS
store i32 %72, i32* %3
br label %73
73: ; preds = %71, %34
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"%s: fork() fallita\0A\00"
@errno = global i32 0
@.str.1 = [56 x i8] c"PID %ld: Processo figlio parte - Il processo padre %ld\0A\00"
@.str.2 = [58 x i8] c"PID %ld: Processo figlio partito - Il processo padre %ld\0A\00"
@.str.3 = [12 x i8] c"%s: wait()\0A\00"
@.str.4 = [16 x i8] c"Uscita $? = %d\0A\00"
@.str.5 = [14 x i8] c"Signal: %d%s\0A\00"
@.str.6 = [18 x i8] c" with core file.\00"
@.str.7 = [1 x i8] zeroinitializer
@EXIT_SUCCESS = global i32 0
@str = [8 x i8] c"Stopped\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (...) @fork()
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 13)
unreachable
13: ; preds = %2
%14 = icmp eq i32 %5, 0
%15 = tail call i64 (...) @getpid()
br i1 %14, label %16, label %20
16: ; preds = %13
%17 = tail call i64 (...) @getppid()
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i64 %15, i64 %17)
%19 = tail call i32 (...) @exec_ps_cmd()
br label %55
20: ; preds = %13
%21 = zext i32 %5 to i64
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i64 %15, i64 %21)
%23 = call i32 @waitpid(i32 -1, i32* %3, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %57
30: ; preds = %20
%31 = icmp eq i32 %23, %5
br i1 %31, label %34, label %32
32: ; preds = %30
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %30
%35 = load i32, i32* %3
%36 = call i64 @WIFEXITED(i32 %35)
%37 = icmp eq i64 %36, 0
%38 = load i32, i32* %3
br i1 %37, label %42, label %39
39: ; preds = %34
%40 = call i32 @WEXITSTATUS(i32 %38)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %40)
br label %55
42: ; preds = %34
%43 = call i64 @WIFSIGNALED(i32 %38)
%44 = icmp eq i64 %43, 0
br i1 %44, label %53, label %45
45: ; preds = %42
%46 = load i32, i32* %3
%47 = call i32 @WTERMSIG(i32 %46)
%48 = load i32, i32* %3
%49 = call i64 @WCOREDUMP(i32 %48)
%50 = icmp eq i64 %49, 0
%51 = select i1 %50, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %47, i8* %51)
br label %55
53: ; preds = %42
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %55
55: ; preds = %45, %53, %39, %16
%56 = load i32, i32* @EXIT_SUCCESS
br label %57
57: ; preds = %55, %25
%58 = phi i32 [ %56, %55 ], [ 1, %25 ]
ret i32 %58
}