#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*/ assert(int /*<<< orphan*/);
void **queue_ptr(struct queue *);
int /*<<< orphan*/ queue_push_close(struct queue *, int);
int queue_push_open(struct queue *);
int queue_push_ptr(struct queue *q, void *v) {
  assert(v != NULL);
  int tail = queue_push_open(q);
  if (tail < 0)
    return 1;
  void **data = queue_ptr(q);
  data[tail] = v;
  queue_push_close(q, tail);
  return 0;
}


x86 assembly (clang, -O0):
<queue_push_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1060 <queue_push_open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1184 <queue_push_ptr+0x44>
movl   $0x1,-0x4(%rbp)
jmp    11b4 <queue_push_ptr+0x74>
mov    -0x10(%rbp),%rdi
call   1030 <queue_ptr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <queue_push_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<queue_push_ptr>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1060 <queue_push_open@plt>
test   %eax,%eax
js     1182 <queue_push_ptr+0x42>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <queue_ptr@plt>
mov    %ebp,%ecx
mov    %r14,(%rax,%rcx,8)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <queue_push_close@plt>
xor    %eax,%eax
jmp    1187 <queue_push_ptr+0x47>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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