#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 */
scalar_t__ getUnsignedChar(unsigned char *, int, unsigned char *);
int getUnsignedShort(unsigned char *rawBuff, int iStartBit,
                     unsigned int *puiVal) {
  unsigned char ucVal;
  unsigned char ucNextByte;
  ucVal = 0, ucNextByte = 0;
  iStartBit += getUnsignedChar(rawBuff, iStartBit, &ucVal);
  *puiVal = ucVal << 8;
  ucVal = 0;
  ucNextByte = iStartBit / 8, iStartBit = iStartBit % 8;
  iStartBit += getUnsignedChar(rawBuff + ucNextByte, iStartBit, &ucVal);
  *puiVal |= ucVal;
  return 16;
}


x86 assembly (clang, -O0):
<getUnsignedShort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movb   $0x0,-0x1a(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x19(%rbp),%rdx
call   1030 <getUnsignedChar@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
movzbl -0x19(%rbp),%ecx
shl    $0x8,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movb   $0x0,-0x19(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %al,-0x1a(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
movzbl -0x1a(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0xc(%rbp),%esi
lea    -0x19(%rbp),%rdx
call   1030 <getUnsignedChar@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
movzbl -0x19(%rbp),%ecx
mov    -0x18(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    $0x10,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getUnsignedShort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r12
movb   $0x0,0x7(%rsp)
lea    0x7(%rsp),%r14
mov    %r14,%rdx
call   1030 <getUnsignedChar@plt>
movzbl 0x7(%rsp),%ecx
shl    $0x8,%ecx
mov    %ecx,(%r15)
movb   $0x0,0x7(%rsp)
lea    (%rax,%rbx,1),%esi
add    %ebx,%eax
add    $0x7,%eax
test   %esi,%esi
cmovns %esi,%eax
mov    %eax,%ecx
and    $0xfffffff8,%ecx
sub    %ecx,%esi
sar    $0x3,%eax
movzbl %al,%edi
add    %r12,%rdi
mov    %r14,%rdx
call   1030 <getUnsignedChar@plt>
movzbl 0x7(%rsp),%eax
or     %eax,(%r15)
mov    $0x10,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @getUnsignedShort(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8
%8 = alloca i8
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i8 0, i8* %7
store i8 0, i8* %8
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = call i64 @getUnsignedChar(i8* %9, i32 %10, i8* %7)
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = add nsw i64 %13, %11
%15 = trunc i64 %14 to i32
store i32 %15, i32* %5
%16 = load i8, i8* %7
%17 = zext i8 %16 to i32
%18 = shl i32 %17, 8
%19 = load i32*, i32** %6
store i32 %18, i32* %19
store i8 0, i8* %7
%20 = load i32, i32* %5
%21 = sdiv i32 %20, 8
%22 = trunc i32 %21 to i8
store i8 %22, i8* %8
%23 = load i32, i32* %5
%24 = srem i32 %23, 8
store i32 %24, i32* %5
%25 = load i8*, i8** %4
%26 = load i8, i8* %8
%27 = zext i8 %26 to i32
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = load i32, i32* %5
%31 = call i64 @getUnsignedChar(i8* %29, i32 %30, i8* %7)
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = add nsw i64 %33, %31
%35 = trunc i64 %34 to i32
store i32 %35, i32* %5
%36 = load i8, i8* %7
%37 = zext i8 %36 to i32
%38 = load i32*, i32** %6
%39 = load i32, i32* %38
%40 = or i32 %39, %37
store i32 %40, i32* %38
ret i32 16
}

LLVM IR (-O2):
define i32 @getUnsignedShort(i8* %0, i32 %1, i32* nocapture %2) {
%4 = alloca i8
store i8 0, i8* %4
%5 = call i64 @getUnsignedChar(i8* %0, i32 %1, i8* %4)
%6 = trunc i64 %5 to i32
%7 = add i32 %6, %1
%8 = load i8, i8* %4
%9 = zext i8 %8 to i32
%10 = shl nuw nsw i32 %9, 8
store i32 %10, i32* %2
store i8 0, i8* %4
%11 = sdiv i32 %7, 8
%12 = srem i32 %7, 8
%13 = and i32 %11, 255
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = call i64 @getUnsignedChar(i8* %15, i32 %12, i8* %4)
%17 = load i8, i8* %4
%18 = zext i8 %17 to i32
%19 = load i32, i32* %2
%20 = or i32 %19, %18
store i32 %20, i32* %2
ret i32 16
}