#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
scalar_t__ getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int n_arg1, n_arg2, n_tot_somma, n_tot_moltip;
  pid_t pid;
  if (argc < 3) {
    printf("Uso: %s <int1> <int2>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  n_arg1 = atoi(argv[1]);
  n_arg2 = atoi(argv[2]);
  pid = fork();
  if (pid == -1) {
    printf("Errore creando il processo\n");
    perror("fork");
    exit(EXIT_FAILURE);
  }
  if (pid == 0) {
    n_tot_moltip = n_arg1 * n_arg2;
    printf("Processo figlio %ld - %d * %d = %d\n", (long)getpid(), n_arg1,
           n_arg2, n_tot_moltip);
  } else {
    n_tot_somma = n_arg1 + n_arg2;
    printf("Processo padre %ld - %d + %d = %d\n", (long)getpid(), n_arg1,
           n_arg2, n_tot_somma);
  }
  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)
cmpl   $0x3,-0x8(%rbp)
jge    11a3 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11ff <main+0x9f>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe47(%rip),%rdi
call   1050 <perror@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x24(%rbp)
jne    123a <main+0xda>
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1265 <main+0x105>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
cmp    $0x2,%edi
jle    11ec <main+0x7c>
mov    0x8(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11b8 <main+0x48>
cmp    $0xffffffff,%eax
je     1200 <main+0x90>
mov    %ebx,%ebp
add    %r14d,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe8a(%rip),%rdi
jmp    11cc <main+0x5c>
mov    %ebx,%ebp
imul   %r14d,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe50(%rip),%rdi
mov    %rax,%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x0(%rbp),%rsi
lea    0xe09(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1218 <main+0xa8>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe04(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Uso: %s <int1> <int2>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c"Errore creando il processo\0A\00"
@.str.2 = [5 x i8] c"fork\00"
@.str.3 = [36 x i8] c"Processo figlio %ld - %d * %d = %d\0A\00"
@.str.4 = [35 x i8] c"Processo padre %ld - %d + %d = %d\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
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %7
%29 = call i32 (...) @fork()
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %37
32: ; preds = %20
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %20
%38 = load i32, i32* %10
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = load i32, i32* %6
%42 = load i32, i32* %7
%43 = mul nsw i32 %41, %42
store i32 %43, i32* %9
%44 = call i64 (...) @getpid()
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = load i32, i32* %9
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i64 %44, i32 %45, i32 %46, i32 %47)
br label %58
49: ; preds = %37
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = add nsw i32 %50, %51
store i32 %52, i32* %8
%53 = call i64 (...) @getpid()
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = load i32, i32* %8
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i64 %53, i32 %54, i32 %55, i32 %56)
br label %58
58: ; preds = %49, %40
%59 = load i32, i32* @EXIT_SUCCESS
ret i32 %59
}

LLVM IR (-O2):
@.str = [23 x i8] c"Uso: %s <int1> <int2>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"fork\00"
@.str.3 = [36 x i8] c"Processo figlio %ld - %d * %d = %d\0A\00"
@.str.4 = [35 x i8] c"Processo padre %ld - %d + %d = %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [27 x i8] c"Errore creando il processo\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = tail call i32 (...) @fork()
switch i32 %16, label %26 [
i32 -1, label %17
i32 0, label %22
]
17: ; preds = %9
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %9
%23 = mul nsw i32 %15, %12
%24 = tail call i64 (...) @getpid()
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i64 %24, i32 %12, i32 %15, i32 %23)
br label %30
26: ; preds = %9
%27 = add nsw i32 %15, %12
%28 = tail call i64 (...) @getpid()
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i64 %28, i32 %12, i32 %15, i32 %27)
br label %30
30: ; preds = %26, %22
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}