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

/* Variables and functions */
int twi_read();
int /*<<< orphan*/ twi_start();
int /*<<< orphan*/ twi_stop();
int /*<<< orphan*/ twi_write(int);
uint16_t twi_read_2byte(uint8_t addr) {
  uint32_t tmp;
  twi_start();
  twi_write(addr << 1);
  twi_write(0x00);
  twi_stop();
  twi_start();
  twi_write((addr << 1) | 0x1);
  tmp = twi_read();
  tmp = (tmp << 8) | twi_read();
  twi_stop();
  return (tmp & 0xffff);
}


x86 assembly (clang, -O0):
<twi_read_2byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <twi_start@plt>
mov    -0x4(%rbp),%edi
shl    $0x1,%edi
call   1040 <twi_write@plt>
xor    %edi,%edi
call   1040 <twi_write@plt>
mov    $0x0,%al
call   1050 <twi_stop@plt>
mov    $0x0,%al
call   1030 <twi_start@plt>
mov    -0x4(%rbp),%edi
shl    $0x1,%edi
or     $0x1,%edi
call   1040 <twi_write@plt>
mov    $0x0,%al
call   1060 <twi_read@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1060 <twi_read@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <twi_stop@plt>
mov    -0x8(%rbp),%eax
and    $0xffff,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twi_read_2byte>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <twi_start@plt>
lea    (%rbx,%rbx,1),%edi
call   1040 <twi_write@plt>
xor    %edi,%edi
call   1040 <twi_write@plt>
xor    %eax,%eax
call   1050 <twi_stop@plt>
xor    %eax,%eax
call   1030 <twi_start@plt>
lea    (%rbx,%rbx,1),%edi
add    $0x1,%edi
call   1040 <twi_write@plt>
xor    %eax,%eax
call   1060 <twi_read@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
xor    %eax,%eax
call   1060 <twi_read@plt>
mov    %eax,%ebp
or     %ebx,%ebp
xor    %eax,%eax
call   1050 <twi_stop@plt>
movzwl %bp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @twi_read_2byte(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 (...) @twi_start()
%5 = load i32, i32* %2
%6 = shl i32 %5, 1
%7 = call i32 @twi_write(i32 %6)
%8 = call i32 @twi_write(i32 0)
%9 = call i32 (...) @twi_stop()
%10 = call i32 (...) @twi_start()
%11 = load i32, i32* %2
%12 = shl i32 %11, 1
%13 = or i32 %12, 1
%14 = call i32 @twi_write(i32 %13)
%15 = call i32 (...) @twi_read()
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = shl i32 %16, 8
%18 = call i32 (...) @twi_read()
%19 = or i32 %17, %18
store i32 %19, i32* %3
%20 = call i32 (...) @twi_stop()
%21 = load i32, i32* %3
%22 = and i32 %21, 65535
ret i32 %22
}

LLVM IR (-O2):
define i32 @twi_read_2byte(i32 %0) {
%2 = tail call i32 (...) @twi_start()
%3 = shl i32 %0, 1
%4 = tail call i32 @twi_write(i32 %3)
%5 = tail call i32 @twi_write(i32 0)
%6 = tail call i32 (...) @twi_stop()
%7 = tail call i32 (...) @twi_start()
%8 = or i32 %3, 1
%9 = tail call i32 @twi_write(i32 %8)
%10 = tail call i32 (...) @twi_read()
%11 = shl i32 %10, 8
%12 = tail call i32 (...) @twi_read()
%13 = or i32 %11, %12
%14 = tail call i32 (...) @twi_stop()
%15 = and i32 %13, 65535
ret i32 %15
}