#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 */
unsigned int iic_read_m();
int /*<<< orphan*/ iic_write_m(unsigned char);
int /*<<< orphan*/ start();
int /*<<< orphan*/ stop();
unsigned int ina_read(unsigned char addr, unsigned char reg) {
  unsigned int dat;
  start();
  iic_write_m(addr);
  iic_write_m(reg);
  stop();
  start();
  iic_write_m(addr + 1);
  dat = iic_read_m();
  dat <<= 8;
  dat |= iic_read_m();
  stop();
  return dat;
}


x86 assembly (clang, -O0):
<ina_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
mov    $0x0,%al
call   1050 <start@plt>
movzbl -0x1(%rbp),%edi
call   1030 <iic_write_m@plt>
movzbl -0x2(%rbp),%edi
call   1030 <iic_write_m@plt>
mov    $0x0,%al
call   1040 <stop@plt>
mov    $0x0,%al
call   1050 <start@plt>
movzbl -0x1(%rbp),%eax
add    $0x1,%eax
movzbl %al,%edi
call   1030 <iic_write_m@plt>
mov    $0x0,%al
call   1060 <iic_read_m@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1060 <iic_read_m@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <stop@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ina_read>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <start@plt>
mov    %ebx,%edi
call   1030 <iic_write_m@plt>
mov    %ebp,%edi
call   1030 <iic_write_m@plt>
xor    %eax,%eax
call   1040 <stop@plt>
xor    %eax,%eax
call   1050 <start@plt>
lea    0x1(%rbx),%eax
movzbl %al,%edi
call   1030 <iic_write_m@plt>
xor    %eax,%eax
call   1060 <iic_read_m@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
xor    %eax,%eax
call   1060 <iic_read_m@plt>
mov    %eax,%ebp
or     %ebx,%ebp
xor    %eax,%eax
call   1040 <stop@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ina_read(i8 zeroext %0, i8 zeroext %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
store i8 %0, i8* %3
store i8 %1, i8* %4
%6 = call i32 (...) @start()
%7 = load i8, i8* %3
%8 = call i32 @iic_write_m(i8 zeroext %7)
%9 = load i8, i8* %4
%10 = call i32 @iic_write_m(i8 zeroext %9)
%11 = call i32 (...) @stop()
%12 = call i32 (...) @start()
%13 = load i8, i8* %3
%14 = zext i8 %13 to i32
%15 = add nsw i32 %14, 1
%16 = trunc i32 %15 to i8
%17 = call i32 @iic_write_m(i8 zeroext %16)
%18 = call i32 (...) @iic_read_m()
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = shl i32 %19, 8
store i32 %20, i32* %5
%21 = call i32 (...) @iic_read_m()
%22 = load i32, i32* %5
%23 = or i32 %22, %21
store i32 %23, i32* %5
%24 = call i32 (...) @stop()
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
define i32 @ina_read(i8 zeroext %0, i8 zeroext %1) {
%3 = tail call i32 (...) @start()
%4 = tail call i32 @iic_write_m(i8 zeroext %0)
%5 = tail call i32 @iic_write_m(i8 zeroext %1)
%6 = tail call i32 (...) @stop()
%7 = tail call i32 (...) @start()
%8 = add i8 %0, 1
%9 = tail call i32 @iic_write_m(i8 zeroext %8)
%10 = tail call i32 (...) @iic_read_m()
%11 = shl i32 %10, 8
%12 = tail call i32 (...) @iic_read_m()
%13 = or i32 %11, %12
%14 = tail call i32 (...) @stop()
ret i32 %13
}