#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 */
int /*<<< orphan*/ TWI_Read(unsigned char, int *, int);
int /*<<< orphan*/ TWI_Write(unsigned char, int);
void TWI_WriteBit(unsigned char reg, unsigned char bit_num,
                  unsigned char data) {
  int read_aux[1];
  unsigned char data_add = 0;
  TWI_Read(reg, read_aux, 1);
  if (data == 1)
    data_add |= (1 << bit_num);
  else
    data_add &= ~(1 << bit_num);
  read_aux[0] |= data_add;
  TWI_Write(reg, read_aux[0]);
}


x86 assembly (clang, -O0):
<TWI_WriteBit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
movb   $0x0,-0x9(%rbp)
mov    -0x1(%rbp),%al
lea    -0x8(%rbp),%rsi
mov    $0x1,%edx
movzbl %al,%edi
call   1040 <TWI_Read@plt>
movzbl -0x3(%rbp),%eax
cmp    $0x1,%eax
jne    1179 <TWI_WriteBit+0x59>
movzbl -0x2(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
movzbl -0x9(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x9(%rbp)
jmp    1192 <TWI_WriteBit+0x72>
movzbl -0x2(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
xor    $0xffffffff,%ecx
movzbl -0x9(%rbp),%eax
and    %ecx,%eax
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x1(%rbp),%al
mov    -0x8(%rbp),%esi
movzbl %al,%edi
call   1030 <TWI_Write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TWI_WriteBit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
lea    0x4(%rsp),%rsi
mov    $0x1,%ebp
mov    $0x1,%edx
call   1040 <TWI_Read@plt>
mov    %r15d,%ecx
shl    %cl,%ebp
xor    %eax,%eax
cmp    $0x1,%r14b
movzbl %bpl,%esi
cmovne %eax,%esi
or     0x4(%rsp),%esi
mov    %esi,0x4(%rsp)
mov    %ebx,%edi
call   1030 <TWI_Write@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @TWI_WriteBit(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca [1 x i32]
%8 = alloca i8
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8 %2, i8* %6
store i8 0, i8* %8
%9 = load i8, i8* %4
%10 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 0
%11 = call i32 @TWI_Read(i8 zeroext %9, i32* %10, i32 1)
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %23
15: ; preds = %3
%16 = load i8, i8* %5
%17 = zext i8 %16 to i32
%18 = shl i32 1, %17
%19 = load i8, i8* %8
%20 = zext i8 %19 to i32
%21 = or i32 %20, %18
%22 = trunc i32 %21 to i8
store i8 %22, i8* %8
br label %32
23: ; preds = %3
%24 = load i8, i8* %5
%25 = zext i8 %24 to i32
%26 = shl i32 1, %25
%27 = xor i32 %26, -1
%28 = load i8, i8* %8
%29 = zext i8 %28 to i32
%30 = and i32 %29, %27
%31 = trunc i32 %30 to i8
store i8 %31, i8* %8
br label %32
32: ; preds = %23, %15
%33 = load i8, i8* %8
%34 = zext i8 %33 to i32
%35 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 0
%36 = load i32, i32* %35
%37 = or i32 %36, %34
store i32 %37, i32* %35
%38 = load i8, i8* %4
%39 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 0
%40 = load i32, i32* %39
%41 = call i32 @TWI_Write(i8 zeroext %38, i32 %40)
ret void
}

LLVM IR (-O2):
define void @TWI_WriteBit(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca [1 x i32]
%5 = bitcast [1 x i32]* %4 to i8*
%6 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
%7 = call i32 @TWI_Read(i8 zeroext %0, i32* %6, i32 1)
%8 = icmp eq i8 %2, 1
%9 = zext i8 %1 to i32
%10 = shl nuw i32 1, %9
%11 = and i32 %10, 255
%12 = select i1 %8, i32 %11, i32 0
%13 = load i32, i32* %6
%14 = or i32 %13, %12
store i32 %14, i32* %6
%15 = call i32 @TWI_Write(i8 zeroext %0, i32 %14)
ret void
}