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

/* Variables and functions */
scalar_t__ CL_SUCCESS;
int /*<<< orphan*/ CL_TRUE;
scalar_t__ clEnqueueWriteBuffer(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/, size_t,
                                char *, int /*<<< orphan*/,
                                int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(char *, int, size_t);
int /*<<< orphan*/ printf(char *, ...);
void clMemSet(cl_command_queue clCommandQueue, cl_mem buf, int val,
              size_t size) {
  cl_int clStatus;
  char *temp = (char *)malloc(size);
  memset(temp, val, size);
  clStatus = clEnqueueWriteBuffer(clCommandQueue, buf, CL_TRUE, 0, size, temp,
                                  0, NULL, NULL);
  if (clStatus != CL_SUCCESS) {
    printf("Error: %s!\n", "clEnqueueWriteBuffer");
    printf("Line: %d\n", 47);
    exit(1);
  }
  free(temp);
}


x86 assembly (clang, -O0):
<clMemSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%r8
mov    -0x28(%rbp),%r9
xor    %ecx,%ecx
xor    %eax,%eax
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1080 <clEnqueueWriteBuffer@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2dfe(%rip),%rcx
cmp    (%rcx),%rax
je     1215 <clMemSet+0xb5>
lea    0xe16(%rip),%rdi
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe22(%rip),%rdi
mov    $0x2f,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clMemSet>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %esi,%r15d
mov    %edi,%r12d
mov    %rcx,%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %r12d,%edi
mov    %r15d,%esi
xor    %ecx,%ecx
mov    %rbx,%r8
mov    %r14,%r9
call   1080 <clEnqueueWriteBuffer@plt>
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%rax
jne    11da <clMemSet+0x7a>
mov    %r14,%rdi
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xe1f(%rip),%rdi
lea    0xe24(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe2b(%rip),%rdi
mov    $0x2f,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@CL_TRUE = global i32 0
@CL_SUCCESS = global i64 0
@.str = [12 x i8] c"Error: %s!\0A\00"
@.str.1 = [21 x i8] c"clEnqueueWriteBuffer\00"
@.str.2 = [10 x i8] c"Line: %d\0A\00"
define void @clMemSet(i32 %0, i32 %1, i32 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i64 %3, i64* %8
%11 = load i64, i64* %8
%12 = call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %10
%14 = load i8*, i8** %10
%15 = load i32, i32* %7
%16 = load i64, i64* %8
%17 = call i32 @memset(i8* %14, i32 %15, i64 %16)
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = load i32, i32* @CL_TRUE
%21 = load i64, i64* %8
%22 = load i8*, i8** %10
%23 = call i64 @clEnqueueWriteBuffer(i32 %18, i32 %19, i32 %20, i32 0, i64 %21, i8* %22, i32 0, i32* null, i32* null)
store i64 %23, i64* %9
%24 = load i64, i64* %9
%25 = load i64, i64* @CL_SUCCESS
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 47)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %4
%32 = load i8*, i8** %10
%33 = call i32 @free(i8* %32)
ret void
}

LLVM IR (-O2):
@CL_TRUE = global i32 0
@CL_SUCCESS = global i64 0
@.str = [12 x i8] c"Error: %s!\0A\00"
@.str.1 = [21 x i8] c"clEnqueueWriteBuffer\00"
@.str.2 = [10 x i8] c"Line: %d\0A\00"
define void @clMemSet(i32 %0, i32 %1, i32 %2, i64 %3) {
%5 = tail call i64 @malloc(i64 %3)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @memset(i8* %6, i32 %2, i64 %3)
%8 = load i32, i32* @CL_TRUE
%9 = tail call i64 @clEnqueueWriteBuffer(i32 %0, i32 %1, i32 %8, i32 0, i64 %3, i8* %6, i32 0, i32* null, i32* null)
%10 = load i64, i64* @CL_SUCCESS
%11 = icmp eq i64 %9, %10
br i1 %11, label %16, label %12
12: ; preds = %4
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 47)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %4
%17 = tail call i32 @free(i8* %6)
ret void
}