#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 _i2c_get(int);
int /*<<< orphan*/ _i2c_read(unsigned char *, int);
int /*<<< orphan*/ _i2c_set(int, unsigned int);
int /*<<< orphan*/ _i2c_start(unsigned int);
int /*<<< orphan*/ _i2c_stop();
int /*<<< orphan*/ _i2c_wait();
int /*<<< orphan*/ _i2c_write(unsigned char *, int);
void _i2c_write_read(unsigned char *write_buf, int num_write,
                     unsigned char *read_buf, int num_read,
                     unsigned int connector) {
  unsigned int tmp;
  if (num_write) {
    _i2c_start(connector);
    tmp = _i2c_get(0x7d3c) & (~(0xf << 8));
    tmp |= num_write << 8;
    _i2c_set(0x7d3c, tmp);
    tmp = _i2c_get(0x7d40);
    _i2c_set(0x7d40, tmp);
    _i2c_set(0x7d44, 0xA0);
    _i2c_write(write_buf, num_write);
    tmp = _i2c_get(0x7d38) & (~0x7);
    _i2c_set(0x7d38, tmp | (1 << 0) | (1 << 1));
    _i2c_wait();
  }
  if (num_read) {
    _i2c_set(0x7d44, 0xA0 | 1);
    tmp = _i2c_get(0x7d3c) & (~(0xf << 8));
    tmp |= num_read << 8;
    _i2c_set(0x7d3c, tmp);
    tmp = _i2c_get(0x7d38) & (~0x7);
    _i2c_set(0x7d38, tmp | (1 << 0) | (1 << 1) | (1 << 2));
    _i2c_wait();
    _i2c_read(read_buf, num_read);
    _i2c_stop();
  }
}


x86 assembly (clang, -O0):
<_i2c_write_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1226 <_i2c_write_read+0xb6>
mov    -0x20(%rbp),%edi
call   1050 <_i2c_start@plt>
mov    $0x7d3c,%edi
call   1060 <_i2c_get@plt>
and    $0xfffff0ff,%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x8,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
mov    $0x7d3c,%edi
call   1090 <_i2c_set@plt>
mov    $0x7d40,%edi
call   1060 <_i2c_get@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
mov    $0x7d40,%edi
call   1090 <_i2c_set@plt>
mov    $0x7d44,%edi
mov    $0xa0,%esi
call   1090 <_i2c_set@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <_i2c_write@plt>
mov    $0x7d38,%edi
call   1060 <_i2c_get@plt>
and    $0xfffffff8,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
or     $0x1,%esi
or     $0x2,%esi
mov    $0x7d38,%edi
call   1090 <_i2c_set@plt>
mov    $0x0,%al
call   1070 <_i2c_wait@plt>
cmpl   $0x0,-0x1c(%rbp)
je     12aa <_i2c_write_read+0x13a>
mov    $0x7d44,%edi
mov    $0xa1,%esi
call   1090 <_i2c_set@plt>
mov    $0x7d3c,%edi
call   1060 <_i2c_get@plt>
and    $0xfffff0ff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x8,%eax
or     -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
mov    $0x7d3c,%edi
call   1090 <_i2c_set@plt>
mov    $0x7d38,%edi
call   1060 <_i2c_get@plt>
and    $0xfffffff8,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
or     $0x1,%esi
or     $0x2,%esi
or     $0x4,%esi
mov    $0x7d38,%edi
call   1090 <_i2c_set@plt>
mov    $0x0,%al
call   1070 <_i2c_wait@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <_i2c_read@plt>
mov    $0x0,%al
call   1030 <_i2c_stop@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_i2c_write_read>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r14
test   %esi,%esi
je     11fe <_i2c_write_read+0x8e>
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %r8d,%edi
call   1050 <_i2c_start@plt>
mov    $0x7d3c,%edi
call   1060 <_i2c_get@plt>
and    $0xfffff0ff,%eax
mov    %ebp,%esi
shl    $0x8,%esi
or     %eax,%esi
mov    $0x7d3c,%edi
call   1090 <_i2c_set@plt>
mov    $0x7d40,%edi
call   1060 <_i2c_get@plt>
mov    $0x7d40,%edi
mov    %eax,%esi
call   1090 <_i2c_set@plt>
mov    $0x7d44,%edi
mov    $0xa0,%esi
call   1090 <_i2c_set@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <_i2c_write@plt>
mov    $0x7d38,%edi
call   1060 <_i2c_get@plt>
and    $0xfffffff8,%eax
lea    0x3(%rax),%esi
mov    $0x7d38,%edi
call   1090 <_i2c_set@plt>
xor    %eax,%eax
call   1070 <_i2c_wait@plt>
test   %r15d,%r15d
je     126f <_i2c_write_read+0xff>
mov    $0x7d44,%edi
mov    $0xa1,%esi
call   1090 <_i2c_set@plt>
mov    $0x7d3c,%edi
call   1060 <_i2c_get@plt>
and    $0xfffff0ff,%eax
mov    %r15d,%esi
shl    $0x8,%esi
or     %eax,%esi
mov    $0x7d3c,%edi
call   1090 <_i2c_set@plt>
mov    $0x7d38,%edi
call   1060 <_i2c_get@plt>
or     $0x7,%eax
mov    $0x7d38,%edi
mov    %eax,%esi
call   1090 <_i2c_set@plt>
xor    %eax,%eax
call   1070 <_i2c_wait@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   1040 <_i2c_read@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_i2c_stop@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @_i2c_write_read(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %39
14: ; preds = %5
%15 = load i32, i32* %10
%16 = call i32 @_i2c_start(i32 %15)
%17 = call i32 @_i2c_get(i32 32060)
%18 = and i32 %17, -3841
store i32 %18, i32* %11
%19 = load i32, i32* %7
%20 = shl i32 %19, 8
%21 = load i32, i32* %11
%22 = or i32 %21, %20
store i32 %22, i32* %11
%23 = load i32, i32* %11
%24 = call i32 @_i2c_set(i32 32060, i32 %23)
%25 = call i32 @_i2c_get(i32 32064)
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = call i32 @_i2c_set(i32 32064, i32 %26)
%28 = call i32 @_i2c_set(i32 32068, i32 160)
%29 = load i8*, i8** %6
%30 = load i32, i32* %7
%31 = call i32 @_i2c_write(i8* %29, i32 %30)
%32 = call i32 @_i2c_get(i32 32056)
%33 = and i32 %32, -8
store i32 %33, i32* %11
%34 = load i32, i32* %11
%35 = or i32 %34, 1
%36 = or i32 %35, 2
%37 = call i32 @_i2c_set(i32 32056, i32 %36)
%38 = call i32 (...) @_i2c_wait()
br label %39
39: ; preds = %14, %5
%40 = load i32, i32* %9
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %64
42: ; preds = %39
%43 = call i32 @_i2c_set(i32 32068, i32 161)
%44 = call i32 @_i2c_get(i32 32060)
%45 = and i32 %44, -3841
store i32 %45, i32* %11
%46 = load i32, i32* %9
%47 = shl i32 %46, 8
%48 = load i32, i32* %11
%49 = or i32 %48, %47
store i32 %49, i32* %11
%50 = load i32, i32* %11
%51 = call i32 @_i2c_set(i32 32060, i32 %50)
%52 = call i32 @_i2c_get(i32 32056)
%53 = and i32 %52, -8
store i32 %53, i32* %11
%54 = load i32, i32* %11
%55 = or i32 %54, 1
%56 = or i32 %55, 2
%57 = or i32 %56, 4
%58 = call i32 @_i2c_set(i32 32056, i32 %57)
%59 = call i32 (...) @_i2c_wait()
%60 = load i8*, i8** %8
%61 = load i32, i32* %9
%62 = call i32 @_i2c_read(i8* %60, i32 %61)
%63 = call i32 (...) @_i2c_stop()
br label %64
64: ; preds = %42, %39
ret void
}

LLVM IR (-O2):
define void @_i2c_write_read(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %1, 0
br i1 %6, label %23, label %7
7: ; preds = %5
%8 = tail call i32 @_i2c_start(i32 %4)
%9 = tail call i32 @_i2c_get(i32 32060)
%10 = and i32 %9, -3841
%11 = shl i32 %1, 8
%12 = or i32 %10, %11
%13 = tail call i32 @_i2c_set(i32 32060, i32 %12)
%14 = tail call i32 @_i2c_get(i32 32064)
%15 = tail call i32 @_i2c_set(i32 32064, i32 %14)
%16 = tail call i32 @_i2c_set(i32 32068, i32 160)
%17 = tail call i32 @_i2c_write(i8* %0, i32 %1)
%18 = tail call i32 @_i2c_get(i32 32056)
%19 = and i32 %18, -8
%20 = or i32 %19, 3
%21 = tail call i32 @_i2c_set(i32 32056, i32 %20)
%22 = tail call i32 (...) @_i2c_wait()
br label %23
23: ; preds = %7, %5
%24 = icmp eq i32 %3, 0
br i1 %24, label %38, label %25
25: ; preds = %23
%26 = tail call i32 @_i2c_set(i32 32068, i32 161)
%27 = tail call i32 @_i2c_get(i32 32060)
%28 = and i32 %27, -3841
%29 = shl i32 %3, 8
%30 = or i32 %28, %29
%31 = tail call i32 @_i2c_set(i32 32060, i32 %30)
%32 = tail call i32 @_i2c_get(i32 32056)
%33 = or i32 %32, 7
%34 = tail call i32 @_i2c_set(i32 32056, i32 %33)
%35 = tail call i32 (...) @_i2c_wait()
%36 = tail call i32 @_i2c_read(i8* %2, i32 %3)
%37 = tail call i32 (...) @_i2c_stop()
br label %38
38: ; preds = %25, %23
ret void
}