#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 */
double average_numbers(int *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stderr;
main() {
  int *table, i, n;
  printf("Average some integer numbers\n");
  printf("How many integers? ");
  scanf("%d", &n);
  table = (int *)malloc(n * sizeof(int));
  if (table == NULL) {
    fprintf(stderr, "Insufficient memory.\n");
    exit(1);
  }
  for (i = 0; i < n; i++) {
    printf("Enter integer #%d: ", i + 1);
    scanf("%d", &table[i]);
  }
  printf("Average is %.12f\n", average_numbers(table, n));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d8 <main+0x78>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1228 <main+0xc8>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe1d(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11df <main+0x7f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <average_numbers@plt>
lea    0xe24(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe76(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     122f <main+0xbf>
mov    %rax,%r14
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    1209 <main+0x99>
lea    0xe62(%rip),%r15
lea    0xe42(%rip),%r12
mov    %r14,%r13
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
movslq 0xc(%rsp),%rsi
add    $0x4,%r13
cmp    %rsi,%rbx
jl     11e0 <main+0x70>
mov    %r14,%rdi
call   1090 <average_numbers@plt>
lea    0xe29(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Average some integer numbers\0A\00"
@.str.1 = [20 x i8] c"How many integers? \00"
@.str.2 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"Insufficient memory.\0A\00"
@.str.4 = [20 x i8] c"Enter integer #%d: \00"
@.str.5 = [18 x i8] c"Average is %.12f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 4
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %0
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
store i32 0, i32* %3
br label %21
21: ; preds = %34, %20
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %37
25: ; preds = %21
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = load i32*, i32** %2
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %32)
br label %34
34: ; preds = %25
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %21
37: ; preds = %21
%38 = load i32*, i32** %2
%39 = load i32, i32* %4
%40 = call double @average_numbers(i32* %38, i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), double %40)
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"How many integers? \00"
@.str.2 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.3 = [22 x i8] c"Insufficient memory.\0A\00"
@.str.4 = [20 x i8] c"Enter integer #%d: \00"
@.str.5 = [18 x i8] c"Average is %.12f\0A\00"
@str = [29 x i8] c"Average some integer numbers\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = shl i32 %6, 2
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i32*
%10 = icmp eq i64 %8, 0
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br i1 %13, label %18, label %28
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11, %18
%19 = phi i64 [ %20, %18 ], [ 0, %11 ]
%20 = add nuw nsw i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds i32, i32* %9, i64 %19
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %23)
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %20, %26
br i1 %27, label %18, label %28
28: ; preds = %18, %11
%29 = phi i32 [ %12, %11 ], [ %25, %18 ]
%30 = call double @average_numbers(i32* %9, i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), double %30)
ret i32 0
}