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

/* Variables and functions */
int fill_size(uint8_t *data, int sz) {
  if (sz < 0)
    return -1;
  if (sz == 0)
    return 0;
  data[0] = sz & 0xff;
  data[1] = (sz >> 8) & 0xff;
  data[2] = (sz >> 16) & 0xff;
  data[3] = (sz >> 24) & 0xff;
  return sz + 4;
}


x86 assembly (clang, -O0):
<fill_size>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1121 <fill_size+0x21>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <fill_size+0x88>
cmpl   $0x0,-0x14(%rbp)
jne    1137 <fill_size+0x37>
movl   $0x0,-0x4(%rbp)
jmp    1188 <fill_size+0x88>
mov    -0x14(%rbp),%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_size>:
test   %esi,%esi
js     112a <fill_size+0x2a>
je     1130 <fill_size+0x30>
mov    %esi,%eax
movzbl %al,%ecx
mov    %ecx,(%rdi)
movzbl %ah,%ecx
mov    %ecx,0x4(%rdi)
mov    %esi,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ecx,0x8(%rdi)
mov    %esi,%ecx
shr    $0x18,%ecx
mov    %ecx,0xc(%rdi)
add    $0x4,%eax
ret
mov    $0xffffffff,%eax
ret
xor    %eax,%eax
ret

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

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