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

/* Variables and functions */
int mcp23s17_read_reg(int, int, int);
void mcp23s17_write_reg(int, int, int, int);
void mcp23s17_write_bit(uint8_t data, uint8_t bit_num, uint8_t reg,
                        uint8_t hw_addr, int fd) {
  uint8_t reg_data = mcp23s17_read_reg(reg, hw_addr, fd);
  if (data) {
    reg_data |= 1 << bit_num;
  } else {
    reg_data &= 0xff ^ (1 << bit_num);
  }
  return mcp23s17_write_reg(reg_data, reg, hw_addr, fd);
}


x86 assembly (clang, -O0):
<mcp23s17_write_bit>:
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),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <mcp23s17_read_reg@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1168 <mcp23s17_write_bit+0x48>
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    117d <mcp23s17_write_bit+0x5d>
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    $0xff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1040 <mcp23s17_write_reg@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mcp23s17_write_bit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r12d
mov    %edx,%edi
mov    %ecx,%esi
mov    %r8d,%edx
call   1030 <mcp23s17_read_reg@plt>
mov    $0xff,%edi
btc    %ebp,%edi
and    %eax,%edi
bts    %ebp,%eax
test   %r12d,%r12d
cmovne %eax,%edi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <mcp23s17_write_reg@plt>

LLVM IR (-O0):
define void @mcp23s17_write_bit(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
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
%12 = load i32, i32* %8
%13 = load i32, i32* %9
%14 = load i32, i32* %10
%15 = call i32 @mcp23s17_read_reg(i32 %12, i32 %13, i32 %14)
store i32 %15, i32* %11
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %5
%19 = load i32, i32* %7
%20 = shl i32 1, %19
%21 = load i32, i32* %11
%22 = or i32 %21, %20
store i32 %22, i32* %11
br label %29
23: ; preds = %5
%24 = load i32, i32* %7
%25 = shl i32 1, %24
%26 = xor i32 255, %25
%27 = load i32, i32* %11
%28 = and i32 %27, %26
store i32 %28, i32* %11
br label %29
29: ; preds = %23, %18
%30 = load i32, i32* %11
%31 = load i32, i32* %8
%32 = load i32, i32* %9
%33 = load i32, i32* %10
ret void
}

LLVM IR (-O2):
define void @mcp23s17_write_bit(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32 @mcp23s17_read_reg(i32 %2, i32 %3, i32 %4)
%7 = icmp eq i32 %0, 0
%8 = shl nuw i32 1, %1
%9 = or i32 %6, %8
%10 = xor i32 %8, 255
%11 = and i32 %6, %10
%12 = select i1 %7, i32 %11, i32 %9
tail call void @mcp23s17_write_reg(i32 %12, i32 %2, i32 %3, i32 %4)
ret void
}