#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 */

/* Variables and functions */
int /*<<< orphan*/ memmove(unsigned char *, unsigned char const *, int);
unsigned long bfx(const unsigned char *cptr, unsigned long bit_offset,
                  unsigned long bit_len) {
  unsigned long l;
  unsigned long byte_offset;
  unsigned long left_shift;
  unsigned long right_shift;
  byte_offset = (bit_offset - 1) / 8;
  left_shift = bit_offset - byte_offset * 8 - 1;
  right_shift = 32 - bit_len;
  memmove((unsigned char *)&l, &cptr[byte_offset], 4);
  return (l << left_shift) >> right_shift;
}


x86 assembly (clang, -O0):
<bfx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
shr    $0x3,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x3,%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    $0x20,%eax
sub    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memmove@plt>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
shl    %cl,%rax
mov    -0x38(%rbp),%rcx
shr    %cl,%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bfx>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
lea    -0x1(%rsi),%rbx
mov    %rbx,%rax
shr    $0x3,%rax
not    %ebx
or     $0x7,%ebx
add    %esi,%ebx
add    %rdi,%rax
mov    %rsp,%rdi
mov    %rax,%rsi
mov    $0x4,%edx
call   1030 <memmove@plt>
mov    (%rsp),%rax
mov    %ebx,%ecx
shl    %cl,%rax
add    $0x20,%r14
neg    %r14
mov    %r14d,%ecx
shr    %cl,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @bfx(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%11 = load i64, i64* %5
%12 = sub i64 %11, 1
%13 = udiv i64 %12, 8
store i64 %13, i64* %8
%14 = load i64, i64* %5
%15 = load i64, i64* %8
%16 = mul i64 %15, 8
%17 = sub i64 %14, %16
%18 = sub i64 %17, 1
store i64 %18, i64* %9
%19 = load i64, i64* %6
%20 = sub i64 32, %19
store i64 %20, i64* %10
%21 = bitcast i64* %7 to i8*
%22 = load i8*, i8** %4
%23 = load i64, i64* %8
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = call i32 @memmove(i8* %21, i8* %24, i32 4)
%26 = load i64, i64* %7
%27 = load i64, i64* %9
%28 = shl i64 %26, %27
%29 = load i64, i64* %10
%30 = lshr i64 %28, %29
ret i64 %30
}

LLVM IR (-O2):
define i64 @bfx(i8* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = add i64 %1, -1
%7 = lshr i64 %6, 3
%8 = and i64 %6, -8
%9 = xor i64 %8, -1
%10 = add i64 %9, %1
%11 = sub i64 32, %2
%12 = getelementptr inbounds i8, i8* %0, i64 %7
%13 = call i32 @memmove(i8* %5, i8* %12, i32 4)
%14 = load i64, i64* %4
%15 = shl i64 %14, %10
%16 = lshr i64 %15, %11
ret i64 %16
}