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

/* Variables and functions */
long pop_to_long();
int /*<<< orphan*/ push_nil();
int /*<<< orphan*/ push_t();
void builtin_eq(struct Context *ctx, unsigned int stack_track) {
  if (stack_track == 0) {
    push_nil();
    return;
  }
  if (stack_track == 1) {
    push_t();
    return;
  }
  unsigned int result = 1;
  long previous = pop_to_long(), current;
  for (stack_track--; stack_track; stack_track--) {
    current = pop_to_long();
    if (previous != current)
      result = 0;
    previous = current;
  }
  if (result)
    push_t();
  else
    push_nil();
}


x86 assembly (clang, -O0):
<builtin_eq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1155 <builtin_eq+0x25>
mov    $0x0,%al
call   1050 <push_nil@plt>
jmp    11e3 <builtin_eq+0xb3>
cmpl   $0x1,-0xc(%rbp)
jne    116b <builtin_eq+0x3b>
mov    $0x0,%al
call   1040 <push_t@plt>
jmp    11e3 <builtin_eq+0xb3>
movl   $0x1,-0x10(%rbp)
mov    $0x0,%al
call   1030 <pop_to_long@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11c6 <builtin_eq+0x96>
mov    $0x0,%al
call   1030 <pop_to_long@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11b0 <builtin_eq+0x80>
movl   $0x0,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1186 <builtin_eq+0x56>
cmpl   $0x0,-0x10(%rbp)
je     11dc <builtin_eq+0xac>
mov    $0x0,%al
call   1040 <push_t@plt>
jmp    11e3 <builtin_eq+0xb3>
mov    $0x0,%al
call   1050 <push_nil@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_eq>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%esi
je     117a <builtin_eq+0x4a>
mov    %esi,%ebx
test   %esi,%esi
je     118b <builtin_eq+0x5b>
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <pop_to_long@plt>
mov    %rax,%r14
add    $0xffffffff,%ebx
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <pop_to_long@plt>
cmp    %rax,%r14
cmovne %r15d,%ebp
mov    %rax,%r14
add    $0xffffffff,%ebx
jne    1160 <builtin_eq+0x30>
test   %ebp,%ebp
je     118b <builtin_eq+0x5b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <push_t@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <push_nil@plt>

LLVM IR (-O0):
%struct.Context = type { i32 }
define void @builtin_eq(%struct.Context* %0, i32 %1) {
%3 = alloca %struct.Context*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store %struct.Context* %0, %struct.Context** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (...) @push_nil()
br label %42
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (...) @push_t()
br label %42
17: ; preds = %12
store i32 1, i32* %5
%18 = call i64 (...) @pop_to_long()
store i64 %18, i64* %6
%19 = load i32, i32* %4
%20 = add i32 %19, -1
store i32 %20, i32* %4
br label %21
21: ; preds = %32, %17
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %21
%25 = call i64 (...) @pop_to_long()
store i64 %25, i64* %7
%26 = load i64, i64* %6
%27 = load i64, i64* %7
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 0, i32* %5
br label %30
30: ; preds = %29, %24
%31 = load i64, i64* %7
store i64 %31, i64* %6
br label %32
32: ; preds = %30
%33 = load i32, i32* %4
%34 = add i32 %33, -1
store i32 %34, i32* %4
br label %21
35: ; preds = %21
%36 = load i32, i32* %5
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 (...) @push_t()
br label %42
40: ; preds = %35
%41 = call i32 (...) @push_nil()
br label %42
42: ; preds = %10, %15, %40, %38
ret void
}

LLVM IR (-O2):
%struct.Context = type { i32 }
define void @builtin_eq(%struct.Context* nocapture readnone %0, i32 %1) {
switch i32 %1, label %7 [
i32 0, label %3
i32 1, label %5
]
3: ; preds = %2
%4 = tail call i32 (...) @push_nil()
br label %25
5: ; preds = %2
%6 = tail call i32 (...) @push_t()
br label %25
7: ; preds = %2
%8 = tail call i64 (...) @pop_to_long()
%9 = add i32 %1, -1
br label %10
10: ; preds = %7, %10
%11 = phi i32 [ %17, %10 ], [ %9, %7 ]
%12 = phi i64 [ %14, %10 ], [ %8, %7 ]
%13 = phi i32 [ %16, %10 ], [ 1, %7 ]
%14 = tail call i64 (...) @pop_to_long()
%15 = icmp eq i64 %12, %14
%16 = select i1 %15, i32 %13, i32 0
%17 = add i32 %11, -1
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %10
19: ; preds = %10
%20 = icmp eq i32 %16, 0
br i1 %20, label %23, label %21
21: ; preds = %19
%22 = tail call i32 (...) @push_t()
br label %25
23: ; preds = %19
%24 = tail call i32 (...) @push_nil()
br label %25
25: ; preds = %21, %23, %5, %3
ret void
}