#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 main(void) {
  int n;
  int nPos = 0;
  int i;
  float sum = 0;
  float temp;
  float avg;
  printf("\nPlease input how many numbers you want to calculate the average "
         "of.\nNote that only positive numbers will be calculated.\n");
  scanf("\n%d\n", &n);
  while (n < 1) {
    printf("\nThe integer you input is invalid. Please input an integer of 1 "
           "or more.");
    scanf("\n%d\n", &n);
  }
  for (i = 1; i <= n; i++) {
    printf("\nPlease input the next number.");
    scanf("\n%f", &temp);
    if (temp > 0) {
      sum += temp;
      nPos++;
    }
  }
  avg = (sum / nPos);
  printf("\n\nThe average of your numbers is %f", avg);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf27(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jge    118d <main+0x6d>
lea    0xf10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefd(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
jmp    115e <main+0x3e>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11fc <main+0xdc>
lea    0xf21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf32(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movss  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11e9 <main+0xc9>
movss  -0x18(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ee <main+0xce>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1194 <main+0x74>
movss  -0x14(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xecc(%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    0xf5a(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jg     119e <main+0x6e>
lea    0xea4(%rip),%r14
lea    0xe98(%rip),%r15
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    1180 <main+0x50>
lea    0xeb1(%rip),%r14
lea    0xec9(%rip),%r15
lea    0xc(%rsp),%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
xorps  %xmm1,%xmm1
nopl   0x0(%rax,%rax,1)
movss  %xmm1,0x8(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movss  0x8(%rsp),%xmm1
movss  0xc(%rsp),%xmm0
xor    %eax,%eax
ucomiss 0xe12(%rip),%xmm0
seta   %al
maxss  0xe03(%rip),%xmm0
addss  %xmm0,%xmm1
add    %eax,%ebp
add    $0x1,%ebx
cmp    0x4(%rsp),%ebx
jl     11c0 <main+0x90>
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe54(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [122 x i8] c"\0APlease input how many numbers you want to calculate the average of.\0ANote that only positive numbers will be calculated.\0A\00"
@.str.1 = [5 x i8] c"\0A%d\0A\00"
@.str.2 = [73 x i8] c"\0AThe integer you input is invalid. Please input an integer of 1 or more.\00"
@.str.3 = [31 x i8] c"\0APlease input the next number.\00"
@.str.4 = [4 x i8] c"\0A%f\00"
@.str.5 = [36 x i8] c"\0A\0AThe average of your numbers is %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca float
store i32 0, i32* %1
store i32 0, i32* %3
store float 0.000000e+00, float* %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([122 x i8], [122 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %10
10: ; preds = %13, %0
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %10
16: ; preds = %10
store i32 1, i32* %4
br label %17
17: ; preds = %33, %16
%18 = load i32, i32* %4
%19 = load i32, i32* %2
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), float* %6)
%24 = load float, float* %6
%25 = fcmp ogt float %24, 0.000000e+00
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load float, float* %6
%28 = load float, float* %5
%29 = fadd float %28, %27
store float %29, float* %5
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %32
32: ; preds = %26, %21
br label %33
33: ; preds = %32
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %17
36: ; preds = %17
%37 = load float, float* %5
%38 = load i32, i32* %3
%39 = sitofp i32 %38 to float
%40 = fdiv float %37, %39
store float %40, float* %7
%41 = load float, float* %7
%42 = fpext float %41 to double
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), double %42)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"\0A%d\0A\00"
@.str.2 = [73 x i8] c"\0AThe integer you input is invalid. Please input an integer of 1 or more.\00"
@.str.3 = [31 x i8] c"\0APlease input the next number.\00"
@.str.4 = [4 x i8] c"\0A%f\00"
@.str.5 = [36 x i8] c"\0A\0AThe average of your numbers is %f\00"
@str = [121 x i8] c"\0APlease input how many numbers you want to calculate the average of.\0ANote that only positive numbers will be calculated.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = bitcast i32* %1 to i8*
%4 = bitcast float* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([121 x i8], [121 x i8]* @str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %14
9: ; preds = %0, %9
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = icmp slt i32 %12, 1
br i1 %13, label %9, label %14
14: ; preds = %9, %0
br label %15
15: ; preds = %14, %15
%16 = phi i32 [ %27, %15 ], [ 0, %14 ]
%17 = phi float [ %25, %15 ], [ 0.000000e+00, %14 ]
%18 = phi i32 [ %28, %15 ], [ 1, %14 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), float* %2)
%21 = load float, float* %2
%22 = fcmp ogt float %21, 0.000000e+00
%23 = fcmp ogt float %21, -0.000000e+00
%24 = select i1 %23, float %21, float -0.000000e+00
%25 = fadd float %17, %24
%26 = zext i1 %22 to i32
%27 = add nuw nsw i32 %16, %26
%28 = add nuw nsw i32 %18, 1
%29 = load i32, i32* %1
%30 = icmp slt i32 %18, %29
br i1 %30, label %15, label %31
31: ; preds = %15
%32 = sitofp i32 %27 to float
%33 = fdiv float %25, %32
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), double %34)
ret i32 0
}