#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 */
void *malloc(int);
int /*<<< orphan*/ rgb565_to_rgb888(void const *, int, int, void *);
void *rgb565_to_rgb888_buffer(const void *p565, int w, int h) {
  int size = w * h * 3;
  void *p888 = NULL;
  if (p565 && w > 0 && h > 0) {
    p888 = malloc(size);
    if (p888)
      rgb565_to_rgb888(p565, w, h, p888);
  }
  return p888;
}


x86 assembly (clang, -O0):
<rgb565_to_rgb888_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
imul   $0x3,%eax,%eax
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1195 <rgb565_to_rgb888_buffer+0x75>
cmpl   $0x0,-0xc(%rbp)
jle    1195 <rgb565_to_rgb888_buffer+0x75>
cmpl   $0x0,-0x10(%rbp)
jle    1195 <rgb565_to_rgb888_buffer+0x75>
mov    -0x14(%rbp),%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1190 <rgb565_to_rgb888_buffer+0x70>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1040 <rgb565_to_rgb888@plt>
jmp    1195 <rgb565_to_rgb888_buffer+0x75>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgb565_to_rgb888_buffer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rdi,%rdi
je     1168 <rgb565_to_rgb888_buffer+0x48>
mov    %esi,%ebp
test   %esi,%esi
jle    1168 <rgb565_to_rgb888_buffer+0x48>
mov    %edx,%r14d
test   %edx,%edx
jle    1168 <rgb565_to_rgb888_buffer+0x48>
mov    %rdi,%r15
mov    %ebp,%eax
imul   %r14d,%eax
lea    (%rax,%rax,2),%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     1166 <rgb565_to_rgb888_buffer+0x46>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1040 <rgb565_to_rgb888@plt>
jmp    1168 <rgb565_to_rgb888_buffer+0x48>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @rgb565_to_rgb888_buffer(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = mul nsw i32 %9, %10
%12 = mul nsw i32 %11, 3
store i32 %12, i32* %7
store i8* null, i8** %8
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %33
15: ; preds = %3
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = load i32, i32* %7
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = load i8*, i8** %8
%31 = call i32 @rgb565_to_rgb888(i8* %27, i32 %28, i32 %29, i8* %30)
br label %32
32: ; preds = %26, %21
br label %33
33: ; preds = %32, %18, %15, %3
%34 = load i8*, i8** %8
ret i8* %34
}

LLVM IR (-O2):
define i8* @rgb565_to_rgb888_buffer(i8* %0, i32 %1, i32 %2) {
%4 = icmp ne i8* %0, null
%5 = icmp sgt i32 %1, 0
%6 = and i1 %4, %5
%7 = icmp sgt i32 %2, 0
%8 = and i1 %6, %7
br i1 %8, label %9, label %16
9: ; preds = %3
%10 = mul i32 %1, 3
%11 = mul i32 %10, %2
%12 = tail call i8* @malloc(i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = tail call i32 @rgb565_to_rgb888(i8* %0, i32 %1, i32 %2, i8* %12)
br label %16
16: ; preds = %9, %14, %3
%17 = phi i8* [ %12, %14 ], [ null, %9 ], [ null, %3 ]
ret i8* %17
}