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

/* Variables and functions */
int fill_size(int *, int);
int encode_integer(uint32_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;
  return fill_size(data, sizeof(v));
}


x86 assembly (clang, -O0):
<encode_integer>:
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_integer+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <encode_integer+0x86>
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    -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_integer>:
cmp    $0x8,%edx
jae    111b <encode_integer+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_integer(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 %34
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** %6
%33 = call i32 @fill_size(i32* %32, i32 4)
store i32 %33, i32* %4
br label %34
34: ; preds = %12, %11
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @encode_integer(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
}