#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int, size_t);
void allocateImageData(size_t width, unsigned char **state,
                       unsigned char **img_buff) {
  *state = (char *)malloc(sizeof(char) * width + 3);
  *img_buff = (char *)malloc(sizeof(char) * width * 3 + 1);
  memset(*state, 0, width + 3);
  memset(*img_buff, 255, width * 3);
}


x86 assembly (clang, -O0):
<allocateImageData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x0,%rax
add    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
shl    $0x0,%rax
imul   $0x3,%rax,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rdx
add    $0x3,%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
imul   $0x3,-0x8(%rbp),%rdx
mov    $0xff,%esi
call   1030 <memset@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocateImageData>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x3(%rdi),%r12
mov    %r12d,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15)
lea    (%rbx,%rbx,2),%rbx
lea    0x1(%rbx),%edi
call   1040 <malloc@plt>
mov    %rax,(%r14)
mov    (%r15),%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1030 <memset@plt>
mov    (%r14),%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <memset@plt>

LLVM IR (-O0):
define void @allocateImageData(i64 %0, i8** %1, i8** %2) {
%4 = alloca i64
%5 = alloca i8**
%6 = alloca i8**
store i64 %0, i64* %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%7 = load i64, i64* %4
%8 = mul i64 1, %7
%9 = add i64 %8, 3
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = load i8**, i8*** %5
store i8* %12, i8** %13
%14 = load i64, i64* %4
%15 = mul i64 1, %14
%16 = mul i64 %15, 3
%17 = add i64 %16, 1
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
%21 = load i8**, i8*** %6
store i8* %20, i8** %21
%22 = load i8**, i8*** %5
%23 = load i8*, i8** %22
%24 = load i64, i64* %4
%25 = add i64 %24, 3
%26 = call i32 @memset(i8* %23, i32 0, i64 %25)
%27 = load i8**, i8*** %6
%28 = load i8*, i8** %27
%29 = load i64, i64* %4
%30 = mul i64 %29, 3
%31 = call i32 @memset(i8* %28, i32 255, i64 %30)
ret void
}

LLVM IR (-O2):
define void @allocateImageData(i64 %0, i8** nocapture %1, i8** nocapture %2) {
%4 = add i64 %0, 3
%5 = trunc i64 %4 to i32
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %1
%8 = mul i64 %0, 3
%9 = trunc i64 %8 to i32
%10 = add i32 %9, 1
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %2
%13 = load i8*, i8** %1
%14 = tail call i32 @memset(i8* %13, i32 0, i64 %4)
%15 = load i8*, i8** %2
%16 = tail call i32 @memset(i8* %15, i32 255, i64 %8)
ret void
}