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

/* Variables and functions */
int us_bits_get_doublet(void *, int);
int /*<<< orphan*/ us_bits_set_doublet(void *, int, int);
void us_bits_set_doublet_bitfield(void *base, uint16_t offset, uint16_t msb,
                                  uint16_t lsb, uint32_t newbits) {
  uint16_t v = us_bits_get_doublet(base, offset);
  v = (((newbits) << (15 - ((lsb)))) |
       (((v)) & ((~(((0xffff) >> (16 - ((((lsb) - (msb) + 1)))))
                    << (15 - ((((lsb))))))) &
                 0xffff)));
  us_bits_set_doublet(base, offset, v);
}


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

x86 assembly (clang, -O2):
<us_bits_set_doublet_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   1030 <us_bits_get_doublet@plt>
mov    $0xf,%dl
sub    %bpl,%dl
mov    %edx,%ecx
shl    %cl,%r12d
sub    %ebp,%ebx
add    $0xf,%bl
mov    $0xffff,%esi
mov    %ebx,%ecx
shr    %cl,%esi
mov    %edx,%ecx
shl    %cl,%esi
not    %esi
and    %eax,%esi
movzwl %si,%edx
or     %r12d,%edx
mov    %r15,%rdi
mov    %r14d,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <us_bits_set_doublet@plt>

LLVM IR (-O0):
define void @us_bits_set_doublet_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_doublet(i8* %12, i32 %13)
store i32 %14, i32* %11
%15 = load i32, i32* %10
%16 = load i32, i32* %9
%17 = sub nsw i32 15, %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 16, %23
%25 = ashr i32 65535, %24
%26 = load i32, i32* %9
%27 = sub nsw i32 15, %26
%28 = shl i32 %25, %27
%29 = xor i32 %28, -1
%30 = and i32 %29, 65535
%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_doublet(i8* %33, i32 %34, i32 %35)
ret void
}

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