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

/* Variables and functions */
int us_bits_get_octet(void *, int);
int /*<<< orphan*/ us_bits_set_octet(void *, int, int);
void us_bits_set_octet_bitfield(void *base, uint16_t offset, uint16_t msb,
                                uint16_t lsb, uint32_t newbits) {
  uint8_t v = us_bits_get_octet(base, offset);
  v = (((newbits) << (7 - ((lsb)))) |
       (((v)) &
        ((~(((0xff) >> (8 - ((((lsb) - (msb) + 1))))) << (7 - ((((lsb))))))) &
         0xff)));
  us_bits_set_octet(base, offset, v);
}


x86 assembly (clang, -O0):
<us_bits_set_octet_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    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <us_bits_get_octet@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x7,%ecx
sub    -0x14(%rbp),%ecx
shl    %cl,%eax
mov    -0x1c(%rbp),%ecx
mov    %ecx,-0x20(%rbp)
mov    -0x14(%rbp),%edx
sub    -0x10(%rbp),%edx
add    $0x1,%edx
mov    $0x8,%ecx
sub    %edx,%ecx
mov    $0xff,%edx
sar    %cl,%edx
mov    $0x7,%ecx
sub    -0x14(%rbp),%ecx
shl    %cl,%edx
mov    -0x20(%rbp),%ecx
xor    $0xffffffff,%edx
and    $0xff,%edx
and    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <us_bits_set_octet@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<us_bits_set_octet_bitfield>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r12d
mov    %ecx,%ebp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
call   1040 <us_bits_get_octet@plt>
mov    $0x7,%dl
sub    %bpl,%dl
mov    %edx,%ecx
shl    %cl,%r12d
sub    %ebp,%ebx
add    $0x7,%bl
mov    $0xff,%esi
mov    %ebx,%ecx
shr    %cl,%esi
mov    %edx,%ecx
shl    %cl,%esi
not    %esi
and    %eax,%esi
movzbl %sil,%edx
or     %r12d,%edx
mov    %r15,%rdi
mov    %r14d,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <us_bits_set_octet@plt>

LLVM IR (-O0):
define void @us_bits_set_octet_bitfield(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i8*, i8** %6
%13 = load i32, i32* %7
%14 = call i32 @us_bits_get_octet(i8* %12, i32 %13)
store i32 %14, i32* %11
%15 = load i32, i32* %10
%16 = load i32, i32* %9
%17 = sub nsw i32 7, %16
%18 = shl i32 %15, %17
%19 = load i32, i32* %11
%20 = load i32, i32* %9
%21 = load i32, i32* %8
%22 = sub nsw i32 %20, %21
%23 = add nsw i32 %22, 1
%24 = sub nsw i32 8, %23
%25 = ashr i32 255, %24
%26 = load i32, i32* %9
%27 = sub nsw i32 7, %26
%28 = shl i32 %25, %27
%29 = xor i32 %28, -1
%30 = and i32 %29, 255
%31 = and i32 %19, %30
%32 = or i32 %18, %31
store i32 %32, i32* %11
%33 = load i8*, i8** %6
%34 = load i32, i32* %7
%35 = load i32, i32* %11
%36 = call i32 @us_bits_set_octet(i8* %33, i32 %34, i32 %35)
ret void
}

LLVM IR (-O2):
define void @us_bits_set_octet_bitfield(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32 @us_bits_get_octet(i8* %0, i32 %1)
%7 = sub nsw i32 7, %3
%8 = shl i32 %4, %7
%9 = add i32 %2, 7
%10 = sub i32 %9, %3
%11 = lshr i32 255, %10
%12 = shl i32 %11, %7
%13 = and i32 %12, 255
%14 = xor i32 %13, 255
%15 = and i32 %6, %14
%16 = or i32 %15, %8
%17 = tail call i32 @us_bits_set_octet(i8* %0, i32 %1, i32 %16)
ret void
}