#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;

/* Variables and functions */
void alterRegisterValue(uint32_t *reg, int bitPos, int bitWidth,
                        uint16_t value) {
  uint32_t mask;
  mask = 1;
  mask = ~(((mask << bitWidth) - 1) << bitPos);
  *reg &= mask;
  mask = 1;
  mask = (mask << bitWidth) - 1;
  mask &= value;
  mask <<= bitPos;
  *reg |= mask;
}


x86 assembly (clang, -O0):
<alterRegisterValue>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    %cl,%eax
sub    $0x1,%eax
mov    -0xc(%rbp),%ecx
shl    %cl,%eax
xor    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    %cl,%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%eax
shl    %cl,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<alterRegisterValue>:
mov    %ecx,%r8d
mov    %edx,%ecx
mov    $0xffffffff,%edx
shl    %cl,%edx
not    %edx
mov    %edx,%eax
mov    %esi,%ecx
shl    %cl,%eax
not    %eax
and    %r8d,%edx
shl    %cl,%edx
and    (%rdi),%eax
or     %eax,%edx
mov    %edx,(%rdi)
ret

LLVM IR (-O0):
define void @alterRegisterValue(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
store i32 1, i32* %9
%10 = load i32, i32* %9
%11 = load i32, i32* %7
%12 = shl i32 %10, %11
%13 = sub nsw i32 %12, 1
%14 = load i32, i32* %6
%15 = shl i32 %13, %14
%16 = xor i32 %15, -1
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = load i32*, i32** %5
%19 = load i32, i32* %18
%20 = and i32 %19, %17
store i32 %20, i32* %18
store i32 1, i32* %9
%21 = load i32, i32* %9
%22 = load i32, i32* %7
%23 = shl i32 %21, %22
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %9
%25 = load i32, i32* %8
%26 = load i32, i32* %9
%27 = and i32 %26, %25
store i32 %27, i32* %9
%28 = load i32, i32* %6
%29 = load i32, i32* %9
%30 = shl i32 %29, %28
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = load i32*, i32** %5
%33 = load i32, i32* %32
%34 = or i32 %33, %31
store i32 %34, i32* %32
ret void
}

LLVM IR (-O2):
define void @alterRegisterValue(i32* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = shl nsw i32 -1, %2
%6 = xor i32 %5, -1
%7 = shl i32 %6, %1
%8 = xor i32 %7, -1
%9 = load i32, i32* %0
%10 = and i32 %9, %8
%11 = and i32 %6, %3
%12 = shl i32 %11, %1
%13 = or i32 %10, %12
store i32 %13, i32* %0
ret void
}