#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*/ printf(char *, int, int, unsigned char, unsigned char,
                          unsigned char);
void readAtPos(char *buffer, int x, int y, int width, int height,
               int bytesPerPixel) {
  int realY = height - y - 1;
  unsigned char *pixel =
      (unsigned char *)(buffer + realY * width * bytesPerPixel +
                        x * bytesPerPixel);
  printf("Na pos (%d,%d) temos RGB: %d %d %d\n", x, y, *(pixel + 2),
         *(pixel + 1), *pixel);
}


x86 assembly (clang, -O0):
<readAtPos>:
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    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x14(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    -0xc(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x28(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x28(%rbp),%rax
mov    0x1(%rax),%r8b
mov    -0x28(%rbp),%rax
lea    0xe81(%rip),%rdi
movzbl %cl,%ecx
movzbl %r8b,%r8d
movzbl (%rax),%r9d
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readAtPos>:
mov    %edx,%eax
not    %eax
add    %r8d,%eax
imul   %r9d,%ecx
imul   %eax,%ecx
movslq %ecx,%rax
add    %rdi,%rax
imul   %esi,%r9d
movslq %r9d,%rdi
movzbl 0x2(%rdi,%rax,1),%ecx
movzbl 0x1(%rdi,%rax,1),%r8d
movzbl (%rdi,%rax,1),%r9d
lea    0xebe(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Na pos (%d,%d) temos RGB: %d %d %d\0A\00"
define void @readAtPos(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%15 = load i32, i32* %11
%16 = load i32, i32* %9
%17 = sub nsw i32 %15, %16
%18 = sub nsw i32 %17, 1
store i32 %18, i32* %13
%19 = load i8*, i8** %7
%20 = load i32, i32* %13
%21 = load i32, i32* %10
%22 = mul nsw i32 %20, %21
%23 = load i32, i32* %12
%24 = mul nsw i32 %22, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %19, i64 %25
%27 = load i32, i32* %8
%28 = load i32, i32* %12
%29 = mul nsw i32 %27, %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %26, i64 %30
store i8* %31, i8** %14
%32 = load i32, i32* %8
%33 = load i32, i32* %9
%34 = load i8*, i8** %14
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = load i8, i8* %35
%37 = load i8*, i8** %14
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = load i8*, i8** %14
%41 = load i8, i8* %40
%42 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %32, i32 %33, i8 zeroext %36, i8 zeroext %39, i8 zeroext %41)
ret void
}

LLVM IR (-O2):
@.str = [36 x i8] c"Na pos (%d,%d) temos RGB: %d %d %d\0A\00"
define void @readAtPos(i8* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = xor i32 %2, -1
%8 = add i32 %7, %4
%9 = mul nsw i32 %8, %3
%10 = mul nsw i32 %9, %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = mul nsw i32 %5, %1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 2
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %15, i64 1
%19 = load i8, i8* %18
%20 = load i8, i8* %15
%21 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2, i8 zeroext %17, i8 zeroext %19, i8 zeroext %20)
ret void
}