#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_FAILURE;
int countDigits(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getValue();
int getpid();
char *malloc(int);
int /*<<< orphan*/ printf(char *);
char **realloc(char **, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int getReceivers(char ***receivers) {
  int count = 0, pid;
  do {
    printf("Inserisci PID del processo destinatario (0 per annullare, INVIO "
           "per terminare): ");
    pid = getValue();
    if (pid == getpid())
      printf("Non puoi inserire il tuo stesso pid.\nRiprovare: ");
    else if (pid != -1 && pid != 0) {
      count++;
      *receivers = realloc(*receivers, sizeof(char *) * count);
      if (*receivers == NULL)
        exit(EXIT_FAILURE);
      int digits = countDigits(pid) + 1;
      *(*receivers + count - 1) = malloc(sizeof(char) * digits);
      if (*(*receivers + count - 1) == NULL)
        exit(EXIT_FAILURE);
      sprintf(*(*receivers + count - 1), "%d", pid);
    } else if (pid == -1) {
      count = 0;
    }
  } while (pid != -1 && pid != 0);
  return count;
}


x86 assembly (clang, -O0):
<getReceivers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getValue@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jne    11d4 <getReceivers+0x54>
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
jmp    12c1 <getReceivers+0x141>
cmpl   $0xffffffff,-0x10(%rbp)
je     12a6 <getReceivers+0x126>
cmpl   $0x0,-0x10(%rbp)
je     12a6 <getReceivers+0x126>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    122d <getReceivers+0xad>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%edi
call   1060 <countDigits@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,-0x8(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,-0x8(%rax,%rcx,8)
jne    1282 <getReceivers+0x102>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0xc(%rbp),%rcx
mov    -0x8(%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%edx
lea    0xde6(%rip),%rsi
call   1090 <sprintf@plt>
jmp    12bc <getReceivers+0x13c>
cmpl   $0xffffffff,-0x10(%rbp)
jne    12b7 <getReceivers+0x137>
movl   $0x0,-0xc(%rbp)
jmp    12bc <getReceivers+0x13c>
jmp    12c1 <getReceivers+0x141>
jmp    12c6 <getReceivers+0x146>
xor    %eax,%eax
cmpl   $0xffffffff,-0x10(%rbp)
mov    %al,-0x19(%rbp)
je     12df <getReceivers+0x15f>
cmpl   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1193 <getReceivers+0x13>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getReceivers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe6b(%rip),%r15
xor    %ebx,%ebx
jmp    11bc <getReceivers+0x3c>
nopl   0x0(%rax)
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
add    $0xffffffff,%ebp
mov    %ebp,%r13d
cmp    $0xfffffffe,%r13d
jae    1241 <getReceivers+0xc1>
mov    %r15,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getValue@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
cmp    %eax,%ebp
je     11a0 <getReceivers+0x20>
lea    -0x1(%rbp),%r13d
cmp    $0xfffffffd,%r13d
ja     1239 <getReceivers+0xb9>
mov    (%r14),%rdi
lea    0x8(,%rbx,8),%esi
call   1080 <realloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1252 <getReceivers+0xd2>
add    $0x1,%ebx
movslq %ebx,%r12
mov    %ebp,%edi
call   1060 <countDigits@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    (%r14),%rcx
mov    %rax,-0x8(%rcx,%r12,8)
mov    (%r14),%rax
mov    -0x8(%rax,%r12,8),%rdi
test   %rdi,%rdi
je     1252 <getReceivers+0xd2>
lea    0xe58(%rip),%rsi
mov    %ebp,%edx
call   1090 <sprintf@plt>
cmp    $0xfffffffe,%r13d
jb     11bc <getReceivers+0x3c>
jmp    1241 <getReceivers+0xc1>
xor    %eax,%eax
cmp    $0xffffffff,%ebp
cmove  %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [81 x i8] c"Inserisci PID del processo destinatario (0 per annullare, INVIO per terminare): \00"
@.str.1 = [49 x i8] c"Non puoi inserire il tuo stesso pid.\0ARiprovare: \00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define i32 @getReceivers(i8*** %0) {
%2 = alloca i8***
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8*** %0, i8**** %2
store i32 0, i32* %3
br label %6
6: ; preds = %86, %1
%7 = call i32 @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @getValue()
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = call i32 (...) @getpid()
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %79
14: ; preds = %6
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %73
17: ; preds = %14
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %73
20: ; preds = %17
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%23 = load i8***, i8**** %2
%24 = load i8**, i8*** %23
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = mul i64 8, %26
%28 = trunc i64 %27 to i32
%29 = call i8** @realloc(i8** %24, i32 %28)
%30 = load i8***, i8**** %2
store i8** %29, i8*** %30
%31 = load i8***, i8**** %2
%32 = load i8**, i8*** %31
%33 = icmp eq i8** %32, null
br i1 %33, label %34, label %37
34: ; preds = %20
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %20
%38 = load i32, i32* %4
%39 = call i32 @countDigits(i32 %38)
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = mul i64 1, %42
%44 = trunc i64 %43 to i32
%45 = call i8* @malloc(i32 %44)
%46 = load i8***, i8**** %2
%47 = load i8**, i8*** %46
%48 = load i32, i32* %3
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = getelementptr inbounds i8*, i8** %50, i64 -1
store i8* %45, i8** %51
%52 = load i8***, i8**** %2
%53 = load i8**, i8*** %52
%54 = load i32, i32* %3
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = getelementptr inbounds i8*, i8** %56, i64 -1
%58 = load i8*, i8** %57
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %63
60: ; preds = %37
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %37
%64 = load i8***, i8**** %2
%65 = load i8**, i8*** %64
%66 = load i32, i32* %3
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
%69 = getelementptr inbounds i8*, i8** %68, i64 -1
%70 = load i8*, i8** %69
%71 = load i32, i32* %4
%72 = call i32 @sprintf(i8* %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %71)
br label %78
73: ; preds = %17, %14
%74 = load i32, i32* %4
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %77
76: ; preds = %73
store i32 0, i32* %3
br label %77
77: ; preds = %76, %73
br label %78
78: ; preds = %77, %63
br label %79
79: ; preds = %78, %12
br label %80
80: ; preds = %79
%81 = load i32, i32* %4
%82 = icmp ne i32 %81, -1
br i1 %82, label %83, label %86
83: ; preds = %80
%84 = load i32, i32* %4
%85 = icmp ne i32 %84, 0
br label %86
86: ; preds = %83, %80
%87 = phi i1 [ false, %80 ], [ %85, %83 ]
br i1 %87, label %6, label %88
88: ; preds = %86
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [81 x i8] c"Inserisci PID del processo destinatario (0 per annullare, INVIO per terminare): \00"
@.str.1 = [49 x i8] c"Non puoi inserire il tuo stesso pid.\0ARiprovare: \00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define i32 @getReceivers(i8*** nocapture %0) {
br label %2
2: ; preds = %44, %1
%3 = phi i32 [ 0, %1 ], [ %46, %44 ]
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (...) @getValue()
%6 = tail call i32 (...) @getpid()
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%10 = add i32 %5, -1
br label %44
11: ; preds = %2
%12 = add i32 %5, -1
%13 = icmp ult i32 %12, -2
br i1 %13, label %14, label %41
14: ; preds = %11
%15 = add nsw i32 %3, 1
%16 = load i8**, i8*** %0
%17 = sext i32 %15 to i64
%18 = shl i32 %15, 3
%19 = tail call i8** @realloc(i8** %16, i32 %18)
store i8** %19, i8*** %0
%20 = icmp eq i8** %19, null
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %14
%25 = tail call i32 @countDigits(i32 %5)
%26 = add nsw i32 %25, 1
%27 = tail call i8* @malloc(i32 %26)
%28 = load i8**, i8*** %0
%29 = getelementptr inbounds i8*, i8** %28, i64 -1
%30 = getelementptr inbounds i8*, i8** %29, i64 %17
store i8* %27, i8** %30
%31 = load i8**, i8*** %0
%32 = getelementptr inbounds i8*, i8** %31, i64 -1
%33 = getelementptr inbounds i8*, i8** %32, i64 %17
%34 = load i8*, i8** %33
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %39
36: ; preds = %24
%37 = load i32, i32* @EXIT_FAILURE
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %24
%40 = tail call i32 @sprintf(i8* %34, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %5)
br label %44
41: ; preds = %11
%42 = icmp eq i32 %5, -1
%43 = select i1 %42, i32 0, i32 %3
br label %48
44: ; preds = %8, %39
%45 = phi i32 [ %10, %8 ], [ %12, %39 ]
%46 = phi i32 [ %3, %8 ], [ %15, %39 ]
%47 = icmp ult i32 %45, -2
br i1 %47, label %2, label %48
48: ; preds = %44, %41
%49 = phi i32 [ %43, %41 ], [ %46, %44 ]
ret i32 %49
}