void movsx_reg32_m16abs(int reg32, unsigned short *m16) {
  if ((long)m16 & 0xFFFFFFFF80000000LL) {
    printf("Error: destination %lx not in lower 2GB for movsx_reg32_m16abs()\n",
           (long)m16);
    asm(" int $3; ");
  }
  put8(0x0F);
  put8(0xBF);
  put8((reg32 << 3) | 4);
  put8(0x25);
  put32((int)(unsigned long)m16);
}


x86 assembly (clang, -O0):
<movsx_reg32_m16abs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0xffffffff80000000,%rax
cmp    $0x0,%rax
je     1166 <movsx_reg32_m16abs+0x36>
mov    -0x10(%rbp),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
int3
mov    $0xf,%edi
mov    $0x0,%al
call   1030 <put8@plt>
mov    $0xbf,%edi
mov    $0x0,%al
call   1030 <put8@plt>
mov    -0x4(%rbp),%edi
shl    $0x3,%edi
or     $0x4,%edi
mov    $0x0,%al
call   1030 <put8@plt>
mov    $0x25,%edi
mov    $0x0,%al
call   1030 <put8@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%edi
mov    $0x0,%al
call   1050 <put32@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<movsx_reg32_m16abs>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r14d
test   $0xffffffff80000000,%rsi
je     1155 <movsx_reg32_m16abs+0x25>
lea    0xeb6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
int3
mov    $0xf,%edi
xor    %eax,%eax
call   1030 <put8@plt>
mov    $0xbf,%edi
xor    %eax,%eax
call   1030 <put8@plt>
lea    0x4(,%r14,8),%edi
xor    %eax,%eax
call   1030 <put8@plt>
mov    $0x25,%edi
xor    %eax,%eax
call   1030 <put8@plt>
mov    %ebx,%edi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <put32@plt>

LLVM IR (-O0):
@.str = [66 x i8] c"Error: destination %lx not in lower 2GB for movsx_reg32_m16abs()\0A\00"
define void @movsx_reg32_m16abs(i32 %0, i16* %1) {
%3 = alloca i32
%4 = alloca i16*
store i32 %0, i32* %3
store i16* %1, i16** %4
%5 = load i16*, i16** %4
%6 = ptrtoint i16* %5 to i64
%7 = and i64 %6, -2147483648
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i16*, i16** %4
%11 = ptrtoint i16* %10 to i64
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i64 %11)
br label %13
13: ; preds = %9, %2
%14 = call i32 (i32, ...) bitcast (i32 (...)* @put8 to i32 (i32, ...)*)(i32 15)
%15 = call i32 (i32, ...) bitcast (i32 (...)* @put8 to i32 (i32, ...)*)(i32 191)
%16 = load i32, i32* %3
%17 = shl i32 %16, 3
%18 = or i32 %17, 4
%19 = call i32 (i32, ...) bitcast (i32 (...)* @put8 to i32 (i32, ...)*)(i32 %18)
%20 = call i32 (i32, ...) bitcast (i32 (...)* @put8 to i32 (i32, ...)*)(i32 37)
%21 = load i16*, i16** %4
%22 = ptrtoint i16* %21 to i64
%23 = trunc i64 %22 to i32
%24 = call i32 (i32, ...) bitcast (i32 (...)* @put32 to i32 (i32, ...)*)(i32 %23)
ret void
}

LLVM IR (-O2):
@.str = [66 x i8] c"Error: destination %lx not in lower 2GB for movsx_reg32_m16abs()\0A\00"
define void @movsx_reg32_m16abs(i32 %0, i16* %1) {
%3 = ptrtoint i16* %1 to i64
%4 = icmp ult i16* %1, inttoptr (i64 2147483648 to i16*)
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i64 %3)
tail call void asm sideeffect " int $$3; ", "~{dirflag},~{fpsr},~{flags}"()
br label %7
7: ; preds = %5, %2
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @put8 to i32 (i32, ...)*)(i32 15)
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @put8 to i32 (i32, ...)*)(i32 191)
%10 = shl i32 %0, 3
%11 = or i32 %10, 4
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @put8 to i32 (i32, ...)*)(i32 %11)
%13 = tail call i32 (i32, ...) bitcast (i32 (...)* @put8 to i32 (i32, ...)*)(i32 37)
%14 = trunc i64 %3 to i32
%15 = tail call i32 (i32, ...) bitcast (i32 (...)* @put32 to i32 (i32, ...)*)(i32 %14)
ret void
}