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

/* Variables and functions */
scalar_t__ stack_empty(unsigned int);
struct tst_expr_tok *stack_pop(struct tst_expr_tok *stack[],
                               unsigned int *op_stack_pos) {
  if (stack_empty(*op_stack_pos))
    return NULL;
  return stack[--(*op_stack_pos)];
}


x86 assembly (clang, -O0):
<stack_pop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <stack_empty@plt>
cmp    $0x0,%rax
je     1142 <stack_pop+0x32>
movq   $0x0,-0x8(%rbp)
jmp    115b <stack_pop+0x4b>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rdx
mov    (%rdx),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rdx)
mov    %ecx,%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stack_pop>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%edi
call   1030 <stack_empty@plt>
test   %rax,%rax
je     112a <stack_pop+0x1a>
xor    %eax,%eax
jmp    1135 <stack_pop+0x25>
mov    (%rbx),%eax
add    $0xffffffff,%eax
mov    %eax,(%rbx)
mov    (%r14,%rax,8),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tst_expr_tok = type { i32 }
define %struct.tst_expr_tok* @stack_pop(%struct.tst_expr_tok** %0, i32* %1) {
%3 = alloca %struct.tst_expr_tok*
%4 = alloca %struct.tst_expr_tok**
%5 = alloca i32*
store %struct.tst_expr_tok** %0, %struct.tst_expr_tok*** %4
store i32* %1, i32** %5
%6 = load i32*, i32** %5
%7 = load i32, i32* %6
%8 = call i64 @stack_empty(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store %struct.tst_expr_tok* null, %struct.tst_expr_tok** %3
br label %19
11: ; preds = %2
%12 = load %struct.tst_expr_tok**, %struct.tst_expr_tok*** %4
%13 = load i32*, i32** %5
%14 = load i32, i32* %13
%15 = add i32 %14, -1
store i32 %15, i32* %13
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds %struct.tst_expr_tok*, %struct.tst_expr_tok** %12, i64 %16
%18 = load %struct.tst_expr_tok*, %struct.tst_expr_tok** %17
store %struct.tst_expr_tok* %18, %struct.tst_expr_tok** %3
br label %19
19: ; preds = %11, %10
%20 = load %struct.tst_expr_tok*, %struct.tst_expr_tok** %3
ret %struct.tst_expr_tok* %20
}

LLVM IR (-O2):
%struct.tst_expr_tok = type { i32 }
define %struct.tst_expr_tok* @stack_pop(%struct.tst_expr_tok** nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = tail call i64 @stack_empty(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* %1
%8 = add i32 %7, -1
store i32 %8, i32* %1
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds %struct.tst_expr_tok*, %struct.tst_expr_tok** %0, i64 %9
%11 = load %struct.tst_expr_tok*, %struct.tst_expr_tok** %10
br label %12
12: ; preds = %2, %6
%13 = phi %struct.tst_expr_tok* [ %11, %6 ], [ null, %2 ]
ret %struct.tst_expr_tok* %13
}