#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 avgcolor(unsigned char const *, int, int, int, int);
void getcolors(int *output, const unsigned char *data, int xres, int yres) {
  int x;
  for (x = 0; x < 5; ++x) {
    output[x] =
        avgcolor(data, (x * xres) / 5, ((x + 1) * xres) / 5, xres * 3, yres);
  }
}


x86 assembly (clang, -O0):
<getcolors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    1188 <getcolors+0x78>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
imul   -0x14(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
imul   $0x3,-0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <avgcolor@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <getcolors+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcolors>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r8d
mov    %ecx,0x4(%rsp)
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rdx,0x10(%rsp)
lea    (%rdx,%rdx,2),%r13d
movslq %edx,%r15
imul   $0x66666667,%r15,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x21,%rbx
add    %eax,%ebx
mov    %rsi,%rdi
xor    %esi,%esi
mov    %ebx,%edx
mov    %r13d,%ecx
call   1030 <avgcolor@plt>
mov    %eax,(%r12)
mov    %r12,0x8(%rsp)
lea    (%r15,%r15,1),%eax
cltq
imul   $0x66666667,%rax,%rbp
mov    %rbp,%rax
shr    $0x3f,%rax
sar    $0x21,%rbp
add    %eax,%ebp
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r13d,%ebx
mov    %r13d,%ecx
mov    0x4(%rsp),%r13d
mov    %r13d,%r8d
call   1030 <avgcolor@plt>
mov    %eax,0x4(%r12)
movslq %ebx,%r12
imul   $0x66666667,%r12,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x21,%rbx
add    %eax,%ebx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %r13d,%r8d
call   1030 <avgcolor@plt>
mov    0x8(%rsp),%rbp
mov    %eax,0x8(%rbp)
shl    $0x2,%r15d
movslq %r15d,%rax
imul   $0x66666667,%rax,%r15
mov    %r15,%rax
shr    $0x3f,%rax
sar    $0x21,%r15
add    %eax,%r15d
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r12d,%ecx
mov    %r13d,%r8d
call   1030 <avgcolor@plt>
mov    %eax,0xc(%rbp)
mov    0x10(%rsp),%rax
lea    (%rax,%rax,4),%eax
cltq
imul   $0x66666667,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x21,%rdx
add    %eax,%edx
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%ecx
mov    %r13d,%r8d
call   1030 <avgcolor@plt>
mov    %eax,0x10(%rbp)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @getcolors(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %32, %4
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 5
br i1 %12, label %13, label %35
13: ; preds = %10
%14 = load i8*, i8** %6
%15 = load i32, i32* %9
%16 = load i32, i32* %7
%17 = mul nsw i32 %15, %16
%18 = sdiv i32 %17, 5
%19 = load i32, i32* %9
%20 = add nsw i32 %19, 1
%21 = load i32, i32* %7
%22 = mul nsw i32 %20, %21
%23 = sdiv i32 %22, 5
%24 = load i32, i32* %7
%25 = mul nsw i32 %24, 3
%26 = load i32, i32* %8
%27 = call i32 @avgcolor(i8* %14, i32 %18, i32 %23, i32 %25, i32 %26)
%28 = load i32*, i32** %5
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %27, i32* %31
br label %32
32: ; preds = %13
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %10
35: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @getcolors(i32* nocapture writeonly %0, i8* %1, i32 %2, i32 %3) {
%5 = mul nsw i32 %2, 3
%6 = sdiv i32 %2, 5
%7 = tail call i32 @avgcolor(i8* %1, i32 0, i32 %6, i32 %5, i32 %3)
store i32 %7, i32* %0
%8 = shl i32 %2, 1
%9 = sdiv i32 %8, 5
%10 = tail call i32 @avgcolor(i8* %1, i32 %6, i32 %9, i32 %5, i32 %3)
%11 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %10, i32* %11
%12 = mul i32 %2, 3
%13 = sdiv i32 %12, 5
%14 = tail call i32 @avgcolor(i8* %1, i32 %9, i32 %13, i32 %5, i32 %3)
%15 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %14, i32* %15
%16 = shl i32 %2, 2
%17 = sdiv i32 %16, 5
%18 = tail call i32 @avgcolor(i8* %1, i32 %13, i32 %17, i32 %5, i32 %3)
%19 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %18, i32* %19
%20 = mul i32 %2, 5
%21 = sdiv i32 %20, 5
%22 = tail call i32 @avgcolor(i8* %1, i32 %17, i32 %21, i32 %5, i32 %3)
%23 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %22, i32* %23
ret void
}