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

/* Variables and functions */
int i2c_read(int, int *, int);
int i2c_read_word(int file_handle, uint16_t *destination) {
  uint8_t bytes_received[2];
  int16_t return_value = i2c_read(file_handle, bytes_received, 2);
  if (return_value < 0)
    return -1;
  else if (return_value != 2)
    return -1;
  else {
    *destination = ((bytes_received[0] << 8) + bytes_received[1]);
    return 0;
  }
}


x86 assembly (clang, -O0):
<i2c_read_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1030 <i2c_read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1149 <i2c_read_word+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1175 <i2c_read_word+0x65>
cmpl   $0x2,-0x1c(%rbp)
je     115f <i2c_read_word+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1175 <i2c_read_word+0x65>
mov    -0x18(%rbp),%ecx
shl    $0x8,%ecx
add    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_read_word>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
mov    $0x2,%edx
call   1030 <i2c_read@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x2,%ecx
jne    1142 <i2c_read_word+0x32>
mov    0x8(%rsp),%eax
shl    $0x8,%eax
add    0xc(%rsp),%eax
mov    %eax,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @i2c_read_word(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [2 x i32]
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%8 = load i32, i32* %4
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%10 = call i32 @i2c_read(i32 %8, i32* %9, i32 2)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %26
14: ; preds = %2
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 -1, i32* %3
br label %26
18: ; preds = %14
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%20 = load i32, i32* %19
%21 = shl i32 %20, 8
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%23 = load i32, i32* %22
%24 = add nsw i32 %21, %23
%25 = load i32*, i32** %5
store i32 %24, i32* %25
store i32 0, i32* %3
br label %26
26: ; preds = %18, %17, %13
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @i2c_read_word(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i32 @i2c_read(i32 %0, i32* %5, i32 2)
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* %5
%10 = shl i32 %9, 8
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%12 = load i32, i32* %11
%13 = add nsw i32 %10, %12
store i32 %13, i32* %1
br label %14
14: ; preds = %2, %8
%15 = phi i32 [ 0, %8 ], [ -1, %2 ]
ret i32 %15
}