#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 unsigned int uint32_t;

/* Variables and functions */
void change_bits_in_word(volatile uint32_t *word, uint32_t bits,
                         uint32_t bits_length, uint32_t bits_pos) {
  uint32_t mask;
  if ((word == NULL) || ((bits_length + bits_pos) > 32U) ||
      (bits_length == 0U)) {
    return;
  }
  if (bits_length == 32U) {
    *word = bits;
    return;
  }
  mask = ((1U << bits_length) - 1);
  *word = ((*word & ~(mask << bits_pos)) | ((bits & mask) << bits_pos));
}


x86 assembly (clang, -O0):
<change_bits_in_word>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1135 <change_bits_in_word+0x35>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    $0x20,%eax
ja     1135 <change_bits_in_word+0x35>
cmpl   $0x0,-0x10(%rbp)
jne    113a <change_bits_in_word+0x3a>
jmp    1190 <change_bits_in_word+0x90>
cmpl   $0x20,-0x10(%rbp)
jne    1152 <change_bits_in_word+0x52>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1190 <change_bits_in_word+0x90>
mov    -0x10(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
and    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    %cl,%eax
mov    -0x1c(%rbp),%ecx
or     %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_bits_in_word>:
test   %rdi,%rdi
je     113a <change_bits_in_word+0x3a>
test   %edx,%edx
je     113a <change_bits_in_word+0x3a>
mov    %ecx,%r8d
lea    (%r8,%rdx,1),%ecx
cmp    $0x20,%ecx
ja     113a <change_bits_in_word+0x3a>
cmp    $0x20,%edx
je     1138 <change_bits_in_word+0x38>
mov    $0xffffffff,%eax
mov    %edx,%ecx
shl    %cl,%eax
not    %eax
mov    %eax,%edx
mov    %r8d,%ecx
shl    %cl,%edx
not    %edx
and    (%rdi),%edx
and    %esi,%eax
shl    %cl,%eax
or     %edx,%eax
mov    %eax,%esi
mov    %esi,(%rdi)
ret

LLVM IR (-O0):
define void @change_bits_in_word(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %20, label %12
12: ; preds = %4
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = add i32 %13, %14
%16 = icmp ugt i32 %15, 32
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17, %12, %4
br label %45
21: ; preds = %17
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 32
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %6
%26 = load i32*, i32** %5
store volatile i32 %25, i32* %26
br label %45
27: ; preds = %21
%28 = load i32, i32* %7
%29 = shl i32 1, %28
%30 = sub i32 %29, 1
store i32 %30, i32* %9
%31 = load i32*, i32** %5
%32 = load volatile i32, i32* %31
%33 = load i32, i32* %9
%34 = load i32, i32* %8
%35 = shl i32 %33, %34
%36 = xor i32 %35, -1
%37 = and i32 %32, %36
%38 = load i32, i32* %6
%39 = load i32, i32* %9
%40 = and i32 %38, %39
%41 = load i32, i32* %8
%42 = shl i32 %40, %41
%43 = or i32 %37, %42
%44 = load i32*, i32** %5
store volatile i32 %43, i32* %44
br label %45
45: ; preds = %27, %24, %20
ret void
}

LLVM IR (-O2):
define void @change_bits_in_word(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32* %0, null
br i1 %5, label %25, label %6
6: ; preds = %4
%7 = add i32 %3, %2
%8 = icmp ugt i32 %7, 32
%9 = icmp eq i32 %2, 0
%10 = or i1 %9, %8
br i1 %10, label %25, label %11
11: ; preds = %6
%12 = icmp eq i32 %2, 32
br i1 %12, label %23, label %13
13: ; preds = %11
%14 = shl nsw i32 -1, %2
%15 = xor i32 %14, -1
%16 = load volatile i32, i32* %0
%17 = shl i32 %15, %3
%18 = xor i32 %17, -1
%19 = and i32 %16, %18
%20 = and i32 %15, %1
%21 = shl i32 %20, %3
%22 = or i32 %19, %21
br label %23
23: ; preds = %11, %13
%24 = phi i32 [ %22, %13 ], [ %1, %11 ]
store volatile i32 %24, i32* %0
br label %25
25: ; preds = %23, %4, %6
ret void
}