#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ addbyte(int);
int /*<<< orphan*/ addlong(int);
int /*<<< orphan*/ addword(int);
int TEST_HOST_REG_IMM(int host_reg, uint32_t imm) {
  if (host_reg & 8) {
    addbyte(0x44);
    addbyte(0x89);
    addbyte(0xc0 | 2 | ((host_reg & 7) << 3));
    host_reg = 2 | (host_reg & 0x10);
  }
  if (host_reg & 0x10) {
    addbyte(0x66);
    addbyte(0x81);
    addbyte(0xe0 | (host_reg & 7));
    addword((imm << 8) | 0xff);
  } else {
    addbyte(0x81);
    addbyte(0xe0 | (host_reg & 7));
    addlong(imm);
  }
  return host_reg;
}


x86 assembly (clang, -O0):
<TEST_HOST_REG_IMM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1181 <TEST_HOST_REG_IMM+0x51>
mov    $0x44,%edi
call   1050 <addbyte@plt>
mov    $0x89,%edi
call   1050 <addbyte@plt>
mov    -0x4(%rbp),%edi
and    $0x7,%edi
shl    $0x3,%edi
or     $0xc2,%edi
call   1050 <addbyte@plt>
mov    -0x4(%rbp),%eax
and    $0x10,%eax
or     $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     11cb <TEST_HOST_REG_IMM+0x9b>
mov    $0x66,%edi
call   1050 <addbyte@plt>
mov    $0x81,%edi
call   1050 <addbyte@plt>
mov    -0x4(%rbp),%edi
and    $0x7,%edi
or     $0xe0,%edi
call   1050 <addbyte@plt>
mov    -0x8(%rbp),%edi
shl    $0x8,%edi
or     $0xff,%edi
call   1030 <addword@plt>
jmp    11ee <TEST_HOST_REG_IMM+0xbe>
mov    $0x81,%edi
call   1050 <addbyte@plt>
mov    -0x4(%rbp),%edi
and    $0x7,%edi
or     $0xe0,%edi
call   1050 <addbyte@plt>
mov    -0x8(%rbp),%edi
call   1040 <addlong@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TEST_HOST_REG_IMM>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
test   $0x8,%bl
je     116a <TEST_HOST_REG_IMM+0x3a>
mov    $0x44,%edi
call   1050 <addbyte@plt>
mov    $0x89,%edi
call   1050 <addbyte@plt>
lea    0x0(,%rbx,8),%eax
or     $0xc2,%eax
movzbl %al,%edi
call   1050 <addbyte@plt>
and    $0x10,%ebx
or     $0x2,%ebx
test   $0x10,%bl
jne    1192 <TEST_HOST_REG_IMM+0x62>
mov    $0x81,%edi
call   1050 <addbyte@plt>
mov    %ebx,%edi
and    $0x7,%edi
or     $0xe0,%edi
call   1050 <addbyte@plt>
mov    %ebp,%edi
call   1040 <addlong@plt>
jmp    11c6 <TEST_HOST_REG_IMM+0x96>
mov    $0x66,%edi
call   1050 <addbyte@plt>
mov    $0x81,%edi
call   1050 <addbyte@plt>
mov    %ebx,%edi
and    $0x7,%edi
or     $0xe0,%edi
call   1050 <addbyte@plt>
shl    $0x8,%ebp
or     $0xff,%ebp
mov    %ebp,%edi
call   1030 <addword@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @TEST_HOST_REG_IMM(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = and i32 %5, 8
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = call i32 @addbyte(i32 68)
%10 = call i32 @addbyte(i32 137)
%11 = load i32, i32* %3
%12 = and i32 %11, 7
%13 = shl i32 %12, 3
%14 = or i32 194, %13
%15 = call i32 @addbyte(i32 %14)
%16 = load i32, i32* %3
%17 = and i32 %16, 16
%18 = or i32 2, %17
store i32 %18, i32* %3
br label %19
19: ; preds = %8, %2
%20 = load i32, i32* %3
%21 = and i32 %20, 16
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = call i32 @addbyte(i32 102)
%25 = call i32 @addbyte(i32 129)
%26 = load i32, i32* %3
%27 = and i32 %26, 7
%28 = or i32 224, %27
%29 = call i32 @addbyte(i32 %28)
%30 = load i32, i32* %4
%31 = shl i32 %30, 8
%32 = or i32 %31, 255
%33 = call i32 @addword(i32 %32)
br label %42
34: ; preds = %19
%35 = call i32 @addbyte(i32 129)
%36 = load i32, i32* %3
%37 = and i32 %36, 7
%38 = or i32 224, %37
%39 = call i32 @addbyte(i32 %38)
%40 = load i32, i32* %4
%41 = call i32 @addlong(i32 %40)
br label %42
42: ; preds = %34, %23
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
define i32 @TEST_HOST_REG_IMM(i32 %0, i32 %1) {
%3 = and i32 %0, 8
%4 = icmp eq i32 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i32 @addbyte(i32 68)
%7 = tail call i32 @addbyte(i32 137)
%8 = shl i32 %0, 3
%9 = and i32 %8, 56
%10 = or i32 %9, 194
%11 = tail call i32 @addbyte(i32 %10)
%12 = and i32 %0, 16
%13 = or i32 %12, 2
br label %14
14: ; preds = %5, %2
%15 = phi i32 [ %13, %5 ], [ %0, %2 ]
%16 = and i32 %15, 16
%17 = icmp eq i32 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %14
%19 = tail call i32 @addbyte(i32 102)
%20 = tail call i32 @addbyte(i32 129)
%21 = and i32 %15, 7
%22 = or i32 %21, 224
%23 = tail call i32 @addbyte(i32 %22)
%24 = shl i32 %1, 8
%25 = or i32 %24, 255
%26 = tail call i32 @addword(i32 %25)
br label %33
27: ; preds = %14
%28 = tail call i32 @addbyte(i32 129)
%29 = and i32 %15, 7
%30 = or i32 %29, 224
%31 = tail call i32 @addbyte(i32 %30)
%32 = tail call i32 @addlong(i32 %1)
br label %33
33: ; preds = %27, %18
ret i32 %15
}