#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*/ size_elem;
typedef int /*<<< orphan*/ cl_mem_flags;
typedef int /*<<< orphan*/ cl_mem;
typedef int /*<<< orphan*/ cl_int;
typedef int /*<<< orphan*/ cl_context;
typedef int /*<<< orphan*/ cl_command_queue;

/* Variables and functions */
int /*<<< orphan*/ CL_TRUE;
int /*<<< orphan*/ clCreateBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                                  size_t, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ *);
void *clEnqueueMapBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/, int /*<<< orphan*/,
                         int /*<<< orphan*/, size_t, int /*<<< orphan*/,
                         int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ oclCheckStatus(int /*<<< orphan*/, char *);
void *oclCreateMapBuffer(cl_context context, cl_command_queue queue,
                         cl_mem_flags create_flags, cl_mem_flags map_flags,
                         size_t size_elem, size_t nb_elem, cl_mem *buffer) {
  cl_int status;
  size_t size = sizeof(size_elem) * nb_elem;
  cl_mem b = clCreateBuffer(context, create_flags, size, NULL, &status);
  oclCheckStatus(status, "clCreateBuffer failed.");
  *buffer = b;
  void *p = clEnqueueMapBuffer(queue, b, CL_TRUE, map_flags, 0, size, 0, NULL,
                               NULL, &status);
  oclCheckStatus(status, "clEnqueueMapBuffer failed.");
  return p;
}


x86 assembly (clang, -O0):
<oclCreateMapBuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x30(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x24(%rbp),%r8
call   1030 <clCreateBuffer@plt>
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%edi
lea    0xe80(%rip),%rsi
call   1040 <oclCheckStatus@plt>
mov    -0x34(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%ecx
mov    -0x30(%rbp),%r9
xor    %r8d,%r8d
xor    %eax,%eax
lea    -0x24(%rbp),%rax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1050 <clEnqueueMapBuffer@plt>
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%edi
lea    0xe39(%rip),%rsi
call   1040 <oclCheckStatus@plt>
mov    -0x40(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oclCreateMapBuffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%rbx
mov    %ecx,%r14d
mov    %esi,%r12d
mov    0x60(%rsp),%r13
shl    $0x3,%rbx
lea    0x24(%rsp),%r15
mov    %edx,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
mov    %r15,%r8
call   1030 <clCreateBuffer@plt>
mov    %eax,%ebp
mov    0x24(%rsp),%edi
lea    0xe8f(%rip),%rsi
call   1040 <oclCheckStatus@plt>
mov    %ebp,0x0(%r13)
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
mov    %r15,0x18(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %r12d,%edi
mov    %ebp,%esi
mov    %r14d,%ecx
xor    %r8d,%r8d
mov    %rbx,%r9
call   1050 <clEnqueueMapBuffer@plt>
mov    %rax,%rbx
mov    0x24(%rsp),%edi
lea    0xe5f(%rip),%rsi
call   1040 <oclCheckStatus@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"clCreateBuffer failed.\00"
@CL_TRUE = global i32 0
@.str.1 = [27 x i8] c"clEnqueueMapBuffer failed.\00"
define i8* @oclCreateMapBuffer(i32 %0, i32 %1, i32 %2, i32 %3, i64 %4, i64 %5, i32* %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i64
%17 = alloca i32
%18 = alloca i8*
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i64 %4, i64* %12
store i64 %5, i64* %13
store i32* %6, i32** %14
%19 = load i64, i64* %13
%20 = mul i64 8, %19
store i64 %20, i64* %16
%21 = load i32, i32* %8
%22 = load i32, i32* %10
%23 = load i64, i64* %16
%24 = call i32 @clCreateBuffer(i32 %21, i32 %22, i64 %23, i32* null, i32* %15)
store i32 %24, i32* %17
%25 = load i32, i32* %15
%26 = call i32 @oclCheckStatus(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* %17
%28 = load i32*, i32** %14
store i32 %27, i32* %28
%29 = load i32, i32* %9
%30 = load i32, i32* %17
%31 = load i32, i32* @CL_TRUE
%32 = load i32, i32* %11
%33 = load i64, i64* %16
%34 = call i8* @clEnqueueMapBuffer(i32 %29, i32 %30, i32 %31, i32 %32, i32 0, i64 %33, i32 0, i32* null, i32* null, i32* %15)
store i8* %34, i8** %18
%35 = load i32, i32* %15
%36 = call i32 @oclCheckStatus(i32 %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%37 = load i8*, i8** %18
ret i8* %37
}

LLVM IR (-O2):
@.str = [23 x i8] c"clCreateBuffer failed.\00"
@CL_TRUE = global i32 0
@.str.1 = [27 x i8] c"clEnqueueMapBuffer failed.\00"
define i8* @oclCreateMapBuffer(i32 %0, i32 %1, i32 %2, i32 %3, i64 %4, i64 %5, i32* nocapture writeonly %6) {
%8 = alloca i32
%9 = bitcast i32* %8 to i8*
%10 = shl i64 %5, 3
%11 = call i32 @clCreateBuffer(i32 %0, i32 %2, i64 %10, i32* null, i32* %8)
%12 = load i32, i32* %8
%13 = call i32 @oclCheckStatus(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %6
%14 = load i32, i32* @CL_TRUE
%15 = call i8* @clEnqueueMapBuffer(i32 %1, i32 %11, i32 %14, i32 %3, i32 0, i64 %10, i32 0, i32* null, i32* null, i32* %8)
%16 = load i32, i32* %8
%17 = call i32 @oclCheckStatus(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
ret i8* %15
}