#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 /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ shl(int /*<<< orphan*/, int);
int /*<<< orphan*/ shr_arith(int /*<<< orphan*/, int);
int64_t bitpack_gets(uint64_t vec, unsigned lsb, unsigned width) {
  assert(lsb < 64);
  assert(width <= 64);
  assert(width + lsb <= 64);
  return (int64_t)shr_arith(shl(vec, 64 - (lsb + width)), 64 - width);
}


x86 assembly (clang, -O0):
<bitpack_gets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x40,-0x8(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x40,-0xc(%rbp)
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
cmp    $0x40,%eax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x40,%esi
sub    %eax,%esi
call   1030 <shl@plt>
mov    %eax,%edi
mov    $0x40,%esi
sub    -0xc(%rbp),%esi
call   1050 <shr_arith@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitpack_gets>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%r14d
xor    %edi,%edi
cmp    $0x40,%esi
setb   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmp    $0x41,%r15d
setb   %dil
call   1040 <assert@plt>
add    %r15d,%ebp
xor    %edi,%edi
cmp    $0x41,%ebp
setb   %dil
call   1040 <assert@plt>
mov    $0x40,%ebx
mov    $0x40,%esi
sub    %ebp,%esi
mov    %r14d,%edi
call   1030 <shl@plt>
sub    %r15d,%ebx
mov    %eax,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <shr_arith@plt>

LLVM IR (-O0):
define i32 @bitpack_gets(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 ult i32 %7, 64
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %6
%12 = icmp ule i32 %11, 64
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = add i32 %15, %16
%18 = icmp ule i32 %17, 64
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = add i32 %22, %23
%25 = sub i32 64, %24
%26 = call i32 @shl(i32 %21, i32 %25)
%27 = load i32, i32* %6
%28 = sub i32 64, %27
%29 = call i32 @shr_arith(i32 %26, i32 %28)
ret i32 %29
}

LLVM IR (-O2):
define i32 @bitpack_gets(i32 %0, i32 %1, i32 %2) {
%4 = icmp ult i32 %1, 64
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ult i32 %2, 65
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = add i32 %2, %1
%11 = icmp ult i32 %10, 65
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = sub i32 64, %10
%15 = tail call i32 @shl(i32 %0, i32 %14)
%16 = sub i32 64, %2
%17 = tail call i32 @shr_arith(i32 %15, i32 %16)
ret i32 %17
}