#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 *);
float calc_mean() {
  float i, num, sum, mean;
  sum = 0;
  i = 0;
  num = 1;
  while (num != 0) {
    printf("\nDigite um numero positivo: ");
    scanf("%f", &num);
    while (num < 0) {
      printf("\nNumero invalido.");
      printf("\nDigite um numero positivo: ");
      scanf("%f", &num);
    }
    sum += num;
    i++;
  }
  mean = sum / (i - 1);
  return mean;
}


x86 assembly (clang, -O0):
<calc_mean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  0xec0(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1161 <calc_mean+0x41>
jp     1161 <calc_mean+0x41>
jmp    11dd <calc_mean+0xbd>
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
lea    0xead(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    11b7 <calc_mean+0x97>
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
lea    0xe78(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
jmp    117d <calc_mean+0x5d>
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xe32(%rip),%xmm0
addss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1145 <calc_mean+0x25>
movss  -0xc(%rbp),%xmm0
movss  -0x4(%rbp),%xmm1
movss  0xe11(%rip),%xmm2
subss  %xmm2,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_mean>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x3f800000,0xc(%rsp)
3f
lea    0xece(%rip),%r14
lea    0xee4(%rip),%r15
lea    0xc(%rsp),%rbx
lea    0xedb(%rip),%r12
xorps  %xmm2,%xmm2
xorps  %xmm0,%xmm0
jmp    117f <calc_mean+0x5f>
cs nopw 0x0(%rax,%rax,1)
nop
movss  0x10(%rsp),%xmm0
addss  %xmm3,%xmm0
movss  0x14(%rsp),%xmm2
addss  0xe88(%rip),%xmm2
ucomiss %xmm1,%xmm3
jne    117f <calc_mean+0x5f>
jnp    11bb <calc_mean+0x9b>
movss  %xmm0,0x10(%rsp)
movss  %xmm2,0x14(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
xorps  %xmm1,%xmm1
movss  0xc(%rsp),%xmm3
ucomiss %xmm3,%xmm1
jbe    1160 <calc_mean+0x40>
mov    %r12,%rdi
call   1030 <printf@plt>
jmp    1190 <calc_mean+0x70>
addss  0xe41(%rip),%xmm2
divss  %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"\0ADigite um numero positivo: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [18 x i8] c"\0ANumero invalido.\00"
define float @calc_mean() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = alloca float
store float 0.000000e+00, float* %3
store float 0.000000e+00, float* %1
store float 1.000000e+00, float* %2
br label %5
5: ; preds = %18, %0
%6 = load float, float* %2
%7 = fcmp une float %6, 0.000000e+00
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
br label %11
11: ; preds = %14, %8
%12 = load float, float* %2
%13 = fcmp olt float %12, 0.000000e+00
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
br label %11
18: ; preds = %11
%19 = load float, float* %2
%20 = load float, float* %3
%21 = fadd float %20, %19
store float %21, float* %3
%22 = load float, float* %1
%23 = fadd float %22, 1.000000e+00
store float %23, float* %1
br label %5
24: ; preds = %5
%25 = load float, float* %3
%26 = load float, float* %1
%27 = fsub float %26, 1.000000e+00
%28 = fdiv float %25, %27
store float %28, float* %4
%29 = load float, float* %4
ret float %29
}

LLVM IR (-O2):
@.str = [29 x i8] c"\0ADigite um numero positivo: \00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [18 x i8] c"\0ANumero invalido.\00"
define float @calc_mean() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
store float 1.000000e+00, float* %1
br label %3
3: ; preds = %0, %16
%4 = phi float [ 0.000000e+00, %0 ], [ %19, %16 ]
%5 = phi float [ 0.000000e+00, %0 ], [ %18, %16 ]
%6 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 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* %1)
%8 = load float, float* %1
%9 = fcmp olt float %8, 0.000000e+00
br i1 %9, label %10, label %16
10: ; preds = %3, %10
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%14 = load float, float* %1
%15 = fcmp olt float %14, 0.000000e+00
br i1 %15, label %10, label %16
16: ; preds = %10, %3
%17 = phi float [ %8, %3 ], [ %14, %10 ]
%18 = fadd float %5, %17
%19 = fadd float %4, 1.000000e+00
%20 = fcmp une float %17, 0.000000e+00
br i1 %20, label %3, label %21
21: ; preds = %16
%22 = fadd float %19, -1.000000e+00
%23 = fdiv float %18, %22
ret float %23
}