#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 uint64_t;
typedef int uint16_t;
typedef scalar_t__ msb;
typedef int lsb;

/* Variables and functions */
int us_bits_get_octlet(void const *, int);
uint64_t us_bits_get_octlet_bitfield(const void *base, uint16_t offset,
                                     uint16_t msb, uint16_t lsb) {
  uint64_t v = us_bits_get_octlet(base, offset);
  uint64_t r =
      ((((v)) & (((0xffffffffffffffffULL) >> (64 - ((lsb) - (msb) + 1)))
                 << (63 - ((lsb))))) >>
       (63 - ((lsb))));
  return r;
}


x86 assembly (clang, -O0):
<us_bits_get_octlet_bitfield>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <us_bits_get_octlet@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
mov    -0x14(%rbp),%edx
sub    -0x10(%rbp),%edx
add    $0x1,%edx
mov    $0x40,%ecx
sub    %edx,%ecx
mov    %ecx,%ecx
mov    $0xffffffffffffffff,%rdx
shr    %cl,%rdx
mov    $0x3f,%ecx
sub    -0x14(%rbp),%ecx
mov    %ecx,%ecx
shl    %cl,%rdx
mov    %rdx,%rcx
and    %rcx,%rax
mov    $0x3f,%ecx
sub    -0x14(%rbp),%ecx
mov    %ecx,%ecx
shr    %cl,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<us_bits_get_octlet_bitfield>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%ebp
call   1030 <us_bits_get_octlet@plt>
movslq %eax,%rdx
sub    %ebx,%ebp
add    $0x3f,%bpl
mov    $0xffffffffffffffff,%rax
mov    %ebp,%ecx
shr    %cl,%rax
mov    $0x3f,%cl
sub    %bl,%cl
shl    %cl,%rax
and    %rdx,%rax
shr    %cl,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @us_bits_get_octlet_bitfield(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = call i32 @us_bits_get_octlet(i8* %11, i32 %12)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = sext i32 %14 to i64
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = sub nsw i32 %16, %17
%19 = add nsw i32 %18, 1
%20 = sub nsw i32 64, %19
%21 = zext i32 %20 to i64
%22 = lshr i64 -1, %21
%23 = load i32, i32* %8
%24 = sub nsw i32 63, %23
%25 = zext i32 %24 to i64
%26 = shl i64 %22, %25
%27 = and i64 %15, %26
%28 = load i32, i32* %8
%29 = sub nsw i32 63, %28
%30 = zext i32 %29 to i64
%31 = lshr i64 %27, %30
%32 = trunc i64 %31 to i32
store i32 %32, i32* %10
%33 = load i32, i32* %10
ret i32 %33
}

LLVM IR (-O2):
define i32 @us_bits_get_octlet_bitfield(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @us_bits_get_octlet(i8* %0, i32 %1)
%6 = sext i32 %5 to i64
%7 = add i32 %2, 63
%8 = sub i32 %7, %3
%9 = zext i32 %8 to i64
%10 = lshr i64 -1, %9
%11 = sub nsw i32 63, %3
%12 = zext i32 %11 to i64
%13 = shl i64 %10, %12
%14 = and i64 %13, %6
%15 = lshr i64 %14, %12
%16 = trunc i64 %15 to i32
ret i32 %16
}