#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*/ I2C_SLAVE;
char i2c_smbus_read_byte_data(int, int);
int /*<<< orphan*/ i2c_smbus_write_byte_data(int, int, char);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, char);
void pca9557_set_pin_level(int fd, char addr, char port, bool level) {
  char state;
  ioctl(fd, I2C_SLAVE, addr);
  state = i2c_smbus_read_byte_data(fd, 0x01);
  if (level)
    state |= (1 << (port));
  else
    state &= ~(1 << (port));
  i2c_smbus_write_byte_data(fd, 0x01, state);
}


x86 assembly (clang, -O0):
<pca9557_set_pin_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %edi,-0x4(%rbp)
mov    %dl,-0x5(%rbp)
mov    %al,-0x6(%rbp)
mov    %ecx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
movsbl -0x5(%rbp),%edx
call   1030 <ioctl@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1050 <i2c_smbus_read_byte_data@plt>
mov    %al,-0xd(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1193 <pca9557_set_pin_level+0x63>
movsbl -0x6(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
movsbl -0xd(%rbp),%eax
or     %ecx,%eax
mov    %al,-0xd(%rbp)
jmp    11ac <pca9557_set_pin_level+0x7c>
movsbl -0x6(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
xor    $0xffffffff,%ecx
movsbl -0xd(%rbp),%eax
and    %ecx,%eax
mov    %al,-0xd(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
movsbl -0xd(%rbp),%edx
call   1040 <i2c_smbus_write_byte_data@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pca9557_set_pin_level>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%edx
mov    %edi,%ebx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
call   1030 <ioctl@plt>
mov    $0x1,%ebp
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <i2c_smbus_read_byte_data@plt>
mov    %r15d,%ecx
shl    %cl,%ebp
mov    %eax,%ecx
or     %bpl,%cl
not    %bpl
and    %al,%bpl
test   %r14d,%r14d
movzbl %bpl,%eax
movzbl %cl,%ecx
cmove  %eax,%ecx
movsbl %cl,%edx
mov    %ebx,%edi
mov    $0x1,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <i2c_smbus_write_byte_data@plt>

LLVM IR (-O0):
@I2C_SLAVE = global i32 0
define void @pca9557_set_pin_level(i32 %0, i8 signext %1, i8 signext %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
%9 = alloca i8
store i32 %0, i32* %5
store i8 %1, i8* %6
store i8 %2, i8* %7
store i32 %3, i32* %8
%10 = load i32, i32* %5
%11 = load i32, i32* @I2C_SLAVE
%12 = load i8, i8* %6
%13 = call i32 @ioctl(i32 %10, i32 %11, i8 signext %12)
%14 = load i32, i32* %5
%15 = call signext i8 @i2c_smbus_read_byte_data(i32 %14, i32 1)
store i8 %15, i8* %9
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %4
%19 = load i8, i8* %7
%20 = sext i8 %19 to i32
%21 = shl i32 1, %20
%22 = load i8, i8* %9
%23 = sext i8 %22 to i32
%24 = or i32 %23, %21
%25 = trunc i32 %24 to i8
store i8 %25, i8* %9
br label %35
26: ; preds = %4
%27 = load i8, i8* %7
%28 = sext i8 %27 to i32
%29 = shl i32 1, %28
%30 = xor i32 %29, -1
%31 = load i8, i8* %9
%32 = sext i8 %31 to i32
%33 = and i32 %32, %30
%34 = trunc i32 %33 to i8
store i8 %34, i8* %9
br label %35
35: ; preds = %26, %18
%36 = load i32, i32* %5
%37 = load i8, i8* %9
%38 = call i32 @i2c_smbus_write_byte_data(i32 %36, i32 1, i8 signext %37)
ret void
}

LLVM IR (-O2):
@I2C_SLAVE = global i32 0
define void @pca9557_set_pin_level(i32 %0, i8 signext %1, i8 signext %2, i32 %3) {
%5 = load i32, i32* @I2C_SLAVE
%6 = tail call i32 @ioctl(i32 %0, i32 %5, i8 signext %1)
%7 = tail call signext i8 @i2c_smbus_read_byte_data(i32 %0, i32 1)
%8 = icmp eq i32 %3, 0
%9 = zext i8 %2 to i32
%10 = shl nuw i32 1, %9
%11 = trunc i32 %10 to i8
%12 = or i8 %7, %11
%13 = xor i8 %11, -1
%14 = and i8 %7, %13
%15 = select i1 %8, i8 %14, i8 %12
%16 = tail call i32 @i2c_smbus_write_byte_data(i32 %0, i32 1, i8 signext %15)
ret void
}