#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 */
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int min_avg(int *, int, int, int, int, int);
int /*<<< orphan*/ printf(char *, int);
void main() {
  int a[] = {1, 7, 4, 3, 8, 3, 9, 1000};
  int len = sizeof(a) / sizeof(a[0]);
  int sum = 0;
  for (int i = 0; i < len; i++) {
    sum = sum + a[i];
  }
  printf("Min avg diff is %d", min_avg(a, len, 1, 1, sum, a[0]));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xec8(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x8,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1191 <main+0x71>
mov    -0x28(%rbp),%eax
movslq -0x2c(%rbp),%rcx
add    -0x20(%rbp,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1169 <main+0x49>
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    $0x1,%ecx
mov    %ecx,%edx
call   1040 <min_avg@plt>
mov    %eax,%esi
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
movaps 0xee5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xec9(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
mov    $0x40b,%r8d
mov    $0x1,%r9d
call   1040 <min_avg@plt>
lea    0xebb(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
@__const.main.a = [8 x i32] [i32 1, i32 7, i32 4, i32 3, i32 8, i32 3, i32 9, i32 1000]
@.str = [19 x i8] c"Min avg diff is %d\00"
define void @main() {
%1 = alloca [8 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast [8 x i32]* %1 to i8*
store i32 8, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %17, %0
%7 = load i32, i32* %4
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %20
10: ; preds = %6
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = add nsw i32 %11, %15
store i32 %16, i32* %3
br label %17
17: ; preds = %10
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %6
20: ; preds = %6
%21 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @min_avg(i32* %21, i32 %22, i32 1, i32 1, i32 %23, i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %26)
ret void
}

LLVM IR (-O2):
@__const.main.a = [8 x i32] [i32 1, i32 7, i32 4, i32 3, i32 8, i32 3, i32 9, i32 1000]
@.str = [19 x i8] c"Min avg diff is %d\00"
define void @main() {
%1 = alloca [8 x i32]
%2 = bitcast [8 x i32]* %1 to i8*
%3 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%4 = call i32 @min_avg(i32* %3, i32 8, i32 1, i32 1, i32 1035, i32 1)
%5 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %4)
ret void
}