#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*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ stderr;
int get_average(int *array_start, int start_index, int end_index, int io_type) {
  int *start_addr = array_start + start_index;
  int sum = 0;
  int i;
  for (i = 0; i < end_index - start_index + 1; i++) {
    sum += start_addr[i];
    fprintf(stderr, " value %i\n", start_addr[i]);
  }
  fprintf(stderr, "%i items' sum is %i, average is %i\n",
          (end_index - start_index + 1), sum,
          sum / (end_index - start_index + 1));
  return sum / (end_index - start_index + 1);
}


x86 assembly (clang, -O0):
<get_average>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    119b <get_average+0x8b>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1146 <get_average+0x36>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
add    $0x1,%esi
cltd
idiv   %esi
mov    -0x2c(%rbp),%edx
mov    %eax,%r8d
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_average>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
sub    %esi,%edx
mov    %rdx,(%rsp)
js     115f <get_average+0x4f>
movslq %esi,%rax
lea    (%rdi,%rax,4),%r12
lea    0x1(%rdx),%ebx
mov    0x2eac(%rip),%r13
lea    0xec5(%rip),%r15
xor    %r14d,%r14d
xor    %ebp,%ebp
mov    (%r12,%r14,4),%edx
add    %edx,%ebp
mov    0x0(%r13),%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%rbx
jne    1140 <get_average+0x30>
jmp    1161 <get_average+0x51>
xor    %ebp,%ebp
mov    (%rsp),%rcx
add    $0x1,%ecx
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%ebx
lea    0xe8c(%rip),%rsi
mov    %ecx,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c" value %i\0A\00"
@.str.1 = [36 x i8] c"%i items' sum is %i, average is %i\0A\00"
define i32 @get_average(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32*, i32** %5
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
store i32* %15, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %16
16: ; preds = %38, %4
%17 = load i32, i32* %11
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = sub nsw i32 %18, %19
%21 = add nsw i32 %20, 1
%22 = icmp slt i32 %17, %21
br i1 %22, label %23, label %41
23: ; preds = %16
%24 = load i32*, i32** %9
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = load i32, i32* %10
%30 = add nsw i32 %29, %28
store i32 %30, i32* %10
%31 = load i32, i32* @stderr
%32 = load i32*, i32** %9
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %23
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
store i32 %40, i32* %11
br label %16
41: ; preds = %16
%42 = load i32, i32* @stderr
%43 = load i32, i32* %7
%44 = load i32, i32* %6
%45 = sub nsw i32 %43, %44
%46 = add nsw i32 %45, 1
%47 = load i32, i32* %10
%48 = load i32, i32* %10
%49 = load i32, i32* %7
%50 = load i32, i32* %6
%51 = sub nsw i32 %49, %50
%52 = add nsw i32 %51, 1
%53 = sdiv i32 %48, %52
%54 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %46, i32 %47, i32 %53)
%55 = load i32, i32* %10
%56 = load i32, i32* %7
%57 = load i32, i32* %6
%58 = sub nsw i32 %56, %57
%59 = add nsw i32 %58, 1
%60 = sdiv i32 %55, %59
ret i32 %60
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c" value %i\0A\00"
@.str.1 = [36 x i8] c"%i items' sum is %i, average is %i\0A\00"
define i32 @get_average(i32* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = sext i32 %1 to i64
%6 = getelementptr inbounds i32, i32* %0, i64 %5
%7 = sub nsw i32 %2, %1
%8 = icmp slt i32 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %4
%10 = add i32 %2, 1
%11 = sub i32 %10, %1
%12 = zext i32 %11 to i64
br label %13
13: ; preds = %9, %13
%14 = phi i64 [ 0, %9 ], [ %21, %13 ]
%15 = phi i32 [ 0, %9 ], [ %18, %13 ]
%16 = getelementptr inbounds i32, i32* %6, i64 %14
%17 = load i32, i32* %16
%18 = add nsw i32 %17, %15
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %17)
%21 = add nuw nsw i64 %14, 1
%22 = icmp eq i64 %21, %12
br i1 %22, label %23, label %13
23: ; preds = %13, %4
%24 = phi i32 [ 0, %4 ], [ %18, %13 ]
%25 = add nsw i32 %7, 1
%26 = load i32, i32* @stderr
%27 = sdiv i32 %24, %25
%28 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %24, i32 %27)
ret i32 %27
}