#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 packet {
  int dummy;
};
struct llist_head {
  int dummy;
};

/* Variables and functions */
scalar_t__ llist_get_value_at_index(struct llist_head *, struct packet **,
                                    int /*<<< orphan*/);
int /*<<< orphan*/ llist_remove_index(struct llist_head **, int /*<<< orphan*/);
struct packet *packetqueue_pull(struct llist_head **queue) {
  struct packet *packet;
  if (llist_get_value_at_index(*queue, &packet, 0)) {
    return NULL;
  }
  llist_remove_index(queue, 0);
  return packet;
}


x86 assembly (clang, -O0):
<packetqueue_pull>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <llist_get_value_at_index@plt>
cmp    $0x0,%rax
je     1155 <packetqueue_pull+0x35>
movq   $0x0,-0x8(%rbp)
jmp    1168 <packetqueue_pull+0x48>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <llist_remove_index@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packetqueue_pull>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%rdi
mov    %rsp,%rsi
xor    %r14d,%r14d
xor    %edx,%edx
call   1030 <llist_get_value_at_index@plt>
test   %rax,%rax
jne    114a <packetqueue_pull+0x2a>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <llist_remove_index@plt>
mov    (%rsp),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.packet = type { i32 }
%struct.llist_head = type { i32 }
define %struct.packet* @packetqueue_pull(%struct.llist_head** %0) {
%2 = alloca %struct.packet*
%3 = alloca %struct.llist_head**
%4 = alloca %struct.packet*
store %struct.llist_head** %0, %struct.llist_head*** %3
%5 = load %struct.llist_head**, %struct.llist_head*** %3
%6 = load %struct.llist_head*, %struct.llist_head** %5
%7 = call i64 @llist_get_value_at_index(%struct.llist_head* %6, %struct.packet** %4, i32 0)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store %struct.packet* null, %struct.packet** %2
br label %14
10: ; preds = %1
%11 = load %struct.llist_head**, %struct.llist_head*** %3
%12 = call i32 @llist_remove_index(%struct.llist_head** %11, i32 0)
%13 = load %struct.packet*, %struct.packet** %4
store %struct.packet* %13, %struct.packet** %2
br label %14
14: ; preds = %10, %9
%15 = load %struct.packet*, %struct.packet** %2
ret %struct.packet* %15
}

LLVM IR (-O2):
%struct.packet = type { i32 }
%struct.llist_head = type { i32 }
define %struct.packet* @packetqueue_pull(%struct.llist_head** %0) {
%2 = alloca %struct.packet*
%3 = bitcast %struct.packet** %2 to i8*
%4 = load %struct.llist_head*, %struct.llist_head** %0
%5 = call i64 @llist_get_value_at_index(%struct.llist_head* %4, %struct.packet** %2, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @llist_remove_index(%struct.llist_head** %0, i32 0)
%9 = load %struct.packet*, %struct.packet** %2
br label %10
10: ; preds = %1, %7
%11 = phi %struct.packet* [ %9, %7 ], [ null, %1 ]
ret %struct.packet* %11
}