#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 */
unsigned int M4U_ReadReg32(unsigned int, unsigned int);
int /*<<< orphan*/ M4U_WriteReg32(unsigned int, unsigned int, unsigned int);
unsigned int m4uHw_set_field(unsigned int M4UBase, unsigned int Reg,
                             unsigned int bit_width, unsigned int shift,
                             unsigned int value) {
  unsigned int mask = ((1 << bit_width) - 1) << shift;
  unsigned int old;
  value = (value << shift) & mask;
  old = M4U_ReadReg32(M4UBase, Reg);
  M4U_WriteReg32(M4UBase, Reg, (old & (~mask)) | value);
  return (old & mask) >> shift;
}


x86 assembly (clang, -O0):
<m4uHw_set_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x1,%eax
mov    -0x10(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    %cl,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <M4U_ReadReg32@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
or     -0x14(%rbp),%edx
call   1040 <M4U_WriteReg32@plt>
mov    -0x1c(%rbp),%eax
and    -0x18(%rbp),%eax
mov    -0x10(%rbp),%ecx
shr    %cl,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m4uHw_set_field>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%ecx
mov    $0xffffffff,%ebp
shl    %cl,%ebp
not    %ebp
mov    %r14d,%ecx
shl    %cl,%ebp
mov    %r8d,%ebx
mov    %esi,%r15d
mov    %edi,%r12d
shl    %cl,%ebx
call   1030 <M4U_ReadReg32@plt>
mov    %eax,%r13d
xor    %eax,%ebx
and    %ebp,%ebx
xor    %eax,%ebx
mov    %r12d,%edi
mov    %r15d,%esi
mov    %ebx,%edx
call   1040 <M4U_WriteReg32@plt>
and    %r13d,%ebp
mov    %r14d,%ecx
shr    %cl,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @m4uHw_set_field(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = shl nsw i32 -1, %2
%7 = xor i32 %6, -1
%8 = shl i32 %7, %3
%9 = shl i32 %4, %3
%10 = and i32 %9, %8
%11 = tail call i32 @M4U_ReadReg32(i32 %0, i32 %1)
%12 = xor i32 %8, -1
%13 = and i32 %11, %12
%14 = or i32 %13, %10
%15 = tail call i32 @M4U_WriteReg32(i32 %0, i32 %1, i32 %14)
%16 = and i32 %11, %8
%17 = lshr i32 %16, %3
ret i32 %17
}