#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*/ set_pixel(int, int, unsigned long);
void draw_bitmap_colored(unsigned long *raw_bits, int x, int y, int w, int h,
                         int orig_w, int orig_h, unsigned long ckey,
                         unsigned long add_color) {
  int i, z;
  for (i = 0; i < w; i++)
    for (z = h; z > 0; z--) {
      int pos_x = i;
      int pos_y = z;
      set_pixel(i + x, z + y, raw_bits[pos_x + pos_y * w] + add_color);
    }
}


x86 assembly (clang, -O0):
<draw_bitmap_colored>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b4 <draw_bitmap_colored+0xa4>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    11a1 <draw_bitmap_colored+0x91>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
add    -0xc(%rbp),%edi
mov    -0x24(%rbp),%esi
add    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%edx
imul   -0x14(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
add    0x20(%rbp),%rdx
call   1030 <set_pixel@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1151 <draw_bitmap_colored+0x41>
jmp    11a6 <draw_bitmap_colored+0x96>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113f <draw_bitmap_colored+0x2f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_bitmap_colored>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,0xc(%rsp)
mov    %edx,0x8(%rsp)
mov    %rsi,0x28(%rsp)
test   %ecx,%ecx
jle    11e1 <draw_bitmap_colored+0xd1>
mov    0x80(%rsp),%r13
mov    0xc(%rsp),%edx
movslq %edx,%rax
mov    %ecx,%ecx
add    %edx,0x8(%rsp)
lea    0x1(%rax),%rdx
mov    %rdx,0x20(%rsp)
imul   %rcx,%rax
lea    (%rdi,%rax,8),%rax
mov    %rax,0x18(%rsp)
mov    %rcx,0x30(%rsp)
lea    0x0(,%rcx,8),%r12
neg    %r12
xor    %eax,%eax
mov    %rax,0x10(%rsp)
jmp    119e <draw_bitmap_colored+0x8e>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rcx
add    $0x1,%rcx
addq   $0x8,0x18(%rsp)
mov    %rcx,%rax
mov    %rcx,0x10(%rsp)
cmp    0x30(%rsp),%rcx
je     11e1 <draw_bitmap_colored+0xd1>
cmpl   $0x0,0xc(%rsp)
jle    1180 <draw_bitmap_colored+0x70>
mov    0x28(%rsp),%rax
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,1),%ebp
mov    0x18(%rsp),%r15
mov    0x20(%rsp),%r14
mov    0x8(%rsp),%ebx
mov    (%r15),%rdx
add    %r13,%rdx
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <set_pixel@plt>
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%r14
add    %r12,%r15
cmp    $0x1,%r14
jg     11c0 <draw_bitmap_colored+0xb0>
jmp    1180 <draw_bitmap_colored+0x70>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @draw_bitmap_colored(i64* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i64 %7, i64 %8) {
%10 = alloca i64*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i64
%18 = alloca i64
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
store i64* %0, i64** %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i64 %7, i64* %17
store i64 %8, i64* %18
store i32 0, i32* %19
br label %23
23: ; preds = %57, %9
%24 = load i32, i32* %19
%25 = load i32, i32* %13
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %60
27: ; preds = %23
%28 = load i32, i32* %14
store i32 %28, i32* %20
br label %29
29: ; preds = %53, %27
%30 = load i32, i32* %20
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %56
32: ; preds = %29
%33 = load i32, i32* %19
store i32 %33, i32* %21
%34 = load i32, i32* %20
store i32 %34, i32* %22
%35 = load i32, i32* %19
%36 = load i32, i32* %11
%37 = add nsw i32 %35, %36
%38 = load i32, i32* %20
%39 = load i32, i32* %12
%40 = add nsw i32 %38, %39
%41 = load i64*, i64** %10
%42 = load i32, i32* %21
%43 = load i32, i32* %22
%44 = load i32, i32* %13
%45 = mul nsw i32 %43, %44
%46 = add nsw i32 %42, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i64, i64* %41, i64 %47
%49 = load i64, i64* %48
%50 = load i64, i64* %18
%51 = add i64 %49, %50
%52 = call i32 @set_pixel(i32 %37, i32 %40, i64 %51)
br label %53
53: ; preds = %32
%54 = load i32, i32* %20
%55 = add nsw i32 %54, -1
store i32 %55, i32* %20
br label %29
56: ; preds = %29
br label %57
57: ; preds = %56
%58 = load i32, i32* %19
%59 = add nsw i32 %58, 1
store i32 %59, i32* %19
br label %23
60: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @draw_bitmap_colored(i64* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i64 %7, i64 %8) {
%10 = icmp sgt i32 %3, 0
br i1 %10, label %11, label %36
11: ; preds = %9
%12 = icmp sgt i32 %4, 0
%13 = sext i32 %4 to i64
%14 = zext i32 %3 to i64
%15 = zext i32 %3 to i64
br label %16
16: ; preds = %11, %33
%17 = phi i64 [ 0, %11 ], [ %34, %33 ]
br i1 %12, label %18, label %33
18: ; preds = %16
%19 = trunc i64 %17 to i32
%20 = add i32 %19, %1
br label %21
21: ; preds = %18, %21
%22 = phi i64 [ %13, %18 ], [ %31, %21 ]
%23 = mul nsw i64 %22, %14
%24 = add nsw i64 %23, %17
%25 = getelementptr inbounds i64, i64* %0, i64 %24
%26 = load i64, i64* %25
%27 = add i64 %26, %8
%28 = trunc i64 %22 to i32
%29 = add i32 %28, %2
%30 = tail call i32 @set_pixel(i32 %20, i32 %29, i64 %27)
%31 = add nsw i64 %22, -1
%32 = icmp sgt i64 %22, 1
br i1 %32, label %21, label %33
33: ; preds = %21, %16
%34 = add nuw nsw i64 %17, 1
%35 = icmp eq i64 %34, %15
br i1 %35, label %36, label %16
36: ; preds = %33, %9
ret void
}