#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;
typedef scalar_t__ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ readWord(int, int, scalar_t__ *);
int writeWord(int, int, scalar_t__);
int writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data) {
  uint16_t w;
  readWord(devAddr, regAddr, &w);
  w = (data != 0) ? (w | (1 << bitNum)) : (w & ~(1 << bitNum));
  return writeWord(devAddr, regAddr, w);
}


x86 assembly (clang, -O0):
<writeBitW>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1030 <readWord@plt>
cmpq   $0x0,-0x18(%rbp)
je     116e <writeBitW+0x4e>
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
or     %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    118b <writeBitW+0x6b>
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <writeWord@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeBitW>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ebx
mov    %esi,%r15d
mov    %edi,%ebp
mov    %rsp,%rdx
call   1030 <readWord@plt>
mov    $0x1,%eax
mov    %ebx,%ecx
shl    %cl,%eax
mov    (%rsp),%rdx
test   %r14,%r14
je     1152 <writeBitW+0x32>
cltq
or     %rax,%rdx
jmp    1159 <writeBitW+0x39>
not    %eax
cltq
and    %rax,%rdx
mov    %rdx,(%rsp)
mov    %ebp,%edi
mov    %r15d,%esi
call   1040 <writeWord@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @writeBitW(i32 %0, i32 %1, i32 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i64 %3, i64* %8
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i32 @readWord(i32 %10, i32 %11, i64* %9)
%13 = load i64, i64* %8
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %4
%16 = load i64, i64* %9
%17 = load i32, i32* %7
%18 = shl i32 1, %17
%19 = sext i32 %18 to i64
%20 = or i64 %16, %19
br label %28
21: ; preds = %4
%22 = load i64, i64* %9
%23 = load i32, i32* %7
%24 = shl i32 1, %23
%25 = xor i32 %24, -1
%26 = sext i32 %25 to i64
%27 = and i64 %22, %26
br label %28
28: ; preds = %21, %15
%29 = phi i64 [ %20, %15 ], [ %27, %21 ]
store i64 %29, i64* %9
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = load i64, i64* %9
%33 = call i32 @writeWord(i32 %30, i32 %31, i64 %32)
ret i32 %33
}

LLVM IR (-O2):
define i32 @writeBitW(i32 %0, i32 %1, i32 %2, i64 %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = call i32 @readWord(i32 %0, i32 %1, i64* %5)
%8 = icmp eq i64 %3, 0
%9 = load i64, i64* %5
%10 = shl nuw i32 1, %2
br i1 %8, label %14, label %11
11: ; preds = %4
%12 = sext i32 %10 to i64
%13 = or i64 %9, %12
br label %18
14: ; preds = %4
%15 = xor i32 %10, -1
%16 = sext i32 %15 to i64
%17 = and i64 %9, %16
br label %18
18: ; preds = %14, %11
%19 = phi i64 [ %13, %11 ], [ %17, %14 ]
store i64 %19, i64* %5
%20 = call i32 @writeWord(i32 %0, i32 %1, i64 %19)
ret i32 %20
}