#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 */
float abs(int);
float getAverageArray(int *, int);
int getMostDifferentFromAverage(int *array, int length) {
  float diff = 0;
  float average = getAverageArray(array, length);
  int n = 0;
  for (int i = 0; i < length; i++)
    if (diff < abs(array[i] - average)) {
      diff = abs(array[i] - average);
      n = i;
    }
  return n;
}


x86 assembly (clang, -O0):
<getMostDifferentFromAverage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <getAverageArray@plt>
movss  %xmm0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ce <getMostDifferentFromAverage+0xae>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cvtsi2ssl (%rax,%rcx,4),%xmm0
subss  -0x14(%rbp),%xmm0
cvttss2si %xmm0,%edi
call   1030 <abs@plt>
movss  -0x20(%rbp),%xmm1
ucomiss %xmm1,%xmm0
jbe    11bb <getMostDifferentFromAverage+0x9b>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cvtsi2ssl (%rax,%rcx,4),%xmm0
subss  -0x14(%rbp),%xmm0
cvttss2si %xmm0,%edi
call   1030 <abs@plt>
movss  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11c0 <getMostDifferentFromAverage+0xa0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <getMostDifferentFromAverage+0x36>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMostDifferentFromAverage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <getAverageArray@plt>
movss  %xmm0,0x4(%rsp)
test   %ebp,%ebp
jle    1197 <getMostDifferentFromAverage+0x77>
mov    %ebp,%r15d
xorps  %xmm0,%xmm0
movss  %xmm0,(%rsp)
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1159 <getMostDifferentFromAverage+0x39>
nopl   (%rax)
add    $0x1,%rbp
cmp    %rbp,%r15
je     119a <getMostDifferentFromAverage+0x7a>
xorps  %xmm0,%xmm0
cvtsi2ssl (%rbx,%rbp,4),%xmm0
subss  0x4(%rsp),%xmm0
cvttss2si %xmm0,%edi
call   1030 <abs@plt>
ucomiss (%rsp),%xmm0
jbe    1150 <getMostDifferentFromAverage+0x30>
xorps  %xmm0,%xmm0
cvtsi2ssl (%rbx,%rbp,4),%xmm0
subss  0x4(%rsp),%xmm0
cvttss2si %xmm0,%edi
call   1030 <abs@plt>
movss  %xmm0,(%rsp)
mov    %ebp,%r14d
jmp    1150 <getMostDifferentFromAverage+0x30>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getMostDifferentFromAverage(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store float 0.000000e+00, float* %5
%9 = load i32*, i32** %3
%10 = load i32, i32* %4
%11 = call float @getAverageArray(i32* %9, i32 %10)
store float %11, float* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %12
12: ; preds = %42, %2
%13 = load i32, i32* %8
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %45
16: ; preds = %12
%17 = load float, float* %5
%18 = load i32*, i32** %3
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32, i32* %21
%23 = sitofp i32 %22 to float
%24 = load float, float* %6
%25 = fsub float %23, %24
%26 = fptosi float %25 to i32
%27 = call float @abs(i32 %26)
%28 = fcmp olt float %17, %27
br i1 %28, label %29, label %41
29: ; preds = %16
%30 = load i32*, i32** %3
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = sitofp i32 %34 to float
%36 = load float, float* %6
%37 = fsub float %35, %36
%38 = fptosi float %37 to i32
%39 = call float @abs(i32 %38)
store float %39, float* %5
%40 = load i32, i32* %8
store i32 %40, i32* %7
br label %41
41: ; preds = %29, %16
br label %42
42: ; preds = %41
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %12
45: ; preds = %12
%46 = load i32, i32* %7
ret i32 %46
}

LLVM IR (-O2):
define i32 @getMostDifferentFromAverage(i32* %0, i32 %1) {
%3 = tail call float @getAverageArray(i32* %0, i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %9
7: ; preds = %27, %2
%8 = phi i32 [ 0, %2 ], [ %29, %27 ]
ret i32 %8
9: ; preds = %5, %27
%10 = phi i64 [ 0, %5 ], [ %30, %27 ]
%11 = phi i32 [ 0, %5 ], [ %29, %27 ]
%12 = phi float [ 0.000000e+00, %5 ], [ %28, %27 ]
%13 = getelementptr inbounds i32, i32* %0, i64 %10
%14 = load i32, i32* %13
%15 = sitofp i32 %14 to float
%16 = fsub float %15, %3
%17 = fptosi float %16 to i32
%18 = tail call float @abs(i32 %17)
%19 = fcmp olt float %12, %18
br i1 %19, label %20, label %27
20: ; preds = %9
%21 = load i32, i32* %13
%22 = sitofp i32 %21 to float
%23 = fsub float %22, %3
%24 = fptosi float %23 to i32
%25 = tail call float @abs(i32 %24)
%26 = trunc i64 %10 to i32
br label %27
27: ; preds = %9, %20
%28 = phi float [ %25, %20 ], [ %12, %9 ]
%29 = phi i32 [ %26, %20 ], [ %11, %9 ]
%30 = add nuw nsw i64 %10, 1
%31 = icmp eq i64 %30, %6
br i1 %31, label %7, label %9
}