#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() {
  float num, average, sum;
  int i, n;
  printf("Maximum no. of inputs\n");
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    printf("Enter n%d: ", i);
    scanf("%f", &num);
    if (num < 0.0)
      break;
    sum = sum + num;
  }
  average = sum / (i - 1);
  printf("Average=%.2f", average);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11bd <main+0x9d>
mov    -0x14(%rbp),%esi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11a0 <main+0x80>
jmp    11bd <main+0x9d>
movss  -0x10(%rbp),%xmm0
addss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <main+0x36>
movss  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe44(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb6(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0x10(%rsp)
jle    11c4 <main+0x94>
mov    $0x1,%ebx
lea    0xe9a(%rip),%r14
lea    0xe9f(%rip),%r15
lea    0x14(%rsp),%r12
nopl   0x0(%rax)
movss  %xmm1,0xc(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movss  0x14(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
ja     11cb <main+0x9b>
movss  0xc(%rsp),%xmm1
addss  %xmm0,%xmm1
lea    0x1(%rbx),%eax
cmp    0x10(%rsp),%ebx
mov    %eax,%ebx
jl     1180 <main+0x50>
jmp    11d3 <main+0xa3>
mov    $0x1,%eax
jmp    11d3 <main+0xa3>
mov    %ebx,%eax
movss  0xc(%rsp),%xmm1
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xe27(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Maximum no. of inputs\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"Enter n%d: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [13 x i8] c"Average=%.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
store i32 1, i32* %5
br label %9
9: ; preds = %25, %0
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = load i32, i32* %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %2)
%17 = load float, float* %2
%18 = fpext float %17 to double
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %20, label %21
20: ; preds = %13
br label %28
21: ; preds = %13
%22 = load float, float* %4
%23 = load float, float* %2
%24 = fadd float %22, %23
store float %24, float* %4
br label %25
25: ; preds = %21
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %9
28: ; preds = %20, %9
%29 = load float, float* %4
%30 = load i32, i32* %5
%31 = sub nsw i32 %30, 1
%32 = sitofp i32 %31 to float
%33 = fdiv float %29, %32
store float %33, float* %3
%34 = load float, float* %3
%35 = fpext float %34 to double
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), double %35)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"Enter n%d: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [13 x i8] c"Average=%.2f\00"
@str = [22 x i8] c"Maximum no. of inputs\00"
define i32 @main() {
%1 = alloca float
%2 = alloca i32
%3 = bitcast float* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 1
br i1 %8, label %21, label %9
9: ; preds = %0, %16
%10 = phi i32 [ %18, %16 ], [ 1, %0 ]
%11 = phi float [ %17, %16 ], [ undef, %0 ]
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %1)
%14 = load float, float* %1
%15 = fcmp olt float %14, 0.000000e+00
br i1 %15, label %21, label %16
16: ; preds = %9
%17 = fadd float %11, %14
%18 = add nuw nsw i32 %10, 1
%19 = load i32, i32* %2
%20 = icmp slt i32 %10, %19
br i1 %20, label %9, label %21
21: ; preds = %16, %9, %0
%22 = phi float [ undef, %0 ], [ %11, %9 ], [ %17, %16 ]
%23 = phi i32 [ 1, %0 ], [ %10, %9 ], [ %18, %16 ]
%24 = add nsw i32 %23, -1
%25 = sitofp i32 %24 to float
%26 = fdiv float %22, %25
%27 = fpext float %26 to double
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), double %27)
ret i32 0
}