#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 *, int *);
int main() {
  int count = 0, num;
  int sum = 0;
  float average = 0;
  printf("Enter each number on a seperate line (enter 9999 to exit): ");
  scanf("%d", &num);
  while (num != 9999) {
    sum += num;
    count++;
    scanf("%d", &num);
  }
  if (count)
    average = (float)sum / count;
  printf("\nThe average of the entered numbers is %f\n", average);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x270f,-0xc(%rbp)
je     1197 <main+0x77>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1163 <main+0x43>
cmpl   $0x0,-0x8(%rbp)
je     11b4 <main+0x94>
cvtsi2ssl -0x10(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe7b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xee2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf10(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
xorps  %xmm0,%xmm0
cmp    $0x270f,%eax
je     11b7 <main+0x97>
pxor   %xmm2,%xmm2
lea    0xeed(%rip),%r14
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movd   %eax,%xmm0
movaps 0xe85(%rip),%xmm1
movss  %xmm0,%xmm1
paddd  %xmm1,%xmm2
movdqa %xmm2,0x10(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
movdqa 0x10(%rsp),%xmm2
mov    0xc(%rsp),%eax
cmp    $0x270f,%eax
jne    1170 <main+0x50>
cvtdq2ps %xmm2,%xmm0
movaps %xmm0,%xmm1
shufps $0x55,%xmm0,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe91(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [60 x i8] c"Enter each number on a seperate line (enter 9999 to exit): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [43 x i8] c"\0AThe average of the entered numbers is %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %4
store float 0.000000e+00, float* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 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), i32* %3)
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 9999
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = add nsw i32 %13, %12
store i32 %14, i32* %4
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %8
18: ; preds = %8
%19 = load i32, i32* %2
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* %4
%23 = sitofp i32 %22 to float
%24 = load i32, i32* %2
%25 = sitofp i32 %24 to float
%26 = fdiv float %23, %25
store float %26, float* %5
br label %27
27: ; preds = %21, %18
%28 = load float, float* %5
%29 = fpext float %28 to double
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), double %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [60 x i8] c"Enter each number on a seperate line (enter 9999 to exit): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [43 x i8] c"\0AThe average of the entered numbers is %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 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), i32* %1)
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 9999
br i1 %6, label %21, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %13, %7 ], [ %5, %0 ]
%9 = phi <2 x i32> [ %11, %7 ], [ zeroinitializer, %0 ]
%10 = insertelement <2 x i32> <i32 poison, i32 1>, i32 %8, i64 0
%11 = add nsw <2 x i32> %9, %10
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %1
%14 = icmp eq i32 %13, 9999
br i1 %14, label %15, label %7
15: ; preds = %7
%16 = sitofp <2 x i32> %11 to <2 x float>
%17 = extractelement <2 x float> %16, i64 0
%18 = extractelement <2 x float> %16, i64 1
%19 = fdiv float %17, %18
%20 = fpext float %19 to double
br label %21
21: ; preds = %0, %15
%22 = phi double [ %20, %15 ], [ 0.000000e+00, %0 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), double %22)
ret i32 0
}