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

/* Variables and functions */
int /*<<< orphan*/ size_buffer(char **, size_t *, size_t);
size_t uint32Pack(const uint32_t *data, char **buffer, size_t *size,
                  size_t *pos) {
  size_buffer(buffer, size, *pos + sizeof(uint32_t));
  (*buffer)[(*pos)++] = (*data >> 24) & 0xFF;
  (*buffer)[(*pos)++] = (*data >> 16) & 0xFF;
  (*buffer)[(*pos)++] = (*data >> 8) & 0xFF;
  (*buffer)[(*pos)++] = (*data >> 0) & 0xFF;
  return sizeof(uint32_t);
}


x86 assembly (clang, -O0):
<uint32Pack>:
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
sar    $0x18,%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    -0x8(%rbp),%rax
mov    (%rax),%eax
sar    $0x10,%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    -0x8(%rbp),%rax
mov    (%rax),%eax
sar    $0x8,%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    -0x8(%rbp),%rax
mov    (%rax),%eax
sar    $0x0,%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):
<uint32Pack>:
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    0x3(%r15),%al
mov    (%r14),%rcx
mov    (%rbx),%rdx
lea    0x1(%rdx),%rsi
mov    %rsi,(%rbx)
mov    %al,(%rcx,%rdx,1)
mov    0x2(%r15),%al
mov    (%r14),%rcx
mov    (%rbx),%rdx
lea    0x1(%rdx),%rsi
mov    %rsi,(%rbx)
mov    %al,(%rcx,%rdx,1)
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 @uint32Pack(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 = ashr i32 %16, 24
%18 = and i32 %17, 255
%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 = ashr i32 %27, 16
%29 = and i32 %28, 255
%30 = trunc i32 %29 to i8
%31 = load i8**, i8*** %6
%32 = load i8*, i8** %31
%33 = load i64*, i64** %8
%34 = load i64, i64* %33
%35 = add i64 %34, 1
store i64 %35, i64* %33
%36 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %30, i8* %36
%37 = load i32*, i32** %5
%38 = load i32, i32* %37
%39 = ashr i32 %38, 8
%40 = and i32 %39, 255
%41 = trunc i32 %40 to i8
%42 = load i8**, i8*** %6
%43 = load i8*, i8** %42
%44 = load i64*, i64** %8
%45 = load i64, i64* %44
%46 = add i64 %45, 1
store i64 %46, i64* %44
%47 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %41, i8* %47
%48 = load i32*, i32** %5
%49 = load i32, i32* %48
%50 = ashr i32 %49, 0
%51 = and i32 %50, 255
%52 = trunc i32 %51 to i8
%53 = load i8**, i8*** %6
%54 = load i8*, i8** %53
%55 = load i64*, i64** %8
%56 = load i64, i64* %55
%57 = add i64 %56, 1
store i64 %57, i64* %55
%58 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 %52, i8* %58
ret i64 4
}

LLVM IR (-O2):
define i64 @uint32Pack(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, 24
%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 = lshr i32 %15, 16
%17 = trunc i32 %16 to i8
%18 = load i8*, i8** %1
%19 = load i64, i64* %3
%20 = add i64 %19, 1
store i64 %20, i64* %3
%21 = getelementptr inbounds i8, i8* %18, i64 %19
store i8 %17, i8* %21
%22 = load i32, i32* %0
%23 = lshr i32 %22, 8
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %1
%26 = load i64, i64* %3
%27 = add i64 %26, 1
store i64 %27, i64* %3
%28 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 %24, i8* %28
%29 = load i32, i32* %0
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %1
%32 = load i64, i64* %3
%33 = add i64 %32, 1
store i64 %33, i64* %3
%34 = getelementptr inbounds i8, i8* %31, i64 %32
store i8 %30, i8* %34
ret i64 4
}