#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ FBLCD_DrawImg(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                 int, unsigned char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
unsigned int lcd_drawRGBimage(const char *filename) {
  FILE *f;
  unsigned char *buff = (unsigned char *)malloc((800 * 480 * 3));
  if (buff == NULL)
    return 1;
  memset(buff, 0x00, (800 * 480 * 3) + 1);
  f = fopen(filename, "rb");
  if (f == NULL) {
    free(buff);
    return 1;
  }
  fread(&buff[0], 1, (800 * 480 * 3), f);
  fclose(f);
  FBLCD_DrawImg(0, 0, 800, 480, &buff[0]);
  free(buff);
  return 0;
}


x86 assembly (clang, -O0):
<lcd_drawRGBimage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x119400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a1 <lcd_drawRGBimage+0x31>
movl   $0x1,-0x4(%rbp)
jmp    122c <lcd_drawRGBimage+0xbc>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x119401,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e5 <lcd_drawRGBimage+0x75>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    122c <lcd_drawRGBimage+0xbc>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x119400,%edx
call   1050 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%r8
xor    %esi,%esi
mov    $0x320,%edx
mov    $0x1e0,%ecx
mov    %esi,%edi
call   1040 <FBLCD_DrawImg@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcd_drawRGBimage>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
mov    $0x119400,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     11e7 <lcd_drawRGBimage+0x77>
mov    %rax,%rbx
xor    %r14d,%r14d
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x119401,%edx
call   1070 <memset@plt>
lea    0xe5e(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11ef <lcd_drawRGBimage+0x7f>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x119400,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    $0x320,%edx
mov    $0x1e0,%ecx
mov    %rbx,%r8
call   1040 <FBLCD_DrawImg@plt>
jmp    11f5 <lcd_drawRGBimage+0x85>
mov    $0x1,%r14d
jmp    11fd <lcd_drawRGBimage+0x8d>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @lcd_drawRGBimage(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = call i64 @malloc(i32 1152000)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 1, i32* %2
br label %33
11: ; preds = %1
%12 = load i8*, i8** %5
%13 = call i32 @memset(i8* %12, i32 0, i32 1152001)
%14 = load i8*, i8** %3
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %4
%16 = load i32*, i32** %4
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i8*, i8** %5
%20 = call i32 @free(i8* %19)
store i32 1, i32* %2
br label %33
21: ; preds = %11
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i32*, i32** %4
%25 = call i32 @fread(i8* %23, i32 1, i32 1152000, i32* %24)
%26 = load i32*, i32** %4
%27 = call i32 @fclose(i32* %26)
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = call i32 @FBLCD_DrawImg(i32 0, i32 0, i32 800, i32 480, i8* %29)
%31 = load i8*, i8** %5
%32 = call i32 @free(i8* %31)
store i32 0, i32* %2
br label %33
33: ; preds = %21, %18, %10
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @lcd_drawRGBimage(i8* nocapture %0) {
%2 = tail call i64 @malloc(i32 1152000)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = tail call i32 @memset(i8* %3, i32 0, i32 1152001)
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = tail call i32 @fread(i8* %3, i32 1, i32 1152000, i32* %7)
%11 = tail call i32 @fclose(i32* %7)
%12 = tail call i32 @FBLCD_DrawImg(i32 0, i32 0, i32 800, i32 480, i8* %3)
br label %13
13: ; preds = %5, %9
%14 = phi i32 [ 0, %9 ], [ 1, %5 ]
%15 = tail call i32 @free(i8* %3)
br label %16
16: ; preds = %13, %1
%17 = phi i32 [ 1, %1 ], [ %14, %13 ]
ret i32 %17
}