#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*/ v;
typedef int uint8_t;
typedef int uint64_t;

/* Variables and functions */
int fill_size(int *, int);
int encode_uint64(uint64_t v, uint8_t *data, int size) {
  if (size < 4 + sizeof(v))
    return -1;
  data[4] = v & 0xff;
  data[5] = (v >> 8) & 0xff;
  data[6] = (v >> 16) & 0xff;
  data[7] = (v >> 24) & 0xff;
  data[8] = (v >> 32) & 0xff;
  data[9] = (v >> 40) & 0xff;
  data[10] = (v >> 48) & 0xff;
  data[11] = (v >> 56) & 0xff;
  return fill_size(data, sizeof(v));
}


x86 assembly (clang, -O0):
<encode_uint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x8,%rax
jae    113c <encode_uint64+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fa <encode_uint64+0xea>
mov    -0x8(%rbp),%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x8(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x8(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x8(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x1c(%rax)
mov    -0x8(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    -0x8(%rbp),%eax
mov    $0x28,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x24(%rax)
mov    -0x8(%rbp),%eax
mov    $0x30,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    -0x8(%rbp),%eax
mov    $0x38,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x2c(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1030 <fill_size@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_uint64>:
cmp    $0x8,%edx
jae    111b <encode_uint64+0xb>
mov    $0xffffffff,%eax
ret
mov    %edi,%eax
movzbl %al,%ecx
mov    %ecx,0x10(%rsi)
movzbl %ah,%ecx
mov    %ecx,0x14(%rsi)
mov    %edi,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ecx,0x18(%rsi)
shr    $0x18,%eax
mov    %eax,0x1c(%rsi)
mov    %rsi,%rdi
mov    $0x4,%esi
jmp    1030 <fill_size@plt>

LLVM IR (-O0):
define i32 @encode_uint64(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = sext i32 %8 to i64
%10 = icmp ult i64 %9, 8
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 -1, i32* %4
br label %54
12: ; preds = %3
%13 = load i32, i32* %5
%14 = and i32 %13, 255
%15 = load i32*, i32** %6
%16 = getelementptr inbounds i32, i32* %15, i64 4
store i32 %14, i32* %16
%17 = load i32, i32* %5
%18 = ashr i32 %17, 8
%19 = and i32 %18, 255
%20 = load i32*, i32** %6
%21 = getelementptr inbounds i32, i32* %20, i64 5
store i32 %19, i32* %21
%22 = load i32, i32* %5
%23 = ashr i32 %22, 16
%24 = and i32 %23, 255
%25 = load i32*, i32** %6
%26 = getelementptr inbounds i32, i32* %25, i64 6
store i32 %24, i32* %26
%27 = load i32, i32* %5
%28 = ashr i32 %27, 24
%29 = and i32 %28, 255
%30 = load i32*, i32** %6
%31 = getelementptr inbounds i32, i32* %30, i64 7
store i32 %29, i32* %31
%32 = load i32, i32* %5
%33 = ashr i32 %32, 32
%34 = and i32 %33, 255
%35 = load i32*, i32** %6
%36 = getelementptr inbounds i32, i32* %35, i64 8
store i32 %34, i32* %36
%37 = load i32, i32* %5
%38 = ashr i32 %37, 40
%39 = and i32 %38, 255
%40 = load i32*, i32** %6
%41 = getelementptr inbounds i32, i32* %40, i64 9
store i32 %39, i32* %41
%42 = load i32, i32* %5
%43 = ashr i32 %42, 48
%44 = and i32 %43, 255
%45 = load i32*, i32** %6
%46 = getelementptr inbounds i32, i32* %45, i64 10
store i32 %44, i32* %46
%47 = load i32, i32* %5
%48 = ashr i32 %47, 56
%49 = and i32 %48, 255
%50 = load i32*, i32** %6
%51 = getelementptr inbounds i32, i32* %50, i64 11
store i32 %49, i32* %51
%52 = load i32*, i32** %6
%53 = call i32 @fill_size(i32* %52, i32 4)
store i32 %53, i32* %4
br label %54
54: ; preds = %12, %11
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
define i32 @encode_uint64(i32 %0, i32* %1, i32 %2) {
%4 = icmp ult i32 %2, 8
br i1 %4, label %17, label %5
5: ; preds = %3
%6 = and i32 %0, 255
%7 = getelementptr inbounds i32, i32* %1, i64 4
store i32 %6, i32* %7
%8 = lshr i32 %0, 8
%9 = and i32 %8, 255
%10 = getelementptr inbounds i32, i32* %1, i64 5
store i32 %9, i32* %10
%11 = lshr i32 %0, 16
%12 = and i32 %11, 255
%13 = getelementptr inbounds i32, i32* %1, i64 6
store i32 %12, i32* %13
%14 = lshr i32 %0, 24
%15 = getelementptr inbounds i32, i32* %1, i64 7
store i32 %14, i32* %15
%16 = tail call i32 @fill_size(i32* %1, i32 4)
br label %17
17: ; preds = %3, %5
%18 = phi i32 [ %16, %5 ], [ -1, %3 ]
ret i32 %18
}