#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 */
unsigned char *malloc(int);
scalar_t__ rt_mynode();
int /*<<< orphan*/ rt_ui_message(int, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int fakeimage(char *name, int *xres, int *yres, unsigned char **imgdata) {
  int i, imgsize;
  if (rt_mynode() == 0) {
    char msgtxt[2048];
    sprintf(msgtxt, "Error loading image %s.  Faking it using solid gray.",
            name);
    rt_ui_message(100, msgtxt);
  }
  *xres = 4;
  *yres = 4;
  imgsize = 3 * (*xres) * (*yres);
  *imgdata = malloc(imgsize);
  for (i = 0; i < imgsize; i++) {
    (*imgdata)[i] = 255;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fakeimage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x0,%al
call   1060 <rt_mynode@plt>
cmp    $0x0,%rax
jne    1194 <fakeimage+0x54>
lea    -0x830(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x830(%rbp),%rsi
mov    $0x64,%edi
call   1030 <rt_ui_message@plt>
mov    -0x10(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x10(%rbp),%rax
imul   $0x3,(%rax),%eax
mov    -0x18(%rbp),%rcx
imul   (%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11fb <fakeimage+0xbb>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d2 <fakeimage+0x92>
xor    %eax,%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fakeimage>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbp
xor    %eax,%eax
call   1060 <rt_mynode@plt>
test   %rax,%rax
jne    1189 <fakeimage+0x49>
lea    0xe92(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbp,%rdx
call   1050 <sprintf@plt>
mov    $0x64,%edi
mov    %r12,%rsi
call   1030 <rt_ui_message@plt>
movl   $0x4,(%r14)
movl   $0x4,(%r15)
mov    (%r14),%eax
shl    $0x2,%eax
lea    (%rax,%rax,2),%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
test   %ebp,%ebp
jle    1214 <fakeimage+0xd4>
movb   $0xff,(%rax)
mov    $0x1,%eax
cmp    $0x4,%ebp
je     11fd <fakeimage+0xbd>
mov    %ebp,%ecx
add    $0xfffffffffffffffc,%rcx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx),%rdx
movb   $0xff,0x1(%rdx,%rax,1)
mov    (%rbx),%rdx
movb   $0xff,0x2(%rdx,%rax,1)
mov    (%rbx),%rdx
movb   $0xff,0x3(%rdx,%rax,1)
mov    (%rbx),%rdx
movb   $0xff,0x4(%rdx,%rax,1)
add    $0x4,%rax
cmp    %rax,%rcx
jne    11d0 <fakeimage+0x90>
add    $0x1,%rax
xor    %ecx,%ecx
nop
mov    (%rbx),%rdx
add    %rax,%rdx
movb   $0xff,(%rcx,%rdx,1)
add    $0x1,%rcx
cmp    $0x3,%rcx
jne    1200 <fakeimage+0xc0>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"Error loading image %s. Faking it using solid gray.\00"
define i32 @fakeimage(i8* %0, i32* %1, i32* %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca [2048 x i8]
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i8** %3, i8*** %8
%12 = call i64 (...) @rt_mynode()
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %4
%15 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%19 = call i32 @rt_ui_message(i32 100, i8* %18)
br label %20
20: ; preds = %14, %4
%21 = load i32*, i32** %6
store i32 4, i32* %21
%22 = load i32*, i32** %7
store i32 4, i32* %22
%23 = load i32*, i32** %6
%24 = load i32, i32* %23
%25 = mul nsw i32 3, %24
%26 = load i32*, i32** %7
%27 = load i32, i32* %26
%28 = mul nsw i32 %25, %27
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = call i8* @malloc(i32 %29)
%31 = load i8**, i8*** %8
store i8* %30, i8** %31
store i32 0, i32* %9
br label %32
32: ; preds = %42, %20
%33 = load i32, i32* %9
%34 = load i32, i32* %10
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i8**, i8*** %8
%38 = load i8*, i8** %37
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 -1, i8* %41
br label %42
42: ; preds = %36
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %32
45: ; preds = %32
ret i32 0
}

LLVM IR (-O2):
@.str = [53 x i8] c"Error loading image %s. Faking it using solid gray.\00"
define i32 @fakeimage(i8* %0, i32* nocapture %1, i32* nocapture writeonly %2, i8** nocapture %3) {
%5 = alloca [2048 x i8]
%6 = tail call i64 (...) @rt_mynode()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = call i32 @rt_ui_message(i32 100, i8* %9)
br label %12
12: ; preds = %8, %4
store i32 4, i32* %1
store i32 4, i32* %2
%13 = load i32, i32* %1
%14 = mul i32 %13, 12
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %3
%16 = icmp sgt i32 %14, 0
br i1 %16, label %17, label %49
17: ; preds = %12
store i8 -1, i8* %15
%18 = icmp eq i32 %14, 4
br i1 %18, label %39, label %19
19: ; preds = %17
%20 = zext i32 %14 to i64
%21 = add nsw i64 %20, -4
br label %22
22: ; preds = %22, %19
%23 = phi i64 [ 1, %19 ], [ %36, %22 ]
%24 = phi i64 [ 0, %19 ], [ %37, %22 ]
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 %23
store i8 -1, i8* %26
%27 = add nuw nsw i64 %23, 1
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 %27
store i8 -1, i8* %29
%30 = add nuw nsw i64 %23, 2
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 %30
store i8 -1, i8* %32
%33 = add nuw nsw i64 %23, 3
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 %33
store i8 -1, i8* %35
%36 = add nuw nsw i64 %23, 4
%37 = add i64 %24, 4
%38 = icmp eq i64 %37, %21
br i1 %38, label %39, label %22
39: ; preds = %17, %22
%40 = phi i64 [ 1, %17 ], [ %36, %22 ]
br label %41
41: ; preds = %41, %39
%42 = phi i64 [ %40, %39 ], [ %46, %41 ]
%43 = phi i64 [ 0, %39 ], [ %47, %41 ]
%44 = load i8*, i8** %3
%45 = getelementptr inbounds i8, i8* %44, i64 %42
store i8 -1, i8* %45
%46 = add nuw nsw i64 %42, 1
%47 = add i64 %43, 1
%48 = icmp eq i64 %47, 3
br i1 %48, label %49, label %41
49: ; preds = %41, %12
ret i32 0
}