#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 *);
int main(int argc, const char *argv[]) {
  int c, lim, sum = 0;
  printf("This program averages a list of 5 integers.\n");
  printf("How many values are there in the list? ");
  scanf("%d", &lim);
  for (int i = 0; i < lim; i++) {
    printf(" ? ");
    scanf("%d", &c);
    sum += c;
  }
  printf("The average is %g\n", sum / 5.0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefd(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11b1 <main+0x91>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1170 <main+0x50>
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  0xe42(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe9b(%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    0xf07(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed3(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11b8 <main+0x88>
lea    0xebe(%rip),%r14
lea    0xeb4(%rip),%r15
lea    0xc(%rsp),%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
add    0xc(%rsp),%ebp
add    $0x1,%ebx
cmp    0x8(%rsp),%ebx
jl     1190 <main+0x60>
cvtsi2sd %ebp,%xmm0
jmp    11bc <main+0x8c>
xorpd  %xmm0,%xmm0
divsd  0xe3c(%rip),%xmm0
lea    0xe6c(%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 = [45 x i8] c"This program averages a list of 5 integers.\0A\00"
@.str.1 = [40 x i8] c"How many values are there in the list? \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c" ? \00"
@.str.4 = [19 x i8] c"The average is %g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
store i32 0, i32* %9
br label %13
13: ; preds = %23, %2
%14 = load i32, i32* %9
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%20 = load i32, i32* %6
%21 = load i32, i32* %8
%22 = add nsw i32 %21, %20
store i32 %22, i32* %8
br label %23
23: ; preds = %17
%24 = load i32, i32* %9
%25 = add nsw i32 %24, 1
store i32 %25, i32* %9
br label %13
26: ; preds = %13
%27 = load i32, i32* %8
%28 = sitofp i32 %27 to double
%29 = fdiv double %28, 5.000000e+00
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), double %29)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [40 x i8] c"How many values are there in the list? \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c" ? \00"
@.str.4 = [19 x i8] c"The average is %g\0A\00"
@str = [44 x i8] c"This program averages a list of 5 integers.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %18, label %14
12: ; preds = %18
%13 = sitofp i32 %24 to double
br label %14
14: ; preds = %12, %2
%15 = phi double [ 0.000000e+00, %2 ], [ %13, %12 ]
%16 = fdiv double %15, 5.000000e+00
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), double %16)
ret i32 0
18: ; preds = %2, %18
%19 = phi i32 [ %25, %18 ], [ 0, %2 ]
%20 = phi i32 [ %24, %18 ], [ 0, %2 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%23 = load i32, i32* %3
%24 = add nsw i32 %23, %20
%25 = add nuw nsw i32 %19, 1
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %18, label %12
}