#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*/ calcolaTotali(float **, unsigned int, unsigned int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ registraDistinta(float **, unsigned int, unsigned int,
                                    float);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stampaTotali(float **, unsigned int, unsigned int);
int main() {
  unsigned int numeroAgente;
  unsigned int numeroProdotto;
  float quantitaVenduta;
  float sales[5 + 1][4 + 1] = {{0}, {0}};
  unsigned int stampareRisultati = 0;
  unsigned int valoreSentinella = 0;
  do {
    printf("%s", "Prego inserire l'ID dell'agente intestatario della "
                 "distinta(0 per uscire): ");
    scanf("%u", &numeroAgente);
    if (numeroAgente != valoreSentinella) {
      if (numeroAgente <= 4) {
        printf("%s", "Prego inserire l'ID del prodotto relativo alla "
                     "distinta(0 per uscire): ");
        scanf("%u", &numeroProdotto);
        if (numeroProdotto != valoreSentinella) {
          if (numeroProdotto <= 5) {
            printf("%s", "Prego inserire l'importo delle vendite: $");
            scanf("%f", &quantitaVenduta);
            if (quantitaVenduta >= 0) {
              registraDistinta(sales, (numeroAgente - 1), (numeroProdotto - 1),
                               quantitaVenduta);
              stampareRisultati = 1;
            } else {
              puts("Importo della vendita errato, ripetere inserimento "
                   "distinta");
            }
          } else {
            puts("Attenzione, e' stato inserito un valore non valido");
          }
        }
      } else {
        puts("Attenzione, e' stato inserito un valore non valido");
      }
    }
  } while (numeroAgente != valoreSentinella &&
           numeroProdotto != valoreSentinella);
  if (stampareRisultati == 1) {
    calcolaTotali(sales, (unsigned int)4, (unsigned int)5);
    stampaTotali(sales, (unsigned int)4, (unsigned int)5);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x78,%edx
call   1050 <memset@plt>
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
lea    0xe50(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x8(%rbp),%eax
cmp    -0x98(%rbp),%eax
je     12bf <main+0x14f>
cmpl   $0x4,-0x8(%rbp)
ja     12ae <main+0x13e>
lea    0xe12(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <printf@plt>
lea    0xe4e(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x98(%rbp),%eax
je     12a9 <main+0x139>
cmpl   $0x5,-0xc(%rbp)
ja     1298 <main+0x128>
lea    0xdd4(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1040 <printf@plt>
lea    0xe85(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movss  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1287 <main+0x117>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
movss  -0x10(%rbp),%xmm0
call   1090 <registraDistinta@plt>
movl   $0x1,-0x94(%rbp)
jmp    1293 <main+0x123>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
jmp    12a4 <main+0x134>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
jmp    12a9 <main+0x139>
jmp    12ba <main+0x14a>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
jmp    12bf <main+0x14f>
jmp    12c4 <main+0x154>
mov    -0x8(%rbp),%ecx
xor    %eax,%eax
cmp    -0x98(%rbp),%ecx
mov    %al,-0x99(%rbp)
je     12ed <main+0x17d>
mov    -0xc(%rbp),%eax
cmp    -0x98(%rbp),%eax
setne  %al
mov    %al,-0x99(%rbp)
mov    -0x99(%rbp),%al
test   $0x1,%al
jne    11a9 <main+0x39>
cmpl   $0x1,-0x94(%rbp)
jne    1334 <main+0x1c4>
lea    -0x90(%rbp),%rdi
mov    $0x4,%esi
mov    $0x5,%edx
call   1060 <calcolaTotali@plt>
lea    -0x90(%rbp),%rdi
mov    $0x4,%esi
mov    $0x5,%edx
call   1070 <stampaTotali@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x80(%rsp)
lea    0xe5a(%rip),%rbx
lea    0xe56(%rip),%r14
lea    0xe9b(%rip),%r15
lea    0x4(%rsp),%r12
lea    0xf43(%rip),%r13
mov    %rsp,%rbp
movl   $0x0,0x8(%rsp)
nop
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     1265 <main+0x105>
mov    %r13,%rdi
cmp    $0x4,%eax
ja     1260 <main+0x100>
mov    %rbx,%rdi
lea    0xe54(%rip),%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    (%rsp),%eax
test   %eax,%eax
je     1265 <main+0x105>
mov    %r13,%rdi
cmp    $0x5,%eax
ja     1260 <main+0x100>
mov    %rbx,%rdi
lea    0xe71(%rip),%rsi
call   1040 <printf@plt>
lea    0xe8f(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movss  0xc(%rsp),%xmm0
ucomiss 0xdae(%rip),%xmm0
lea    0xe72(%rip),%rdi
jae    1278 <main+0x118>
nopl   0x0(%rax,%rax,1)
call   1030 <puts@plt>
cmpl   $0x0,0x4(%rsp)
je     12a8 <main+0x148>
cmpl   $0x0,(%rsp)
jne    11d0 <main+0x70>
jmp    12a8 <main+0x148>
mov    0x4(%rsp),%esi
add    $0xffffffff,%esi
mov    (%rsp),%edx
add    $0xffffffff,%edx
lea    0x10(%rsp),%rdi
call   1080 <registraDistinta@plt>
cmpl   $0x0,0x4(%rsp)
je     12af <main+0x14f>
mov    $0x1,%al
mov    %eax,0x8(%rsp)
cmpl   $0x0,(%rsp)
jne    11d0 <main+0x70>
jmp    12af <main+0x14f>
testb  $0x1,0x8(%rsp)
je     12d8 <main+0x178>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x5,%edx
call   1050 <calcolaTotali@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x5,%edx
call   1060 <stampaTotali@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [76 x i8] c"Prego inserire l'ID dell'agente intestatario della distinta(0 per uscire): \00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [72 x i8] c"Prego inserire l'ID del prodotto relativo alla distinta(0 per uscire): \00"
@.str.4 = [42 x i8] c"Prego inserire l'importo delle vendite: $\00"
@.str.5 = [3 x i8] c"%f\00"
@.str.6 = [60 x i8] c"Importo della vendita errato, ripetere inserimento distinta\00"
@.str.7 = [51 x i8] c"Attenzione, e' stato inserito un valore non valido\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca [6 x [5 x float]]
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [6 x [5 x float]]* %5 to i8*
store i32 0, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %60, %0
%10 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
%13 = load i32, i32* %7
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %51
15: ; preds = %9
%16 = load i32, i32* %2
%17 = icmp ule i32 %16, 4
br i1 %17, label %18, label %48
18: ; preds = %15
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%21 = load i32, i32* %3
%22 = load i32, i32* %7
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %47
24: ; preds = %18
%25 = load i32, i32* %3
%26 = icmp ule i32 %25, 5
br i1 %26, label %27, label %44
27: ; preds = %24
%28 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), float* %4)
%30 = load float, float* %4
%31 = fcmp oge float %30, 0.000000e+00
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = getelementptr inbounds [6 x [5 x float]], [6 x [5 x float]]* %5, i64 0, i64 0
%34 = bitcast [5 x float]* %33 to float**
%35 = load i32, i32* %2
%36 = sub i32 %35, 1
%37 = load i32, i32* %3
%38 = sub i32 %37, 1
%39 = load float, float* %4
%40 = call i32 @registraDistinta(float** %34, i32 %36, i32 %38, float %39)
store i32 1, i32* %6
br label %43
41: ; preds = %27
%42 = call i32 @puts(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.6, i64 0, i64 0))
br label %43
43: ; preds = %41, %32
br label %46
44: ; preds = %24
%45 = call i32 @puts(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0))
br label %46
46: ; preds = %44, %43
br label %47
47: ; preds = %46, %18
br label %50
48: ; preds = %15
%49 = call i32 @puts(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0))
br label %50
50: ; preds = %48, %47
br label %51
51: ; preds = %50, %9
br label %52
52: ; preds = %51
%53 = load i32, i32* %2
%54 = load i32, i32* %7
%55 = icmp ne i32 %53, %54
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = load i32, i32* %3
%58 = load i32, i32* %7
%59 = icmp ne i32 %57, %58
br label %60
60: ; preds = %56, %52
%61 = phi i1 [ false, %52 ], [ %59, %56 ]
br i1 %61, label %9, label %62
62: ; preds = %60
%63 = load i32, i32* %6
%64 = icmp eq i32 %63, 1
br i1 %64, label %65, label %72
65: ; preds = %62
%66 = getelementptr inbounds [6 x [5 x float]], [6 x [5 x float]]* %5, i64 0, i64 0
%67 = bitcast [5 x float]* %66 to float**
%68 = call i32 @calcolaTotali(float** %67, i32 4, i32 5)
%69 = getelementptr inbounds [6 x [5 x float]], [6 x [5 x float]]* %5, i64 0, i64 0
%70 = bitcast [5 x float]* %69 to float**
%71 = call i32 @stampaTotali(float** %70, i32 4, i32 5)
br label %72
72: ; preds = %65, %62
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [76 x i8] c"Prego inserire l'ID dell'agente intestatario della distinta(0 per uscire): \00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [72 x i8] c"Prego inserire l'ID del prodotto relativo alla distinta(0 per uscire): \00"
@.str.4 = [42 x i8] c"Prego inserire l'importo delle vendite: $\00"
@.str.5 = [3 x i8] c"%f\00"
@.str.6 = [60 x i8] c"Importo della vendita errato, ripetere inserimento distinta\00"
@.str.7 = [51 x i8] c"Attenzione, e' stato inserito un valore non valido\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca [6 x [5 x float]]
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast float* %3 to i8*
%8 = bitcast [6 x [5 x float]]* %4 to i8*
%9 = bitcast [6 x [5 x float]]* %4 to float**
br label %10
10: ; preds = %40, %0
%11 = phi i1 [ true, %40 ], [ false, %0 ]
br label %12
12: ; preds = %10, %34
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%15 = load i32, i32* %1
%16 = icmp eq i32 %15, 0
br i1 %16, label %34, label %17
17: ; preds = %12
%18 = icmp ult i32 %15, 5
br i1 %18, label %19, label %31
19: ; preds = %17
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%22 = load i32, i32* %2
%23 = icmp eq i32 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %19
%25 = icmp ult i32 %22, 6
br i1 %25, label %26, label %31
26: ; preds = %24
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), float* %3)
%29 = load float, float* %3
%30 = fcmp ult float %29, 0.000000e+00
br i1 %30, label %31, label %40
31: ; preds = %17, %24, %26
%32 = phi i8* [ getelementptr inbounds ([60 x i8], [60 x i8]* @.str.6, i64 0, i64 0), %26 ], [ getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0), %24 ], [ getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0), %17 ]
%33 = call i32 @puts(i8* dereferenceable(1) %32)
br label %34
34: ; preds = %31, %12, %19
%35 = load i32, i32* %1
%36 = icmp ne i32 %35, 0
%37 = load i32, i32* %2
%38 = icmp ne i32 %37, 0
%39 = select i1 %36, i1 %38, i1 false
br i1 %39, label %12, label %51
40: ; preds = %26
%41 = load i32, i32* %1
%42 = add i32 %41, -1
%43 = load i32, i32* %2
%44 = add i32 %43, -1
%45 = call i32 @registraDistinta(float** %9, i32 %42, i32 %44, float %29)
%46 = load i32, i32* %1
%47 = icmp ne i32 %46, 0
%48 = load i32, i32* %2
%49 = icmp ne i32 %48, 0
%50 = select i1 %47, i1 %49, i1 false
br i1 %50, label %10, label %52
51: ; preds = %34
br i1 %11, label %52, label %55
52: ; preds = %40, %51
%53 = call i32 @calcolaTotali(float** %9, i32 4, i32 5)
%54 = call i32 @stampaTotali(float** %9, i32 4, i32 5)
br label %55
55: ; preds = %52, %51
ret i32 0
}