#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(void) {
  int i = 0;
  int counter = 0;
  int sum = 0;
  printf("Input some numbers to calculate average .\n");
  scanf("%d", &i);
  while (i != 9999) {
    sum = sum + i;
    counter = counter + 1;
    scanf("%d", &i);
  }
  printf("Average is %f \n", (float)sum / counter);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x270f,-0x8(%rbp)
je     1196 <main+0x76>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xea3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1162 <main+0x42>
cvtsi2ssl -0x10(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe7f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movl   $0x0,0xc(%rsp)
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
lea    0xece(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x270f,%eax
jne    1171 <main+0x41>
movsd  0xe91(%rip),%xmm0
jmp    11d7 <main+0xa7>
pxor   %xmm2,%xmm2
lea    0xea4(%rip),%r14
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movd   %eax,%xmm0
movaps 0xe75(%rip),%xmm1
movss  %xmm0,%xmm1
paddd  %xmm1,%xmm2
movdqa %xmm2,0x10(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
movdqa 0x10(%rsp),%xmm2
mov    0xc(%rsp),%eax
cmp    $0x270f,%eax
jne    1190 <main+0x60>
cvtdq2ps %xmm2,%xmm0
movaps %xmm0,%xmm1
shufps $0x55,%xmm0,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe45(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Input some numbers to calculate average .\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Average is %f \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %7
7: ; preds = %10, %0
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 9999
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* %4
%12 = load i32, i32* %2
%13 = add nsw i32 %11, %12
store i32 %13, i32* %4
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %7
17: ; preds = %7
%18 = load i32, i32* %4
%19 = sitofp i32 %18 to float
%20 = load i32, i32* %3
%21 = sitofp i32 %20 to float
%22 = fdiv float %19, %21
%23 = fpext float %22 to double
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %23)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Average is %f \0A\00"
@str = [42 x i8] c"Input some numbers to calculate average .\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 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 = %15, %0
%22 = phi double [ %20, %15 ], [ 0x7FF8000000000000, %0 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %22)
ret i32 0
}