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

/* Variables and functions */
int /*<<< orphan*/ clReleaseCommandQueue(int /*<<< orphan*/ *);
int /*<<< orphan*/ clReleaseContext(int /*<<< orphan*/ *);
void cl_utils_cleanup_gpu(cl_context *context,
                          cl_command_queue *command_queue) {
  if (*command_queue != NULL) {
    clReleaseCommandQueue(*command_queue);
    *command_queue = NULL;
  }
  if (*context != NULL) {
    clReleaseContext(*context);
    *context = NULL;
  }
}


x86 assembly (clang, -O0):
<cl_utils_cleanup_gpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1155 <cl_utils_cleanup_gpu+0x35>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <clReleaseCommandQueue@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     117a <cl_utils_cleanup_gpu+0x5a>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <clReleaseContext@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cl_utils_cleanup_gpu>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rsi),%rdi
test   %rdi,%rdi
je     113e <cl_utils_cleanup_gpu+0x1e>
mov    %rsi,%rbx
call   1030 <clReleaseCommandQueue@plt>
movq   $0x0,(%rbx)
mov    (%r14),%rdi
test   %rdi,%rdi
je     1152 <cl_utils_cleanup_gpu+0x32>
call   1040 <clReleaseContext@plt>
movq   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @cl_utils_cleanup_gpu(i32** %0, i32** %1) {
%3 = alloca i32**
%4 = alloca i32**
store i32** %0, i32*** %3
store i32** %1, i32*** %4
%5 = load i32**, i32*** %4
%6 = load i32*, i32** %5
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32**, i32*** %4
%10 = load i32*, i32** %9
%11 = call i32 @clReleaseCommandQueue(i32* %10)
%12 = load i32**, i32*** %4
store i32* null, i32** %12
br label %13
13: ; preds = %8, %2
%14 = load i32**, i32*** %3
%15 = load i32*, i32** %14
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32**, i32*** %3
%19 = load i32*, i32** %18
%20 = call i32 @clReleaseContext(i32* %19)
%21 = load i32**, i32*** %3
store i32* null, i32** %21
br label %22
22: ; preds = %17, %13
ret void
}

LLVM IR (-O2):
define void @cl_utils_cleanup_gpu(i32** nocapture %0, i32** nocapture %1) {
%3 = load i32*, i32** %1
%4 = icmp eq i32* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @clReleaseCommandQueue(i32* %3)
store i32* null, i32** %1
br label %7
7: ; preds = %5, %2
%8 = load i32*, i32** %0
%9 = icmp eq i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @clReleaseContext(i32* %8)
store i32* null, i32** %0
br label %12
12: ; preds = %10, %7
ret void
}