#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 num, contador = 0, acumulador = 0;
  float media = 0;
  while (num != 9999) {
    printf("Digite um numero (9999 para sair): ");
    scanf("%d", &num);
    if (num == 9999) {
      break;
    }
    acumulador += num;
    contador++;
  }
  media = (acumulador / (contador * 1.0));
  printf("a media e %.3f\n", media);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
cmpl   $0x270f,-0x8(%rbp)
je     1199 <main+0x79>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x270f,-0x8(%rbp)
jne    1182 <main+0x62>
jmp    1199 <main+0x79>
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1145 <main+0x25>
cvtsi2sdl -0x10(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xe55(%rip),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe63(%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   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xed5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeeb(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x270f,%eax
jne    1160 <main+0x40>
movsd  0xea2(%rip),%xmm0
jmp    11b9 <main+0x99>
lea    0xea1(%rip),%r14
lea    0xebe(%rip),%r15
lea    0xc(%rsp),%r12
xor    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
add    %eax,%ebx
add    $0x1,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x270f,%eax
jne    1180 <main+0x60>
cvtsi2sd %ebx,%xmm0
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe6f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Digite um numero (9999 para sair): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"a media e %.3f\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* %3
store i32 0, i32* %4
store float 0.000000e+00, float* %5
br label %6
6: ; preds = %15, %0
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 9999
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 9999
br i1 %13, label %14, label %15
14: ; preds = %9
br label %21
15: ; preds = %9
%16 = load i32, i32* %2
%17 = load i32, i32* %4
%18 = add nsw i32 %17, %16
store i32 %18, i32* %4
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %6
21: ; preds = %14, %6
%22 = load i32, i32* %4
%23 = sitofp i32 %22 to double
%24 = load i32, i32* %3
%25 = sitofp i32 %24 to double
%26 = fmul double %25, 1.000000e+00
%27 = fdiv double %23, %26
%28 = fptrunc double %27 to float
store float %28, float* %5
%29 = load float, float* %5
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Digite um numero (9999 para sair): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"a media e %.3f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = 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), i32* %1)
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 9999
br i1 %6, label %23, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %15, %7 ], [ %5, %0 ]
%9 = phi i32 [ %12, %7 ], [ 0, %0 ]
%10 = phi i32 [ %11, %7 ], [ 0, %0 ]
%11 = add nsw i32 %8, %10
%12 = add nuw nsw i32 %9, 1
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%15 = load i32, i32* %1
%16 = icmp eq i32 %15, 9999
br i1 %16, label %17, label %7
17: ; preds = %7
%18 = sitofp i32 %11 to double
%19 = sitofp i32 %12 to double
%20 = fdiv double %18, %19
%21 = fptrunc double %20 to float
%22 = fpext float %21 to double
br label %23
23: ; preds = %17, %0
%24 = phi double [ %22, %17 ], [ 0x7FF8000000000000, %0 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %24)
ret i32 0
}