#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 /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ i;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                          size_t);
uint64_t _ProtoBufFixed(const uint8_t *buf, size_t bufLen, size_t *off,
                        size_t size) {
  uint64_t i = 0;
  if (buf && *off + size <= bufLen && size <= sizeof(i))
    memcpy(&i, &buf[*off], size);
  *off += size;
  return i;
}


x86 assembly (clang, -O0):
<_ProtoBufFixed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1179 <_ProtoBufFixed+0x69>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
add    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     1179 <_ProtoBufFixed+0x69>
cmpq   $0x4,-0x20(%rbp)
ja     1179 <_ProtoBufFixed+0x69>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rdi
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ProtoBufFixed>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
test   %rdi,%rdi
je     1150 <_ProtoBufFixed+0x40>
cmp    $0x4,%rbx
ja     1150 <_ProtoBufFixed+0x40>
mov    (%r14),%rcx
lea    (%rcx,%rbx,1),%rdx
cmp    %rsi,%rdx
ja     1150 <_ProtoBufFixed+0x40>
lea    (%rdi,%rcx,4),%rsi
lea    0x4(%rsp),%rdi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
mov    0x4(%rsp),%eax
add    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @_ProtoBufFixed(i32* %0, i64 %1, i64* %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64* %2, i64** %7
store i64 %3, i64* %8
store i32 0, i32* %9
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %29
12: ; preds = %4
%13 = load i64*, i64** %7
%14 = load i64, i64* %13
%15 = load i64, i64* %8
%16 = add i64 %14, %15
%17 = load i64, i64* %6
%18 = icmp ule i64 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %12
%20 = load i64, i64* %8
%21 = icmp ule i64 %20, 4
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32*, i32** %5
%24 = load i64*, i64** %7
%25 = load i64, i64* %24
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i64, i64* %8
%28 = call i32 @memcpy(i32* %9, i32* %26, i64 %27)
br label %29
29: ; preds = %22, %19, %12, %4
%30 = load i64, i64* %8
%31 = load i64*, i64** %7
%32 = load i64, i64* %31
%33 = add i64 %32, %30
store i64 %33, i64* %31
%34 = load i32, i32* %9
ret i32 %34
}

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