#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 /*<<< orphan*/ uint8_t;
typedef int uint32_t;
typedef int uint16_t;

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


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

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

LLVM IR (-O0):
define i32 @__unserialize_uint32(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, 4
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_uint16(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 2
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 2
%26 = call i32 @__unserialize_uint16(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, 16
%33 = and i32 %32, -65536
%34 = load i32, i32* %10
%35 = or i32 %33, %34
%36 = load i32*, i32** %5
store i32 %35, i32* %36
store i32 4, 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_uint32(i32* nocapture writeonly %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = icmp slt i32 %2, 4
br i1 %6, label %24, label %7
7: ; preds = %3
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i32 @__unserialize_uint16(i32* %5, i32* %1, i32 %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %22, label %12
12: ; preds = %7
%13 = getelementptr inbounds i32, i32* %1, i64 2
%14 = add nsw i32 %2, -2
%15 = call i32 @__unserialize_uint16(i32* %4, i32* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load i32, i32* %4
%19 = shl i32 %18, 16
%20 = load i32, i32* %5
%21 = or i32 %19, %20
store i32 %21, i32* %0
br label %22
22: ; preds = %7, %12, %17
%23 = phi i32 [ 4, %17 ], [ -1, %12 ], [ -1, %7 ]
br label %24
24: ; preds = %3, %22
%25 = phi i32 [ %23, %22 ], [ -1, %3 ]
ret i32 %25
}