#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
uint16_t widen(uint8_t n) {
  unsigned int i;
  uint16_t r = 0;
  for (i = 0; i < 8; i++) {
    r <<= 2;
    if (n & 0x80)
      r |= 0x03;
    n <<= 1;
  }
  return r;
}


x86 assembly (clang, -O0):
<widen>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jae    1159 <widen+0x59>
mov    -0xc(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1142 <widen+0x42>
mov    -0xc(%rbp),%eax
or     $0x3,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1115 <widen+0x15>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<widen>:
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeef(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xef3(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%ecx
xor    %eax,%eax
test   $0x80,%cl
mov    $0xc000,%edx
cmovne %eax,%edx
lea    0x3000(%rdx),%eax
test   $0x40,%cl
cmovne %edx,%eax
lea    0xc00(%rax),%edx
test   $0x20,%cl
cmovne %eax,%edx
lea    0x300(%rdx),%eax
test   $0x10,%cl
cmovne %edx,%eax
mov    %eax,%edx
or     $0xc0,%edx
test   $0x8,%cl
cmovne %eax,%edx
mov    %edx,%eax
or     $0x30,%eax
test   $0x4,%cl
cmovne %edx,%eax
mov    %eax,%edx
or     $0xc,%edx
test   $0x2,%cl
cmovne %eax,%edx
mov    %edx,%eax
or     $0x3,%eax
test   $0x1,%cl
cmovne %edx,%eax
ret

LLVM IR (-O0):
define i32 @widen(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %20, %1
%6 = load i32, i32* %3
%7 = icmp ult i32 %6, 8
br i1 %7, label %8, label %23
8: ; preds = %5
%9 = load i32, i32* %4
%10 = shl i32 %9, 2
store i32 %10, i32* %4
%11 = load i32, i32* %2
%12 = and i32 %11, 128
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i32, i32* %4
%16 = or i32 %15, 3
store i32 %16, i32* %4
br label %17
17: ; preds = %14, %8
%18 = load i32, i32* %2
%19 = shl i32 %18, 1
store i32 %19, i32* %2
br label %20
20: ; preds = %17
%21 = load i32, i32* %3
%22 = add i32 %21, 1
store i32 %22, i32* %3
br label %5
23: ; preds = %5
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
define i32 @widen(i32 %0) {
%2 = insertelement <8 x i32> poison, i32 %0, i64 0
%3 = shufflevector <8 x i32> %2, <8 x i32> poison, <8 x i32> zeroinitializer
%4 = and <8 x i32> %3, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128>
%5 = icmp eq <8 x i32> %4, zeroinitializer
%6 = extractelement <8 x i1> %5, i64 7
%7 = select i1 %6, i32 0, i32 49152
%8 = or i32 %7, 12288
%9 = extractelement <8 x i1> %5, i64 6
%10 = select i1 %9, i32 %7, i32 %8
%11 = or i32 %10, 3072
%12 = extractelement <8 x i1> %5, i64 5
%13 = select i1 %12, i32 %10, i32 %11
%14 = or i32 %13, 768
%15 = extractelement <8 x i1> %5, i64 4
%16 = select i1 %15, i32 %13, i32 %14
%17 = or i32 %16, 192
%18 = extractelement <8 x i1> %5, i64 3
%19 = select i1 %18, i32 %16, i32 %17
%20 = or i32 %19, 48
%21 = extractelement <8 x i1> %5, i64 2
%22 = select i1 %21, i32 %19, i32 %20
%23 = or i32 %22, 12
%24 = extractelement <8 x i1> %5, i64 1
%25 = select i1 %24, i32 %22, i32 %23
%26 = or i32 %25, 3
%27 = extractelement <8 x i1> %5, i64 0
%28 = select i1 %27, i32 %25, i32 %26
ret i32 %28
}