#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 *queue_int(struct queue *);
int /*<<< orphan*/ queue_pop_close(struct queue *, int);
int queue_pop_open(struct queue *);
int queue_pop_int(struct queue *q) {
  int head = queue_pop_open(q);
  if (head < 0)
    return 0;
  int *data = queue_int(q);
  int v = data[head];
  queue_pop_close(q, head);
  return v;
}


x86 assembly (clang, -O0):
<queue_pop_int>:
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    115e <queue_pop_int+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    118b <queue_pop_int+0x5b>
mov    -0x10(%rbp),%rdi
call   1030 <queue_int@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <queue_pop_close@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.queue = type { i32 }
define i32 @queue_pop_int(%struct.queue* %0) {
%2 = alloca i32
%3 = alloca %struct.queue*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
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 i32 0, i32* %2
br label %24
12: ; preds = %1
%13 = load %struct.queue*, %struct.queue** %3
%14 = call i32* @queue_int(%struct.queue* %13)
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
store i32 %19, i32* %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 i32, i32* %6
store i32 %23, i32* %2
br label %24
24: ; preds = %12, %11
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
%struct.queue = type { i32 }
define i32 @queue_pop_int(%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 i32* @queue_int(%struct.queue* %0)
%6 = zext i32 %2 to i64
%7 = getelementptr inbounds i32, i32* %5, i64 %6
%8 = load i32, i32* %7
%9 = tail call i32 @queue_pop_close(%struct.queue* %0, i32 %2)
br label %10
10: ; preds = %1, %4
%11 = phi i32 [ %8, %4 ], [ 0, %1 ]
ret i32 %11
}