#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_cmovne_imm(int, int);
int /*<<< orphan*/ emit_cmpimm(int, int);
int /*<<< orphan*/ emit_sltiu32(int, int, int);
int /*<<< orphan*/ emit_test(int, int);
void emit_sltiu64_32(int rsh, int rsl, int imm, int rt) {
  assert(rsh != rt);
  emit_sltiu32(rsl, imm, rt);
  if (imm >= 0) {
    emit_test(rsh, rsh);
    emit_cmovne_imm(0, rt);
  } else {
    emit_cmpimm(rsh, -1);
    emit_cmovne_imm(1, rt);
  }
}


x86 assembly (clang, -O0):
<emit_sltiu64_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_sltiu32@plt>
cmpl   $0x0,-0xc(%rbp)
jl     11a9 <emit_sltiu64_32+0x59>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1070 <emit_test@plt>
mov    -0x10(%rbp),%esi
xor    %edi,%edi
call   1060 <emit_cmovne_imm@plt>
jmp    11c3 <emit_sltiu64_32+0x73>
mov    -0x4(%rbp),%edi
mov    $0xffffffff,%esi
call   1040 <emit_cmpimm@plt>
mov    -0x10(%rbp),%esi
mov    $0x1,%edi
call   1060 <emit_cmovne_imm@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emit_sltiu64_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_sltiu32@plt>
test   %ebx,%ebx
js     118c <emit_sltiu64_32+0x3c>
mov    %ebp,%edi
mov    %ebp,%esi
call   1070 <emit_test@plt>
xor    %edi,%edi
jmp    119d <emit_sltiu64_32+0x4d>
mov    %ebp,%edi
mov    $0xffffffff,%esi
call   1040 <emit_cmpimm@plt>
mov    $0x1,%edi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <emit_cmovne_imm@plt>

LLVM IR (-O0):
define void @emit_sltiu64_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_sltiu32(i32 %14, i32 %15, i32 %16)
%18 = load i32, i32* %7
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %26
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)
br label %31
26: ; preds = %4
%27 = load i32, i32* %5
%28 = call i32 @emit_cmpimm(i32 %27, i32 -1)
%29 = load i32, i32* %8
%30 = call i32 @emit_cmovne_imm(i32 1, i32 %29)
br label %31
31: ; preds = %26, %20
ret void
}

LLVM IR (-O2):
define void @emit_sltiu64_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_sltiu32(i32 %1, i32 %2, i32 %3)
%9 = icmp sgt i32 %2, -1
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @emit_test(i32 %0, i32 %0)
br label %14
12: ; preds = %4
%13 = tail call i32 @emit_cmpimm(i32 %0, i32 -1)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ 1, %12 ], [ 0, %10 ]
%16 = tail call i32 @emit_cmovne_imm(i32 %15, i32 %3)
ret void
}