#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int n, count;
  double avg, d, sum = 0.;
  double list[100];
  printf("\nHow many numbers do you want to average? ");
  scanf("%d", &n);
  if ((n > 100) || (n <= 0)) {
    printf("\nError: invalid value for n\n");
    exit(1);
  }
  for (count = 0; count < n; ++count) {
    printf("i = %d  x = ", count + 1);
    scanf("%lf", &list[count]);
    sum += list[count];
  }
  avg = sum / (double)n;
  printf("\nThe average is %5.2f\n\n", avg);
  for (count = 0; count < n; ++count) {
    d = list[count] - avg;
    printf("i = %d  x = %5.2f  d = %5.2f\n", count + 1, list[count], d);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x64,-0x8(%rbp)
jg     117e <main+0x4e>
cmpl   $0x0,-0x8(%rbp)
jg     1196 <main+0x66>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1202 <main+0xd2>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0xc(%rbp),%rax
lea    -0x350(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movslq -0xc(%rbp),%rax
movsd  -0x350(%rbp,%rax,8),%xmm0
ff ff
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119d <main+0x6d>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe3b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1286 <main+0x156>
movslq -0xc(%rbp),%rax
movsd  -0x350(%rbp,%rax,8),%xmm0
ff ff
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%esi
add    $0x1,%esi
movslq -0xc(%rbp),%rax
movsd  -0x350(%rbp,%rax,8),%xmm0
ff ff
movsd  -0x20(%rbp),%xmm1
lea    0xe03(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    122f <main+0xff>
xor    %eax,%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x338,%rsp
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec8(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
add    $0xffffff9b,%eax
cmp    $0xffffff9c,%eax
jb     124b <main+0x10b>
xorpd  %xmm0,%xmm0
lea    0x10(%rsp),%r12
lea    0xe9f(%rip),%r14
lea    0xea5(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
add    $0x1,%rbx
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>
movsd  0x8(%rsp),%xmm0
addsd  (%r12),%xmm0
movslq 0x4(%rsp),%rax
add    $0x8,%r12
cmp    %rax,%rbx
jl     11a0 <main+0x60>
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe4d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    123a <main+0xfa>
xor    %ebx,%ebx
lea    0xe4e(%rip),%r14
nopl   0x0(%rax)
movsd  0x10(%rsp,%rbx,8),%xmm0
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x2,%al
call   1040 <printf@plt>
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jl     1210 <main+0xd0>
xor    %eax,%eax
add    $0x338,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"\0AHow many numbers do you want to average? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"\0AError: invalid value for n\0A\00"
@.str.3 = [13 x i8] c"i = %d x = \00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [24 x i8] c"\0AThe average is %5.2f\0A\0A\00"
@.str.6 = [30 x i8] c"i = %d x = %5.2f d = %5.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca [100 x double]
store i32 0, i32* %1
store double 0.000000e+00, double* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 100
br i1 %11, label %15, label %12
12: ; preds = %0
%13 = load i32, i32* %2
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12, %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
store i32 0, i32* %3
br label %19
19: ; preds = %37, %18
%20 = load i32, i32* %3
%21 = load i32, i32* %2
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %40
23: ; preds = %19
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [100 x double], [100 x double]* %7, i64 0, i64 %28
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %29)
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [100 x double], [100 x double]* %7, i64 0, i64 %32
%34 = load double, double* %33
%35 = load double, double* %6
%36 = fadd double %35, %34
store double %36, double* %6
br label %37
37: ; preds = %23
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %19
40: ; preds = %19
%41 = load double, double* %6
%42 = load i32, i32* %2
%43 = sitofp i32 %42 to double
%44 = fdiv double %41, %43
store double %44, double* %4
%45 = load double, double* %4
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), double %45)
store i32 0, i32* %3
br label %47
47: ; preds = %66, %40
%48 = load i32, i32* %3
%49 = load i32, i32* %2
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %69
51: ; preds = %47
%52 = load i32, i32* %3
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x double], [100 x double]* %7, i64 0, i64 %53
%55 = load double, double* %54
%56 = load double, double* %4
%57 = fsub double %55, %56
store double %57, double* %5
%58 = load i32, i32* %3
%59 = add nsw i32 %58, 1
%60 = load i32, i32* %3
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [100 x double], [100 x double]* %7, i64 0, i64 %61
%63 = load double, double* %62
%64 = load double, double* %5
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %59, double %63, double %64)
br label %66
66: ; preds = %51
%67 = load i32, i32* %3
%68 = add nsw i32 %67, 1
store i32 %68, i32* %3
br label %47
69: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
@.str = [43 x i8] c"\0AHow many numbers do you want to average? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [13 x i8] c"i = %d x = \00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [24 x i8] c"\0AThe average is %5.2f\0A\0A\00"
@.str.6 = [30 x i8] c"i = %d x = %5.2f d = %5.2f\0A\00"
@str = [28 x i8] c"\0AError: invalid value for n\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x double]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [100 x double]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 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* %1)
%7 = load i32, i32* %1
%8 = add i32 %7, -101
%9 = icmp ult i32 %8, -100
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0, %13
%14 = phi i64 [ %16, %13 ], [ 0, %0 ]
%15 = phi double [ %22, %13 ], [ 0.000000e+00, %0 ]
%16 = add nuw nsw i64 %14, 1
%17 = trunc i64 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [100 x double], [100 x double]* %2, i64 0, i64 %14
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %19)
%21 = load double, double* %19
%22 = fadd double %15, %21
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %16, %24
br i1 %25, label %13, label %26
26: ; preds = %13
%27 = sitofp i32 %23 to double
%28 = fdiv double %22, %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), double %28)
%30 = load i32, i32* %1
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %26, %32
%33 = phi i64 [ %37, %32 ], [ 0, %26 ]
%34 = getelementptr inbounds [100 x double], [100 x double]* %2, i64 0, i64 %33
%35 = load double, double* %34
%36 = fsub double %35, %28
%37 = add nuw nsw i64 %33, 1
%38 = trunc i64 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %38, double %35, double %36)
%40 = load i32, i32* %1
%41 = sext i32 %40 to i64
%42 = icmp slt i64 %37, %41
br i1 %42, label %32, label %43
43: ; preds = %32, %26
ret i32 0
}