#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_Read(int, unsigned short, unsigned char *);
int STC3115_ReadUnsignedWord(unsigned short RegAddress,
                             unsigned short *RegData) {
  unsigned short data16;
  unsigned char data8[2];
  int status;
  status = I2C_Read(2, RegAddress, data8);
  if (status >= 0) {
    data16 = data8[1];
    data16 = (data16 << 8) | data8[0];
    *RegData = data16;
  } else
    status = -1;
  return (status);
}


x86 assembly (clang, -O0):
<STC3115_ReadUnsignedWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x2(%rbp),%ax
lea    -0x14(%rbp),%rdx
mov    $0x2,%edi
movzwl %ax,%esi
call   1030 <I2C_Read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     116e <STC3115_ReadUnsignedWord+0x5e>
movzbl -0x13(%rbp),%eax
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
shl    $0x8,%eax
movzbl -0x14(%rbp),%ecx
or     %ecx,%eax
mov    %ax,-0x12(%rbp)
mov    -0x12(%rbp),%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
jmp    1175 <STC3115_ReadUnsignedWord+0x65>
movl   $0xffffffff,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<STC3115_ReadUnsignedWord>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%esi
lea    0xe(%rsp),%rdx
mov    $0x2,%edi
call   1030 <I2C_Read@plt>
test   %eax,%eax
js     1137 <STC3115_ReadUnsignedWord+0x27>
movzwl 0xe(%rsp),%ecx
mov    %cx,(%rbx)
jmp    113c <STC3115_ReadUnsignedWord+0x2c>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @STC3115_ReadUnsignedWord(i16 zeroext %0, i16* %1) {
%3 = alloca i16
%4 = alloca i16*
%5 = alloca i16
%6 = alloca [2 x i8]
%7 = alloca i32
store i16 %0, i16* %3
store i16* %1, i16** %4
%8 = load i16, i16* %3
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%10 = call i32 @I2C_Read(i32 2, i16 zeroext %8, i8* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %2
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
%15 = load i8, i8* %14
%16 = zext i8 %15 to i16
store i16 %16, i16* %5
%17 = load i16, i16* %5
%18 = zext i16 %17 to i32
%19 = shl i32 %18, 8
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = or i32 %19, %22
%24 = trunc i32 %23 to i16
store i16 %24, i16* %5
%25 = load i16, i16* %5
%26 = load i16*, i16** %4
store i16 %25, i16* %26
br label %28
27: ; preds = %2
store i32 -1, i32* %7
br label %28
28: ; preds = %27, %13
%29 = load i32, i32* %7
ret i32 %29
}

LLVM IR (-O2):
define i32 @STC3115_ReadUnsignedWord(i16 zeroext %0, i16* nocapture writeonly %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = call i32 @I2C_Read(i32 2, i16 zeroext %0, i8* %4)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
%9 = load i8, i8* %8
%10 = zext i8 %9 to i16
%11 = shl nuw i16 %10, 8
%12 = load i8, i8* %4
%13 = zext i8 %12 to i16
%14 = or i16 %11, %13
store i16 %14, i16* %1
br label %15
15: ; preds = %2, %7
%16 = phi i32 [ %5, %7 ], [ -1, %2 ]
ret i32 %16
}