#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 */
struct opencl_command_t {
  int dummy;
};
struct _cl_command_queue {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ opencl_command_free(struct opencl_command_t *);
struct opencl_command_t *
opencl_command_queue_dequeue(struct _cl_command_queue *);
int /*<<< orphan*/ opencl_command_run(struct opencl_command_t *);
void *opencl_command_queue_thread_func(void *user_data) {
  struct _cl_command_queue *command_queue = user_data;
  struct opencl_command_t *command;
  for (;;) {
    command = opencl_command_queue_dequeue(command_queue);
    if (!command)
      break;
    opencl_command_run(command);
    opencl_command_free(command);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<opencl_command_queue_thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <opencl_command_queue_dequeue@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1161 <opencl_command_queue_thread_func+0x31>
jmp    1178 <opencl_command_queue_thread_func+0x48>
mov    -0x18(%rbp),%rdi
call   1030 <opencl_command_run@plt>
mov    -0x18(%rbp),%rdi
call   1040 <opencl_command_free@plt>
jmp    1144 <opencl_command_queue_thread_func+0x14>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opencl_command_queue_thread_func>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <opencl_command_queue_dequeue@plt>
test   %rax,%rax
je     1170 <opencl_command_queue_thread_func+0x40>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <opencl_command_run@plt>
mov    %rbx,%rdi
call   1040 <opencl_command_free@plt>
mov    %r14,%rdi
call   1050 <opencl_command_queue_dequeue@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1150 <opencl_command_queue_thread_func+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct._cl_command_queue = type { i32 }
%struct.opencl_command_t = type { i32 }
define i8* @opencl_command_queue_thread_func(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct._cl_command_queue*
%4 = alloca %struct.opencl_command_t*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to %struct._cl_command_queue*
store %struct._cl_command_queue* %6, %struct._cl_command_queue** %3
br label %7
7: ; preds = %13, %1
%8 = load %struct._cl_command_queue*, %struct._cl_command_queue** %3
%9 = call %struct.opencl_command_t* @opencl_command_queue_dequeue(%struct._cl_command_queue* %8)
store %struct.opencl_command_t* %9, %struct.opencl_command_t** %4
%10 = load %struct.opencl_command_t*, %struct.opencl_command_t** %4
%11 = icmp ne %struct.opencl_command_t* %10, null
br i1 %11, label %13, label %12
12: ; preds = %7
br label %18
13: ; preds = %7
%14 = load %struct.opencl_command_t*, %struct.opencl_command_t** %4
%15 = call i32 @opencl_command_run(%struct.opencl_command_t* %14)
%16 = load %struct.opencl_command_t*, %struct.opencl_command_t** %4
%17 = call i32 @opencl_command_free(%struct.opencl_command_t* %16)
br label %7
18: ; preds = %12
ret i8* null
}

LLVM IR (-O2):
%struct._cl_command_queue = type { i32 }
%struct.opencl_command_t = type { i32 }
define noalias i8* @opencl_command_queue_thread_func(i8* %0) {
%2 = bitcast i8* %0 to %struct._cl_command_queue*
%3 = tail call %struct.opencl_command_t* @opencl_command_queue_dequeue(%struct._cl_command_queue* %2)
%4 = icmp eq %struct.opencl_command_t* %3, null
br i1 %4, label %11, label %5
5: ; preds = %1, %5
%6 = phi %struct.opencl_command_t* [ %9, %5 ], [ %3, %1 ]
%7 = tail call i32 @opencl_command_run(%struct.opencl_command_t* %6)
%8 = tail call i32 @opencl_command_free(%struct.opencl_command_t* %6)
%9 = tail call %struct.opencl_command_t* @opencl_command_queue_dequeue(%struct._cl_command_queue* %2)
%10 = icmp eq %struct.opencl_command_t* %9, null
br i1 %10, label %11, label %5
11: ; preds = %5, %1
ret i8* null
}