#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 uint64_t;
typedef int uint32_t;

/* Variables and functions */
int __unserialize_uint32(int *, int /*<<< orphan*/ const *, int);
int __unserialize_uint64(uint64_t *out, const uint8_t *data, int s) {
  if (s < 8)
    return (-1);
  int rc;
  uint32_t l, r;
  rc = __unserialize_uint32(&r, data, s);
  {
    if (rc == -1)
      goto failure;
  };
  rc = __unserialize_uint32(&l, data + 4, s - 4);
  {
    if (rc == -1)
      goto failure;
  };
  *out = ((((uint64_t)l << 32) & 0xFFFFFFFF00000000) | r);
  return (8);
failure:
  return (-1);
}


x86 assembly (clang, -O0):
<__unserialize_uint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    1139 <__unserialize_uint64+0x29>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <__unserialize_uint64+0xaf>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rdi
call   1030 <__unserialize_uint32@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    115b <__unserialize_uint64+0x4b>
jmp    11b8 <__unserialize_uint64+0xa8>
mov    -0x18(%rbp),%rsi
add    $0x10,%rsi
mov    -0x1c(%rbp),%edx
sub    $0x4,%edx
lea    -0x24(%rbp),%rdi
call   1030 <__unserialize_uint32@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1184 <__unserialize_uint64+0x74>
jmp    11b8 <__unserialize_uint64+0xa8>
mov    -0x24(%rbp),%eax
mov    $0x20,%ecx
shl    %cl,%eax
cltq
movabs $0xffffffff00000000,%rcx
ff ff ff
and    %rcx,%rax
movslq -0x28(%rbp),%rcx
or     %rcx,%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x8,-0x4(%rbp)
jmp    11bf <__unserialize_uint64+0xaf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__unserialize_uint64>:
mov    $0xffffffff,%eax
cmp    $0x8,%edx
jl     115e <__unserialize_uint64+0x4e>
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rsp,%rdi
call   1030 <__unserialize_uint32@plt>
cmp    $0xffffffff,%eax
je     1152 <__unserialize_uint64+0x42>
add    $0x10,%r14
add    $0xfffffffc,%ebx
lea    0x4(%rsp),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <__unserialize_uint32@plt>
mov    %eax,%ecx
mov    $0x8,%eax
cmp    $0xffffffff,%ecx
jne    1157 <__unserialize_uint64+0x47>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @__unserialize_uint64(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, 8
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %41
14: ; preds = %3
%15 = load i32*, i32** %6
%16 = load i32, i32* %7
%17 = call i32 @__unserialize_uint32(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 %40
21: ; preds = %14
%22 = load i32*, i32** %6
%23 = getelementptr inbounds i32, i32* %22, i64 4
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 4
%26 = call i32 @__unserialize_uint32(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 %40
30: ; preds = %21
%31 = load i32, i32* %9
%32 = shl i32 %31, 32
%33 = sext i32 %32 to i64
%34 = and i64 %33, -4294967296
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = or i64 %34, %36
%38 = trunc i64 %37 to i32
%39 = load i32*, i32** %5
store i32 %38, i32* %39
store i32 8, i32* %4
br label %41
40: ; preds = %29, %20
store i32 -1, i32* %4
br label %41
41: ; preds = %40, %30, %13
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
define i32 @__unserialize_uint64(i32* nocapture readnone %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = icmp slt i32 %2, 8
br i1 %6, label %20, label %7
7: ; preds = %3
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i32 @__unserialize_uint32(i32* %5, i32* %1, i32 %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = getelementptr inbounds i32, i32* %1, i64 4
%14 = add nsw i32 %2, -4
%15 = call i32 @__unserialize_uint32(i32* %4, i32* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %12, %7
br label %18
18: ; preds = %12, %17
%19 = phi i32 [ -1, %17 ], [ 8, %12 ]
br label %20
20: ; preds = %3, %18
%21 = phi i32 [ %19, %18 ], [ -1, %3 ]
ret i32 %21
}