#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 cl_uint;
typedef int /*<<< orphan*/ cl_program;
typedef uintptr_t cl_mem;
typedef int /*<<< orphan*/ cl_kernel;
typedef scalar_t__ cl_int;
typedef int /*<<< orphan*/ cl_device_id;
typedef int /*<<< orphan*/ cl_context;
typedef int /*<<< orphan*/ cl_command_queue;

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_ADDRESS_BITS;
scalar_t__ CL_SUCCESS;
uintptr_t _clIndexedQueue_create_32(int /*<<< orphan*/, int /*<<< orphan*/);
uintptr_t _clIndexedQueue_create_64(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ clCreateKernel(int /*<<< orphan*/, char *, scalar_t__ *);
scalar_t__ clEnqueueNDRangeKernel(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                  uintptr_t, size_t const *, uintptr_t,
                                  int /*<<< orphan*/, uintptr_t, uintptr_t);
scalar_t__ clFinish(int /*<<< orphan*/);
scalar_t__ clGetDeviceInfo(int /*<<< orphan*/, int /*<<< orphan*/, int, int *,
                           uintptr_t);
int /*<<< orphan*/ clReleaseKernel(int /*<<< orphan*/);
int /*<<< orphan*/ clSetKernelArg(int /*<<< orphan*/, int, int, ...);
int /*<<< orphan*/ printf(char *, ...);
cl_mem clIndexedQueue_create(cl_device_id dev, cl_context ctx,
                             cl_command_queue cq, cl_program prg, cl_mem base,
                             cl_uint stride_l2) {
  cl_int error;
  cl_uint bits;
  cl_mem q;
  cl_kernel kernel;
  const size_t threads = 1;
  error = clGetDeviceInfo(dev, CL_DEVICE_ADDRESS_BITS, sizeof(cl_uint), &bits,
                          (uintptr_t)0);
  if (error) {
    printf("clIndexedQueue: could not discover device address space\n");
    return (uintptr_t)0;
  }
  if (bits == 32) {
    q = _clIndexedQueue_create_32(ctx, cq);
  } else {
    q = _clIndexedQueue_create_64(ctx, cq);
  }
  if (!q)
    return (uintptr_t)0;
  kernel = clCreateKernel(prg, "clIndexedQueue_init", &error);
  if (error != CL_SUCCESS) {
    printf("clIndexedQueue: Could not create queue init kernel: %i\n", error);
    return (uintptr_t)0;
  }
  clSetKernelArg(kernel, 0, sizeof(cl_mem), &q);
  clSetKernelArg(kernel, 1, sizeof(cl_mem), &base);
  clSetKernelArg(kernel, 2, sizeof(cl_uint), &stride_l2);
  clSetKernelArg(kernel, 3, sizeof(cl_mem), &base);
  error = clEnqueueNDRangeKernel(cq, kernel, 1, (uintptr_t)0, &threads,
                                 (uintptr_t)0, 0, (uintptr_t)0, (uintptr_t)0);
  if (error != CL_SUCCESS) {
    printf("clIndexedQueue: Could not execute queue init kernel: %i\n", error);
    return (uintptr_t)0;
  }
  error = clFinish(cq);
  if (error != CL_SUCCESS) {
    printf("clIndexedQueue: Could not execute queue init kernel: %i\n", error);
    return (uintptr_t)0;
  }
  clReleaseKernel(kernel);
  return q;
}


x86 assembly (clang, -O0):
<clIndexedQueue_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movq   $0x1,-0x50(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%edx
lea    -0x34(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <clGetDeviceInfo@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11fd <clIndexedQueue_create+0x6d>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13a5 <clIndexedQueue_create+0x215>
cmpl   $0x20,-0x34(%rbp)
jne    121b <clIndexedQueue_create+0x8b>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <_clIndexedQueue_create_32@plt>
mov    %rax,-0x40(%rbp)
jmp    122a <clIndexedQueue_create+0x9a>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1080 <_clIndexedQueue_create_64@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1242 <clIndexedQueue_create+0xb2>
movq   $0x0,-0x8(%rbp)
jmp    13a5 <clIndexedQueue_create+0x215>
mov    -0x18(%rbp),%edi
lea    0xded(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   10a0 <clCreateKernel@plt>
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2d75(%rip),%rcx
cmp    (%rcx),%rax
je     128b <clIndexedQueue_create+0xfb>
mov    -0x30(%rbp),%rsi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13a5 <clIndexedQueue_create+0x215>
mov    -0x44(%rbp),%edi
xor    %esi,%esi
mov    $0x8,%edx
lea    -0x40(%rbp),%rcx
mov    $0x0,%al
call   10b0 <clSetKernelArg@plt>
mov    -0x44(%rbp),%edi
mov    $0x1,%esi
mov    $0x8,%edx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   10b0 <clSetKernelArg@plt>
mov    -0x44(%rbp),%edi
mov    $0x2,%esi
mov    $0x4,%edx
lea    -0x24(%rbp),%rcx
mov    $0x0,%al
call   10b0 <clSetKernelArg@plt>
mov    -0x44(%rbp),%edi
mov    $0x3,%esi
mov    $0x8,%edx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   10b0 <clSetKernelArg@plt>
mov    -0x14(%rbp),%edi
mov    -0x44(%rbp),%esi
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%r9d
lea    -0x50(%rbp),%r8
xor    %eax,%eax
mov    %r9,%rcx
movl   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1060 <clEnqueueNDRangeKernel@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2caa(%rip),%rcx
cmp    (%rcx),%rax
je     1356 <clIndexedQueue_create+0x1c6>
mov    -0x30(%rbp),%rsi
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13a5 <clIndexedQueue_create+0x215>
mov    -0x14(%rbp),%edi
call   1030 <clFinish@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2c6b(%rip),%rcx
cmp    (%rcx),%rax
je     1395 <clIndexedQueue_create+0x205>
mov    -0x30(%rbp),%rsi
lea    0xd04(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13a5 <clIndexedQueue_create+0x215>
mov    -0x44(%rbp),%edi
call   1040 <clReleaseKernel@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clIndexedQueue_create>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %esi,%ebx
mov    %r8,0x40(%rsp)
mov    %r9d,0x2c(%rsp)
movq   $0x1,0x38(%rsp)
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
lea    0x28(%rsp),%rcx
mov    $0x4,%edx
xor    %r8d,%r8d
call   1060 <clGetDeviceInfo@plt>
mov    %rax,0x20(%rsp)
test   %rax,%rax
je     11fc <clIndexedQueue_create+0x5c>
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    1323 <clIndexedQueue_create+0x183>
cmpl   $0x20,0x28(%rsp)
jne    120f <clIndexedQueue_create+0x6f>
mov    %ebx,%edi
mov    %r14d,%esi
call   10a0 <_clIndexedQueue_create_32@plt>
jmp    1219 <clIndexedQueue_create+0x79>
mov    %ebx,%edi
mov    %r14d,%esi
call   1090 <_clIndexedQueue_create_64@plt>
mov    %rax,0x30(%rsp)
test   %rax,%rax
je     1301 <clIndexedQueue_create+0x161>
lea    0xdd2(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %ebp,%edi
call   10b0 <clCreateKernel@plt>
mov    0x20(%rsp),%rsi
mov    0x2d92(%rip),%r15
cmp    (%r15),%rsi
jne    1305 <clIndexedQueue_create+0x165>
mov    %eax,%ebp
lea    0x30(%rsp),%rcx
mov    %eax,%edi
xor    %esi,%esi
mov    $0x8,%edx
xor    %eax,%eax
call   10c0 <clSetKernelArg@plt>
lea    0x40(%rsp),%rbx
mov    %ebp,%edi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   10c0 <clSetKernelArg@plt>
lea    0x2c(%rsp),%rcx
mov    %ebp,%edi
mov    $0x2,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   10c0 <clSetKernelArg@plt>
mov    %ebp,%edi
mov    $0x3,%esi
mov    $0x8,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   10c0 <clSetKernelArg@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movl   $0x0,(%rsp)
lea    0x38(%rsp),%r8
mov    %r14d,%edi
mov    %ebp,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r9d,%r9d
call   1070 <clEnqueueNDRangeKernel@plt>
mov    %rax,0x20(%rsp)
cmp    (%r15),%rax
jne    1310 <clIndexedQueue_create+0x170>
mov    %r14d,%edi
call   1030 <clFinish@plt>
mov    %rax,0x20(%rsp)
cmp    (%r15),%rax
jne    1310 <clIndexedQueue_create+0x170>
mov    %ebp,%edi
call   1050 <clReleaseKernel@plt>
mov    0x30(%rsp),%rbx
jmp    1323 <clIndexedQueue_create+0x183>
xor    %ebx,%ebx
jmp    1323 <clIndexedQueue_create+0x183>
lea    0xd08(%rip),%rdi
xor    %ebx,%ebx
jmp    131c <clIndexedQueue_create+0x17c>
lea    0xd35(%rip),%rdi
xor    %ebx,%ebx
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CL_DEVICE_ADDRESS_BITS = global i32 0
@.str = [57 x i8] c"clIndexedQueue: could not discover device address space\0A\00"
@.str.1 = [20 x i8] c"clIndexedQueue_init\00"
@CL_SUCCESS = global i64 0
@.str.2 = [56 x i8] c"clIndexedQueue: Could not create queue init kernel: %i\0A\00"
@.str.3 = [57 x i8] c"clIndexedQueue: Could not execute queue init kernel: %i\0A\00"
define i64 @clIndexedQueue_create(i32 %0, i32 %1, i32 %2, i32 %3, i64 %4, i32 %5) {
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i32
%14 = alloca i64
%15 = alloca i32
%16 = alloca i64
%17 = alloca i32
%18 = alloca i64
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 i32 %5, i32* %13
store i64 1, i64* %18
%19 = load i32, i32* %8
%20 = load i32, i32* @CL_DEVICE_ADDRESS_BITS
%21 = call i64 @clGetDeviceInfo(i32 %19, i32 %20, i32 4, i32* %15, i64 0)
store i64 %21, i64* %14
%22 = load i64, i64* %14
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %7
br label %81
26: ; preds = %6
%27 = load i32, i32* %15
%28 = icmp eq i32 %27, 32
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = call i64 @_clIndexedQueue_create_32(i32 %30, i32 %31)
store i64 %32, i64* %16
br label %37
33: ; preds = %26
%34 = load i32, i32* %9
%35 = load i32, i32* %10
%36 = call i64 @_clIndexedQueue_create_64(i32 %34, i32 %35)
store i64 %36, i64* %16
br label %37
37: ; preds = %33, %29
%38 = load i64, i64* %16
%39 = icmp ne i64 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %37
store i64 0, i64* %7
br label %81
41: ; preds = %37
%42 = load i32, i32* %11
%43 = call i32 @clCreateKernel(i32 %42, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64* %14)
store i32 %43, i32* %17
%44 = load i64, i64* %14
%45 = load i64, i64* @CL_SUCCESS
%46 = icmp ne i64 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %41
%48 = load i64, i64* %14
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i64 %48)
store i64 0, i64* %7
br label %81
50: ; preds = %41
%51 = load i32, i32* %17
%52 = call i32 (i32, i32, i32, ...) @clSetKernelArg(i32 %51, i32 0, i32 8, i64* %16)
%53 = load i32, i32* %17
%54 = call i32 (i32, i32, i32, ...) @clSetKernelArg(i32 %53, i32 1, i32 8, i64* %12)
%55 = load i32, i32* %17
%56 = call i32 (i32, i32, i32, ...) @clSetKernelArg(i32 %55, i32 2, i32 4, i32* %13)
%57 = load i32, i32* %17
%58 = call i32 (i32, i32, i32, ...) @clSetKernelArg(i32 %57, i32 3, i32 8, i64* %12)
%59 = load i32, i32* %10
%60 = load i32, i32* %17
%61 = call i64 @clEnqueueNDRangeKernel(i32 %59, i32 %60, i32 1, i64 0, i64* %18, i64 0, i32 0, i64 0, i64 0)
store i64 %61, i64* %14
%62 = load i64, i64* %14
%63 = load i64, i64* @CL_SUCCESS
%64 = icmp ne i64 %62, %63
br i1 %64, label %65, label %68
65: ; preds = %50
%66 = load i64, i64* %14
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i64 %66)
store i64 0, i64* %7
br label %81
68: ; preds = %50
%69 = load i32, i32* %10
%70 = call i64 @clFinish(i32 %69)
store i64 %70, i64* %14
%71 = load i64, i64* %14
%72 = load i64, i64* @CL_SUCCESS
%73 = icmp ne i64 %71, %72
br i1 %73, label %74, label %77
74: ; preds = %68
%75 = load i64, i64* %14
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i64 %75)
store i64 0, i64* %7
br label %81
77: ; preds = %68
%78 = load i32, i32* %17
%79 = call i32 @clReleaseKernel(i32 %78)
%80 = load i64, i64* %16
store i64 %80, i64* %7
br label %81
81: ; preds = %77, %74, %65, %47, %40, %24
%82 = load i64, i64* %7
ret i64 %82
}

LLVM IR (-O2):
@CL_DEVICE_ADDRESS_BITS = global i32 0
@.str.1 = [20 x i8] c"clIndexedQueue_init\00"
@CL_SUCCESS = global i64 0
@.str.2 = [56 x i8] c"clIndexedQueue: Could not create queue init kernel: %i\0A\00"
@.str.3 = [57 x i8] c"clIndexedQueue: Could not execute queue init kernel: %i\0A\00"
@str = [56 x i8] c"clIndexedQueue: could not discover device address space\00"
define i64 @clIndexedQueue_create(i32 %0, i32 %1, i32 %2, i32 %3, i64 %4, i32 %5) {
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
store i64 %4, i64* %7
store i32 %5, i32* %8
%13 = bitcast i64* %9 to i8*
%14 = bitcast i32* %10 to i8*
%15 = bitcast i64* %11 to i8*
%16 = bitcast i64* %12 to i8*
store i64 1, i64* %12
%17 = load i32, i32* @CL_DEVICE_ADDRESS_BITS
%18 = call i64 @clGetDeviceInfo(i32 %0, i32 %17, i32 4, i32* %10, i64 0)
store i64 %18, i64* %9
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %6
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
br label %58
22: ; preds = %6
%23 = load i32, i32* %10
%24 = icmp eq i32 %23, 32
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i64 @_clIndexedQueue_create_32(i32 %1, i32 %2)
br label %29
27: ; preds = %22
%28 = call i64 @_clIndexedQueue_create_64(i32 %1, i32 %2)
br label %29
29: ; preds = %27, %25
%30 = phi i64 [ %28, %27 ], [ %26, %25 ]
store i64 %30, i64* %11
%31 = icmp eq i64 %30, 0
br i1 %31, label %58, label %32
32: ; preds = %29
%33 = call i32 @clCreateKernel(i32 %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64* %9)
%34 = load i64, i64* %9
%35 = load i64, i64* @CL_SUCCESS
%36 = icmp eq i64 %34, %35
br i1 %36, label %39, label %37
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i64 %34)
br label %58
39: ; preds = %32
%40 = call i32 (i32, i32, i32, ...) @clSetKernelArg(i32 %33, i32 0, i32 8, i64* %11)
%41 = call i32 (i32, i32, i32, ...) @clSetKernelArg(i32 %33, i32 1, i32 8, i64* %7)
%42 = call i32 (i32, i32, i32, ...) @clSetKernelArg(i32 %33, i32 2, i32 4, i32* %8)
%43 = call i32 (i32, i32, i32, ...) @clSetKernelArg(i32 %33, i32 3, i32 8, i64* %7)
%44 = call i64 @clEnqueueNDRangeKernel(i32 %2, i32 %33, i32 1, i64 0, i64* %12, i64 0, i32 0, i64 0, i64 0)
store i64 %44, i64* %9
%45 = load i64, i64* @CL_SUCCESS
%46 = icmp eq i64 %44, %45
br i1 %46, label %49, label %47
47: ; preds = %39
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i64 %44)
br label %58
49: ; preds = %39
%50 = call i64 @clFinish(i32 %2)
store i64 %50, i64* %9
%51 = load i64, i64* @CL_SUCCESS
%52 = icmp eq i64 %50, %51
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i64 %50)
br label %58
55: ; preds = %49
%56 = call i32 @clReleaseKernel(i32 %33)
%57 = load i64, i64* %11
br label %58
58: ; preds = %29, %55, %53, %47, %37, %20
%59 = phi i64 [ 0, %20 ], [ 0, %37 ], [ 0, %47 ], [ 0, %53 ], [ %57, %55 ], [ 0, %29 ]
ret i64 %59
}