#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 *, float);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int sum = 0, n, i = 0, a;
  float avg = 0;
  scanf("%d", &n);
  while (i < n) {
    scanf("%d", &a);
    sum = sum + a;
    avg = avg + a;
    i++;
  }
  avg = avg / n;
  printf("Sum: %d\n", sum);
  printf("Avg: %.2f\n", avg);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
lea    0xeb4(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119b <main+0x7b>
lea    0xe98(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
movss  -0x18(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1155 <main+0x35>
movss  -0x18(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
cvtsi2ssl -0x8(%rbp),%xmm0
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
movss  -0x18(%rbp),%xmm0
lea    0xe41(%rip),%rdi
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   %rbx
sub    $0x18,%rsp
lea    0xecf(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x10(%rsp),%eax
test   %eax,%eax
jle    119c <main+0x7c>
xor    %ebp,%ebp
xorps  %xmm2,%xmm2
lea    0xeb1(%rip),%r14
lea    0x14(%rsp),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movss  %xmm2,0xc(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
movss  0xc(%rsp),%xmm2
mov    0x14(%rsp),%eax
add    %eax,%ebx
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
addss  %xmm0,%xmm2
add    $0x1,%ebp
mov    0x10(%rsp),%eax
cmp    %eax,%ebp
jl     1160 <main+0x40>
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
jmp    11a2 <main+0x82>
xorps  %xmm0,%xmm0
xorps  %xmm2,%xmm2
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm2
movss  %xmm2,0xc(%rsp)
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
lea    0xe49(%rip),%rdi
movss  0xc(%rsp),%xmm0
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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