#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(int);
int /*<<< orphan*/ getc(int /*<<< orphan*/);
int mediaMobile(int *, int, int, float *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int main() {
  int i, k = 0;
  int V[30] = {0};
  float M[30] = {.0};
  int v, m;
  printf("Vettore di partenza (max %d valori). 'x' per terminare:\n", 30);
  for (i = 0; i < 30; i++) {
    printf("> ");
    if (!scanf("%d", &V[i])) {
      break;
    }
  }
  v = i;
  getc(stdin);
  printf("Inserire il valore di K (minore o uguale a %d):\n> ", v);
  if (!scanf("%d", &k) || k > v)
    exit(1);
  m = mediaMobile(V, v, k, M);
  puts("Vettore media mobile:");
  for (i = 0; i < m; i++) {
    printf("%.3f\n", M[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x78,%edx
call   1050 <memset@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x78,%edx
call   1050 <memset@plt>
lea    0xe4a(%rip),%rdi
mov    $0x1e,%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x1e,-0x8(%rbp)
jge    1220 <main+0xb0>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x8(%rbp),%rax
lea    -0x90(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe3f(%rip),%rdi
call   1070 <scanf@plt>
cmp    $0x0,%eax
jne    120d <main+0x9d>
jmp    1220 <main+0xb0>
jmp    1212 <main+0xa2>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c9 <main+0x59>
mov    -0x8(%rbp),%eax
mov    %eax,-0x114(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1090 <getc@plt>
mov    -0x114(%rbp),%esi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde7(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
cmp    $0x0,%eax
je     1273 <main+0x103>
mov    -0xc(%rbp),%eax
cmp    -0x114(%rbp),%eax
jle    127d <main+0x10d>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x90(%rbp),%rdi
mov    -0x114(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    -0x110(%rbp),%rcx
call   1060 <mediaMobile@plt>
mov    %eax,-0x118(%rbp)
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x118(%rbp),%eax
jge    12ee <main+0x17e>
movslq -0x8(%rbp),%rax
movss  -0x110(%rbp,%rax,4),%xmm0
ff ff
cvtss2sd %xmm0,%xmm0
lea    0xdac(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12b2 <main+0x142>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
movl   $0x0,0xc(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movq   $0x0,0x100(%rsp)
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    0xe0d(%rip),%rdi
mov    $0x1e,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x90(%rsp),%rbx
lea    0xe5e(%rip),%r15
lea    0xe24(%rip),%r12
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
test   %eax,%eax
je     124d <main+0xed>
add    $0x1,%r14
add    $0x4,%rbx
cmp    $0x1e,%r14
jne    1220 <main+0xc0>
mov    $0x1e,%r14d
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1080 <getc@plt>
lea    0xdda(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdc6(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
test   %eax,%eax
je     12ee <main+0x18e>
mov    0xc(%rsp),%edx
cmp    %r14d,%edx
jg     12ee <main+0x18e>
lea    0x90(%rsp),%rdi
lea    0x10(%rsp),%rcx
mov    %r14d,%esi
call   1050 <mediaMobile@plt>
mov    %eax,%ebx
lea    0xdc7(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
jle    12dd <main+0x17d>
mov    %ebx,%r15d
xor    %ebx,%ebx
lea    0xdc8(%rip),%r14
nopl   (%rax)
movss  0x10(%rsp,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    12c0 <main+0x160>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [57 x i8] c"Vettore di partenza (max %d valori). 'x' per terminare:\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.3 = [51 x i8] c"Inserire il valore di K (minore o uguale a %d):\0A> \00"
@.str.4 = [22 x i8] c"Vettore media mobile:\00"
@.str.5 = [6 x i8] c"%.3f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [30 x i32]
%5 = alloca [30 x float]
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%8 = bitcast [30 x i32]* %4 to i8*
%9 = bitcast [30 x float]* %5 to i8*
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 30)
store i32 0, i32* %2
br label %11
11: ; preds = %23, %0
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 30
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [30 x i32], [30 x i32]* %4, i64 0, i64 %17
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %14
br label %26
22: ; preds = %14
br label %23
23: ; preds = %22
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %11
26: ; preds = %21, %11
%27 = load i32, i32* %2
store i32 %27, i32* %6
%28 = load i32, i32* @stdin
%29 = call i32 @getc(i32 %28)
%30 = load i32, i32* %6
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %26
%35 = load i32, i32* %3
%36 = load i32, i32* %6
%37 = icmp sgt i32 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %34, %26
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %34
%41 = getelementptr inbounds [30 x i32], [30 x i32]* %4, i64 0, i64 0
%42 = load i32, i32* %6
%43 = load i32, i32* %3
%44 = getelementptr inbounds [30 x float], [30 x float]* %5, i64 0, i64 0
%45 = call i32 @mediaMobile(i32* %41, i32 %42, i32 %43, float* %44)
store i32 %45, i32* %7
%46 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %47
47: ; preds = %58, %40
%48 = load i32, i32* %2
%49 = load i32, i32* %7
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %61
51: ; preds = %47
%52 = load i32, i32* %2
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [30 x float], [30 x float]* %5, i64 0, i64 %53
%55 = load float, float* %54
%56 = fpext float %55 to double
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), double %56)
br label %58
58: ; preds = %51
%59 = load i32, i32* %2
%60 = add nsw i32 %59, 1
store i32 %60, i32* %2
br label %47
61: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
@.str = [57 x i8] c"Vettore di partenza (max %d valori). 'x' per terminare:\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.3 = [51 x i8] c"Inserire il valore di K (minore o uguale a %d):\0A> \00"
@.str.4 = [22 x i8] c"Vettore media mobile:\00"
@.str.5 = [6 x i8] c"%.3f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i32]
%3 = alloca [30 x float]
%4 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%5 = bitcast [30 x i32]* %2 to i8*
%6 = bitcast [30 x float]* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 30)
br label %8
8: ; preds = %0, %14
%9 = phi i64 [ 0, %0 ], [ %15, %14 ]
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [30 x i32], [30 x i32]* %2, i64 0, i64 %9
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, 30
br i1 %16, label %19, label %8
17: ; preds = %8
%18 = trunc i64 %9 to i32
br label %19
19: ; preds = %14, %17
%20 = phi i32 [ %18, %17 ], [ 30, %14 ]
%21 = load i32, i32* @stdin
%22 = call i32 @getc(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %19
%27 = load i32, i32* %1
%28 = icmp sgt i32 %27, %20
br i1 %28, label %29, label %31
29: ; preds = %26, %19
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %26
%32 = getelementptr inbounds [30 x i32], [30 x i32]* %2, i64 0, i64 0
%33 = getelementptr inbounds [30 x float], [30 x float]* %3, i64 0, i64 0
%34 = call i32 @mediaMobile(i32* %32, i32 %20, i32 %27, float* %33)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp sgt i32 %34, 0
br i1 %36, label %37, label %47
37: ; preds = %31
%38 = zext i32 %34 to i64
br label %39
39: ; preds = %37, %39
%40 = phi i64 [ 0, %37 ], [ %45, %39 ]
%41 = getelementptr inbounds [30 x float], [30 x float]* %3, i64 0, i64 %40
%42 = load float, float* %41
%43 = fpext float %42 to double
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), double %43)
%45 = add nuw nsw i64 %40, 1
%46 = icmp eq i64 %45, %38
br i1 %46, label %47, label %39
47: ; preds = %39, %31
ret i32 0
}