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

/* Variables and functions */
int /*<<< orphan*/ size_buffer(char **, size_t *, size_t);
size_t int16Pack(const int16_t *data, char **buffer, size_t *size,
                 size_t *pos) {
  size_buffer(buffer, size, *pos + sizeof(int16_t));
  (*buffer)[(*pos)++] = (*data & 0xFF00) >> 8;
  (*buffer)[(*pos)++] = (*data & 0x00FF);
  return sizeof(int16_t);
}


x86 assembly (clang, -O0):
<int16Pack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
add    $0x4,%rdx
call   1030 <size_buffer@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rsi
mov    (%rsi),%rcx
mov    %rcx,%rdi
add    $0x1,%rdi
mov    %rdi,(%rsi)
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rsi
mov    (%rsi),%rcx
mov    %rcx,%rdi
add    $0x1,%rdi
mov    %rdi,(%rsi)
mov    %dl,(%rax,%rcx,1)
mov    $0x4,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int16Pack>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rcx),%rax
add    $0x4,%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
call   1030 <size_buffer@plt>
mov    0x1(%r15),%al
mov    (%r14),%rcx
mov    (%rbx),%rdx
lea    0x1(%rdx),%rsi
mov    %rsi,(%rbx)
mov    %al,(%rcx,%rdx,1)
mov    (%r15),%al
mov    (%r14),%rcx
mov    (%rbx),%rdx
lea    0x1(%rdx),%rsi
mov    %rsi,(%rbx)
mov    %al,(%rcx,%rdx,1)
mov    $0x4,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @int16Pack(i32* %0, i8** %1, i64* %2, i64* %3) {
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i64*
store i32* %0, i32** %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
store i64* %3, i64** %8
%9 = load i8**, i8*** %6
%10 = load i64*, i64** %7
%11 = load i64*, i64** %8
%12 = load i64, i64* %11
%13 = add i64 %12, 4
%14 = call i32 @size_buffer(i8** %9, i64* %10, i64 %13)
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = and i32 %16, 65280
%18 = ashr i32 %17, 8
%19 = trunc i32 %18 to i8
%20 = load i8**, i8*** %6
%21 = load i8*, i8** %20
%22 = load i64*, i64** %8
%23 = load i64, i64* %22
%24 = add i64 %23, 1
store i64 %24, i64* %22
%25 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 %19, i8* %25
%26 = load i32*, i32** %5
%27 = load i32, i32* %26
%28 = and i32 %27, 255
%29 = trunc i32 %28 to i8
%30 = load i8**, i8*** %6
%31 = load i8*, i8** %30
%32 = load i64*, i64** %8
%33 = load i64, i64* %32
%34 = add i64 %33, 1
store i64 %34, i64* %32
%35 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %29, i8* %35
ret i64 4
}

LLVM IR (-O2):
define i64 @int16Pack(i32* nocapture %0, i8** %1, i64* %2, i64* nocapture %3) {
%5 = load i64, i64* %3
%6 = add i64 %5, 4
%7 = tail call i32 @size_buffer(i8** %1, i64* %2, i64 %6)
%8 = load i32, i32* %0
%9 = lshr i32 %8, 8
%10 = trunc i32 %9 to i8
%11 = load i8*, i8** %1
%12 = load i64, i64* %3
%13 = add i64 %12, 1
store i64 %13, i64* %3
%14 = getelementptr inbounds i8, i8* %11, i64 %12
store i8 %10, i8* %14
%15 = load i32, i32* %0
%16 = trunc i32 %15 to i8
%17 = load i8*, i8** %1
%18 = load i64, i64* %3
%19 = add i64 %18, 1
store i64 %19, i64* %3
%20 = getelementptr inbounds i8, i8* %17, i64 %18
store i8 %16, i8* %20
ret i64 4
}