#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 /*<<< orphan*/ uint8_t;
struct inv_icm30xxx {
  int dummy;
};

/* Variables and functions */
int inv_icm30xxx_read_reg_one(struct inv_icm30xxx *, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/ *);
int inv_icm30xxx_write_reg_one(struct inv_icm30xxx *, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/);
int inv_icm30xxx_clear_reg_bits(struct inv_icm30xxx *s, uint8_t bank,
                                uint8_t reg, uint8_t bits_mask) {
  int rc;
  uint8_t reg_value;
  if ((rc = inv_icm30xxx_read_reg_one(s, bank, reg, &reg_value)) != 0)
    return rc;
  reg_value &= ~bits_mask;
  if ((rc = inv_icm30xxx_write_reg_one(s, bank, reg, reg_value)) != 0)
    return rc;
  return 0;
}


x86 assembly (clang, -O0):
<inv_icm30xxx_clear_reg_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    -0x24(%rbp),%rcx
call   1040 <inv_icm30xxx_read_reg_one@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     115f <inv_icm30xxx_clear_reg_bits+0x3f>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119b <inv_icm30xxx_clear_reg_bits+0x7b>
mov    -0x1c(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   1030 <inv_icm30xxx_write_reg_one@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     1194 <inv_icm30xxx_clear_reg_bits+0x74>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119b <inv_icm30xxx_clear_reg_bits+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inv_icm30xxx_clear_reg_bits>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbp
lea    0x4(%rsp),%rcx
call   1040 <inv_icm30xxx_read_reg_one@plt>
test   %eax,%eax
jne    115a <inv_icm30xxx_clear_reg_bits+0x3a>
not    %ebx
and    0x4(%rsp),%ebx
mov    %ebx,0x4(%rsp)
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
call   1030 <inv_icm30xxx_write_reg_one@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.inv_icm30xxx = type { i32 }
define i32 @inv_icm30xxx_clear_reg_bits(%struct.inv_icm30xxx* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.inv_icm30xxx*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store %struct.inv_icm30xxx* %0, %struct.inv_icm30xxx** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = load %struct.inv_icm30xxx*, %struct.inv_icm30xxx** %6
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = call i32 @inv_icm30xxx_read_reg_one(%struct.inv_icm30xxx* %12, i32 %13, i32 %14, i32* %11)
store i32 %15, i32* %10
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32, i32* %10
store i32 %18, i32* %5
br label %33
19: ; preds = %4
%20 = load i32, i32* %9
%21 = xor i32 %20, -1
%22 = load i32, i32* %11
%23 = and i32 %22, %21
store i32 %23, i32* %11
%24 = load %struct.inv_icm30xxx*, %struct.inv_icm30xxx** %6
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = load i32, i32* %11
%28 = call i32 @inv_icm30xxx_write_reg_one(%struct.inv_icm30xxx* %24, i32 %25, i32 %26, i32 %27)
store i32 %28, i32* %10
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %19
%31 = load i32, i32* %10
store i32 %31, i32* %5
br label %33
32: ; preds = %19
store i32 0, i32* %5
br label %33
33: ; preds = %32, %30, %17
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
%struct.inv_icm30xxx = type { i32 }
define i32 @inv_icm30xxx_clear_reg_bits(%struct.inv_icm30xxx* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = call i32 @inv_icm30xxx_read_reg_one(%struct.inv_icm30xxx* %0, i32 %1, i32 %2, i32* %5)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = xor i32 %3, -1
%11 = load i32, i32* %5
%12 = and i32 %11, %10
store i32 %12, i32* %5
%13 = call i32 @inv_icm30xxx_write_reg_one(%struct.inv_icm30xxx* %0, i32 %1, i32 %2, i32 %12)
br label %14
14: ; preds = %9, %4
%15 = phi i32 [ %7, %4 ], [ %13, %9 ]
ret i32 %15
}