#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_andimm(int, int, int);
int /*<<< orphan*/ emit_movzbl_dualindexedx4(int, int, int);
int /*<<< orphan*/ emit_orimm(int, int, int);
int /*<<< orphan*/ emit_orreq_imm(int, int, int);
int /*<<< orphan*/ emit_testimm(int, int);
int /*<<< orphan*/ emit_writebyte_dualindexedx4(int, int, int);
void emit_sh2tas(int addr, int map, int sr) {
  if (map < 0) {
    assert(map >= 0);
  } else {
    emit_movzbl_dualindexedx4(addr, map, 14);
    emit_andimm(sr, ~1, sr);
    emit_testimm(14, 0xff);
    emit_orimm(14, 0x80, 14);
    emit_orreq_imm(sr, 1, sr);
    emit_writebyte_dualindexedx4(14, addr, map);
  }
}


x86 assembly (clang, -O0):
<emit_sh2tas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a1 <emit_sh2tas+0x31>
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
jmp    1201 <emit_sh2tas+0x91>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0xe,%edx
call   1030 <emit_movzbl_dualindexedx4@plt>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    $0xfffffffe,%esi
call   1080 <emit_andimm@plt>
mov    $0xe,%edi
mov    $0xff,%esi
call   1050 <emit_testimm@plt>
mov    $0xe,%edx
mov    $0x80,%esi
mov    %edx,%edi
call   1090 <emit_orimm@plt>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    $0x1,%esi
call   1070 <emit_orreq_imm@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    $0xe,%edi
call   1060 <emit_writebyte_dualindexedx4@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emit_sh2tas>:
test   %esi,%esi
js     11db <emit_sh2tas+0x6b>
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r14d
mov    $0xe,%edx
call   1030 <emit_movzbl_dualindexedx4@plt>
mov    %ebp,%edi
mov    $0xfffffffe,%esi
mov    %ebp,%edx
call   1080 <emit_andimm@plt>
mov    $0xe,%edi
mov    $0xff,%esi
call   1050 <emit_testimm@plt>
mov    $0xe,%edi
mov    $0x80,%esi
mov    $0xe,%edx
call   1090 <emit_orimm@plt>
mov    %ebp,%edi
mov    $0x1,%esi
mov    %ebp,%edx
call   1070 <emit_orreq_imm@plt>
mov    $0xe,%edi
mov    %r14d,%esi
mov    %ebx,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <emit_writebyte_dualindexedx4@plt>
xor    %edi,%edi
jmp    1040 <assert@plt>

LLVM IR (-O0):
define void @emit_sh2tas(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i32, i32* %5
%11 = icmp sge i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
br label %29
14: ; preds = %3
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 @emit_movzbl_dualindexedx4(i32 %15, i32 %16, i32 14)
%18 = load i32, i32* %6
%19 = load i32, i32* %6
%20 = call i32 @emit_andimm(i32 %18, i32 -2, i32 %19)
%21 = call i32 @emit_testimm(i32 14, i32 255)
%22 = call i32 @emit_orimm(i32 14, i32 128, i32 14)
%23 = load i32, i32* %6
%24 = load i32, i32* %6
%25 = call i32 @emit_orreq_imm(i32 %23, i32 1, i32 %24)
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = call i32 @emit_writebyte_dualindexedx4(i32 14, i32 %26, i32 %27)
br label %29
29: ; preds = %14, %9
ret void
}

LLVM IR (-O2):
define void @emit_sh2tas(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @assert(i32 0)
br label %14
7: ; preds = %3
%8 = tail call i32 @emit_movzbl_dualindexedx4(i32 %0, i32 %1, i32 14)
%9 = tail call i32 @emit_andimm(i32 %2, i32 -2, i32 %2)
%10 = tail call i32 @emit_testimm(i32 14, i32 255)
%11 = tail call i32 @emit_orimm(i32 14, i32 128, i32 14)
%12 = tail call i32 @emit_orreq_imm(i32 %2, i32 1, i32 %2)
%13 = tail call i32 @emit_writebyte_dualindexedx4(i32 14, i32 %0, i32 %1)
br label %14
14: ; preds = %7, %5
ret void
}