#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*/ scanf(char *, int *);
float average(int x) {
  int sequence;
  int value = 0;
  if (x == 0) {
    return x;
  } else {
    for (int i = 0; i < x; i++) {
      scanf("%d", &sequence);
      value = value + sequence;
    }
    return (float)value / x;
  }
}


x86 assembly (clang, -O0):
<average>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    113b <average+0x2b>
cvtsi2ssl -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1188 <average+0x78>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1175 <average+0x65>
lea    0xeab(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1030 <scanf@plt>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1142 <average+0x32>
cvtsi2ssl -0x10(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<average>:
test   %edi,%edi
je     115a <average+0x4a>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    -0x10(%rsp),%rsp
mov    %edi,%r14d
jle    115e <average+0x4e>
xor    %ebx,%ebx
lea    0xed1(%rip),%r15
lea    0xc(%rsp),%r12
mov    %r14d,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <scanf@plt>
add    0xc(%rsp),%ebx
add    $0xffffffff,%ebp
jne    1140 <average+0x30>
cvtsi2ss %ebx,%xmm0
jmp    1161 <average+0x51>
xorps  %xmm0,%xmm0
ret
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm1
divss  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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