#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ emit_cmovl_imm(int, int);
int /*<<< orphan*/ emit_cmovne_imm(int /*<<< orphan*/, int);
int /*<<< orphan*/ emit_cmovs_imm(int, int);
int /*<<< orphan*/ emit_cmpimm(int, int);
int /*<<< orphan*/ emit_slti32(int, int, int);
int /*<<< orphan*/ emit_test(int, int);
void emit_slti64_32(int rsh, int rsl, int imm, int rt) {
  assert(rsh != rt);
  emit_slti32(rsl, imm, rt);
  if (imm >= 0) {
    emit_test(rsh, rsh);
    emit_cmovne_imm(0, rt);
    emit_cmovs_imm(1, rt);
  } else {
    emit_cmpimm(rsh, -1);
    emit_cmovne_imm(0, rt);
    emit_cmovl_imm(1, rt);
  }
}


x86 assembly (clang, -O0):
<emit_slti64_32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x10(%rbp),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <emit_slti32@plt>
cmpl   $0x0,-0xc(%rbp)
jl     11d6 <emit_slti64_32+0x66>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1090 <emit_test@plt>
mov    -0x10(%rbp),%esi
xor    %edi,%edi
call   1080 <emit_cmovne_imm@plt>
mov    -0x10(%rbp),%esi
mov    $0x1,%edi
call   1060 <emit_cmovs_imm@plt>
jmp    11fa <emit_slti64_32+0x8a>
mov    -0x4(%rbp),%edi
mov    $0xffffffff,%esi
call   1040 <emit_cmpimm@plt>
mov    -0x10(%rbp),%esi
xor    %edi,%edi
call   1080 <emit_cmovne_imm@plt>
mov    -0x10(%rbp),%esi
mov    $0x1,%edi
call   1070 <emit_cmovl_imm@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emit_slti64_32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%r15d
mov    %edi,%ebp
xor    %edi,%edi
cmp    %ecx,%ebp
setne  %dil
call   1050 <assert@plt>
mov    %r15d,%edi
mov    %ebx,%esi
mov    %r14d,%edx
call   1030 <emit_slti32@plt>
test   %ebx,%ebx
js     11c9 <emit_slti64_32+0x59>
mov    %ebp,%edi
mov    %ebp,%esi
call   1090 <emit_test@plt>
xor    %edi,%edi
mov    %r14d,%esi
call   1080 <emit_cmovne_imm@plt>
mov    $0x1,%edi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <emit_cmovs_imm@plt>
mov    %ebp,%edi
mov    $0xffffffff,%esi
call   1040 <emit_cmpimm@plt>
xor    %edi,%edi
mov    %r14d,%esi
call   1080 <emit_cmovne_imm@plt>
mov    $0x1,%edi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <emit_cmovl_imm@plt>

LLVM IR (-O0):
define void @emit_slti64_32(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %5
%10 = load i32, i32* %8
%11 = icmp ne i32 %9, %10
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = call i32 @emit_slti32(i32 %14, i32 %15, i32 %16)
%18 = load i32, i32* %7
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %4
%21 = load i32, i32* %5
%22 = load i32, i32* %5
%23 = call i32 @emit_test(i32 %21, i32 %22)
%24 = load i32, i32* %8
%25 = call i32 @emit_cmovne_imm(i32 0, i32 %24)
%26 = load i32, i32* %8
%27 = call i32 @emit_cmovs_imm(i32 1, i32 %26)
br label %35
28: ; preds = %4
%29 = load i32, i32* %5
%30 = call i32 @emit_cmpimm(i32 %29, i32 -1)
%31 = load i32, i32* %8
%32 = call i32 @emit_cmovne_imm(i32 0, i32 %31)
%33 = load i32, i32* %8
%34 = call i32 @emit_cmovl_imm(i32 1, i32 %33)
br label %35
35: ; preds = %28, %20
ret void
}

LLVM IR (-O2):
define void @emit_slti64_32(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp ne i32 %0, %3
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32 @emit_slti32(i32 %1, i32 %2, i32 %3)
%9 = icmp sgt i32 %2, -1
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = tail call i32 @emit_test(i32 %0, i32 %0)
%12 = tail call i32 @emit_cmovne_imm(i32 0, i32 %3)
%13 = tail call i32 @emit_cmovs_imm(i32 1, i32 %3)
br label %18
14: ; preds = %4
%15 = tail call i32 @emit_cmpimm(i32 %0, i32 -1)
%16 = tail call i32 @emit_cmovne_imm(i32 0, i32 %3)
%17 = tail call i32 @emit_cmovl_imm(i32 1, i32 %3)
br label %18
18: ; preds = %14, %10
ret void
}