#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;

/* Variables and functions */
int __unserialize_uint8(int *, int const *, int);
int __unserialize_uint16(uint16_t *out, const uint8_t *data, int s) {
  if (s < 2)
    return (-1);
  int rc;
  uint8_t l, r;
  rc = __unserialize_uint8(&r, data, s);
  {
    if (rc == -1)
      goto failure;
  };
  rc = __unserialize_uint8(&l, data + 1, s - 1);
  {
    if (rc == -1)
      goto failure;
  };
  *out = (uint16_t)((((uint16_t)l << 8) & 0xFF00) | r);
  return (2);
failure:
  return (-1);
}


x86 assembly (clang, -O0):
<__unserialize_uint16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    1139 <__unserialize_uint16+0x29>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <__unserialize_uint16+0x9c>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rdi
call   1030 <__unserialize_uint8@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    115b <__unserialize_uint16+0x4b>
jmp    11a5 <__unserialize_uint16+0x95>
mov    -0x18(%rbp),%rsi
add    $0x4,%rsi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
lea    -0x24(%rbp),%rdi
call   1030 <__unserialize_uint8@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1184 <__unserialize_uint16+0x74>
jmp    11a5 <__unserialize_uint16+0x95>
mov    -0x24(%rbp),%ecx
shl    $0x8,%ecx
and    $0xff00,%ecx
or     -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x2,-0x4(%rbp)
jmp    11ac <__unserialize_uint16+0x9c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__unserialize_uint16>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r15d
cmp    $0x2,%edx
jl     116e <__unserialize_uint16+0x5e>
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %rsp,%rdi
call   1030 <__unserialize_uint8@plt>
mov    $0xffffffff,%r15d
cmp    $0xffffffff,%eax
je     116e <__unserialize_uint16+0x5e>
add    $0x4,%rbp
add    $0xffffffff,%ebx
lea    0x4(%rsp),%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <__unserialize_uint8@plt>
cmp    $0xffffffff,%eax
je     116e <__unserialize_uint16+0x5e>
mov    0x4(%rsp),%eax
shl    $0x8,%eax
movzwl %ax,%eax
or     (%rsp),%eax
mov    %eax,(%r14)
mov    $0x2,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @__unserialize_uint16(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %38
14: ; preds = %3
%15 = load i32*, i32** %6
%16 = load i32, i32* %7
%17 = call i32 @__unserialize_uint8(i32* %10, i32* %15, i32 %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %14
br label %37
21: ; preds = %14
%22 = load i32*, i32** %6
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 1
%26 = call i32 @__unserialize_uint8(i32* %9, i32* %23, i32 %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %21
br label %37
30: ; preds = %21
%31 = load i32, i32* %9
%32 = shl i32 %31, 8
%33 = and i32 %32, 65280
%34 = load i32, i32* %10
%35 = or i32 %33, %34
%36 = load i32*, i32** %5
store i32 %35, i32* %36
store i32 2, i32* %4
br label %38
37: ; preds = %29, %20
store i32 -1, i32* %4
br label %38
38: ; preds = %37, %30, %13
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
define i32 @__unserialize_uint16(i32* nocapture writeonly %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = icmp slt i32 %2, 2
br i1 %6, label %25, label %7
7: ; preds = %3
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i32 @__unserialize_uint8(i32* %5, i32* %1, i32 %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %23, label %12
12: ; preds = %7
%13 = getelementptr inbounds i32, i32* %1, i64 1
%14 = add nsw i32 %2, -1
%15 = call i32 @__unserialize_uint8(i32* %4, i32* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %23, label %17
17: ; preds = %12
%18 = load i32, i32* %4
%19 = shl i32 %18, 8
%20 = and i32 %19, 65280
%21 = load i32, i32* %5
%22 = or i32 %20, %21
store i32 %22, i32* %0
br label %23
23: ; preds = %7, %12, %17
%24 = phi i32 [ 2, %17 ], [ -1, %12 ], [ -1, %7 ]
br label %25
25: ; preds = %3, %23
%26 = phi i32 [ %24, %23 ], [ -1, %3 ]
ret i32 %26
}