void low_sign_unext(x, len, result) unsigned int x, len;
unsigned int *result;
{
  unsigned int temp;
  unsigned int sign;
  unsigned int rest;
  unsigned int one_bit_at_len;
  unsigned int len_ones;
  len_ones = ones(len);
  one_bit_at_len = 1 << (len - 1);
  sign_unext(x, len, &temp);
  sign = temp & one_bit_at_len;
  sign >>= (len - 1);
  rest = temp & (len_ones ^ one_bit_at_len);
  rest <<= 1;
  *result = rest | sign;
}


x86 assembly (clang, -O0):
<low_sign_unext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x0,%al
call   1030 <ones@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1040 <sign_unext@plt>
mov    -0x14(%rbp),%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%eax
shr    %cl,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x24(%rbp),%ecx
xor    -0x20(%rbp),%ecx
and    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
or     -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<low_sign_unext>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r13d
mov    %edi,%r15d
mov    %esi,%edi
xor    %eax,%eax
call   1030 <ones@plt>
mov    %eax,%ebp
lea    -0x1(%r13),%r12d
mov    $0x1,%ebx
mov    %r12d,%ecx
shl    %cl,%ebx
lea    0x4(%rsp),%rdx
mov    %r15d,%edi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <sign_unext@plt>
mov    0x4(%rsp),%eax
and    %eax,%ebx
mov    %r12d,%ecx
shr    %cl,%ebx
btc    %r12d,%ebp
and    %eax,%ebp
add    %ebp,%ebp
or     %ebx,%ebp
mov    %ebp,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @low_sign_unext(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%12 = load i32, i32* %5
%13 = call i32 (i32, ...) bitcast (i32 (...)* @ones to i32 (i32, ...)*)(i32 %12)
store i32 %13, i32* %11
%14 = load i32, i32* %5
%15 = sub i32 %14, 1
%16 = shl i32 1, %15
store i32 %16, i32* %10
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @sign_unext to i32 (i32, i32, i32*, ...)*)(i32 %17, i32 %18, i32* %7)
%20 = load i32, i32* %7
%21 = load i32, i32* %10
%22 = and i32 %20, %21
store i32 %22, i32* %8
%23 = load i32, i32* %5
%24 = sub i32 %23, 1
%25 = load i32, i32* %8
%26 = lshr i32 %25, %24
store i32 %26, i32* %8
%27 = load i32, i32* %7
%28 = load i32, i32* %11
%29 = load i32, i32* %10
%30 = xor i32 %28, %29
%31 = and i32 %27, %30
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = shl i32 %32, 1
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = load i32, i32* %8
%36 = or i32 %34, %35
%37 = load i32*, i32** %6
store i32 %36, i32* %37
ret void
}

LLVM IR (-O2):
define void @low_sign_unext(i32 %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @ones to i32 (i32, ...)*)(i32 %1)
%7 = add i32 %1, -1
%8 = shl nuw i32 1, %7
%9 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @sign_unext to i32 (i32, i32, i32*, ...)*)(i32 %0, i32 %1, i32* %4)
%10 = load i32, i32* %4
%11 = and i32 %10, %8
%12 = lshr i32 %11, %7
%13 = xor i32 %6, %8
%14 = and i32 %10, %13
%15 = shl i32 %14, 1
%16 = or i32 %15, %12
store i32 %16, i32* %2
ret void
}