#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 queue {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ queue_pop_close(struct queue *, int);
int queue_pop_open(struct queue *);
void **queue_ptr(struct queue *);
void *queue_pop_ptr(struct queue *q) {
  int head = queue_pop_open(q);
  if (head < 0)
    return NULL;
  void **data = queue_ptr(q);
  void *v = data[head];
  queue_pop_close(q, head);
  return v;
}


x86 assembly (clang, -O0):
<queue_pop_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <queue_pop_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    115f <queue_pop_ptr+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    1190 <queue_pop_ptr+0x60>
mov    -0x10(%rbp),%rdi
call   1030 <queue_ptr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <queue_pop_close@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<queue_pop_ptr>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <queue_pop_open@plt>
test   %eax,%eax
js     115c <queue_pop_ptr+0x2c>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <queue_ptr@plt>
mov    %ebp,%ecx
mov    (%rax,%rcx,8),%r14
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <queue_pop_close@plt>
jmp    115f <queue_pop_ptr+0x2f>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.queue = type { i32 }
define i8* @queue_pop_ptr(%struct.queue* %0) {
%2 = alloca i8*
%3 = alloca %struct.queue*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store %struct.queue* %0, %struct.queue** %3
%7 = load %struct.queue*, %struct.queue** %3
%8 = call i32 @queue_pop_open(%struct.queue* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %24
12: ; preds = %1
%13 = load %struct.queue*, %struct.queue** %3
%14 = call i8** @queue_ptr(%struct.queue* %13)
store i8** %14, i8*** %5
%15 = load i8**, i8*** %5
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
store i8* %19, i8** %6
%20 = load %struct.queue*, %struct.queue** %3
%21 = load i32, i32* %4
%22 = call i32 @queue_pop_close(%struct.queue* %20, i32 %21)
%23 = load i8*, i8** %6
store i8* %23, i8** %2
br label %24
24: ; preds = %12, %11
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
%struct.queue = type { i32 }
define i8* @queue_pop_ptr(%struct.queue* %0) {
%2 = tail call i32 @queue_pop_open(%struct.queue* %0)
%3 = icmp slt i32 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call i8** @queue_ptr(%struct.queue* %0)
%6 = zext i32 %2 to i64
%7 = getelementptr inbounds i8*, i8** %5, i64 %6
%8 = load i8*, i8** %7
%9 = tail call i32 @queue_pop_close(%struct.queue* %0, i32 %2)
br label %10
10: ; preds = %1, %4
%11 = phi i8* [ %8, %4 ], [ null, %1 ]
ret i8* %11
}