#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int main() {
  float avg = 0, sum = 0, tmp = 0;
  int counter = 0;
  printf("Give a number or give -1 to exit : ");
  scanf("%f", &tmp);
  while (tmp != -1) {
    counter++;
    sum += tmp;
    printf("Give a number or give -1 to stop : ");
    scanf("%f", &tmp);
  }
  if (counter == 0) {
    printf("ERROR!!! We can't div with zero !!!\n");
  } else {
    avg = sum / counter;
    printf("The avg is %f\n", avg);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movss  -0x10(%rbp),%xmm0
movss  0xe87(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    118d <main+0x6d>
jp     118d <main+0x6d>
jmp    11c8 <main+0xa8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6e(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
jmp    116c <main+0x4c>
cmpl   $0x0,-0x14(%rbp)
jne    11e5 <main+0xc5>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120f <main+0xef>
movss  -0xc(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe6c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movl   $0x0,(%rsp)
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed5(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
movss  (%rsp),%xmm0
ucomiss 0xe99(%rip),%xmm0
jne    116b <main+0x3b>
jnp    11ea <main+0xba>
xorps  %xmm1,%xmm1
lea    0xeb6(%rip),%r14
lea    0xeac(%rip),%r15
mov    %rsp,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
add    $0x1,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movss  0x4(%rsp),%xmm1
movss  (%rsp),%xmm0
ucomiss 0xe3c(%rip),%xmm0
jne    1190 <main+0x60>
jp     1190 <main+0x60>
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe6e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    11f6 <main+0xc6>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Give a number or give -1 to exit : \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [36 x i8] c"Give a number or give -1 to stop : \00"
@.str.3 = [37 x i8] c"ERROR!!! We can't div with zero !!!\0A\00"
@.str.4 = [15 x i8] c"The avg is %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca i32
store i32 0, i32* %1
store float 0.000000e+00, float* %2
store float 0.000000e+00, float* %3
store float 0.000000e+00, float* %4
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %4)
br label %8
8: ; preds = %11, %0
%9 = load float, float* %4
%10 = fcmp une float %9, -1.000000e+00
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
store i32 %13, i32* %5
%14 = load float, float* %4
%15 = load float, float* %3
%16 = fadd float %15, %14
store float %16, float* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %4)
br label %8
19: ; preds = %8
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %32
24: ; preds = %19
%25 = load float, float* %3
%26 = load i32, i32* %5
%27 = sitofp i32 %26 to float
%28 = fdiv float %25, %27
store float %28, float* %2
%29 = load float, float* %2
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), double %30)
br label %32
32: ; preds = %24, %22
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Give a number or give -1 to exit : \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [36 x i8] c"Give a number or give -1 to stop : \00"
@.str.4 = [15 x i8] c"The avg is %f\0A\00"
@str = [36 x i8] c"ERROR!!! We can't div with zero !!!\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
store float 0.000000e+00, float* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%5 = load float, float* %1
%6 = fcmp une float %5, -1.000000e+00
br i1 %6, label %7, label %17
7: ; preds = %0, %7
%8 = phi float [ %15, %7 ], [ %5, %0 ]
%9 = phi i32 [ %11, %7 ], [ 0, %0 ]
%10 = phi float [ %12, %7 ], [ 0.000000e+00, %0 ]
%11 = add nuw nsw i32 %9, 1
%12 = fadd float %10, %8
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%15 = load float, float* %1
%16 = fcmp une float %15, -1.000000e+00
br i1 %16, label %7, label %19
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %24
19: ; preds = %7
%20 = sitofp i32 %11 to float
%21 = fdiv float %12, %20
%22 = fpext float %21 to double
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), double %22)
br label %24
24: ; preds = %19, %17
ret i32 0
}