#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 scalar_t__ uint8_t;
typedef int uint32_t;

/* Variables and functions */
void pack_add_u32(uint8_t *buffer, int byteNr, uint32_t value) {
  *((uint8_t *)(buffer + byteNr + 3)) = (uint8_t)(value >> 24);
  *((uint8_t *)(buffer + byteNr + 2)) = (uint8_t)(value >> 16);
  *((uint8_t *)(buffer + byteNr + 1)) = (uint8_t)(value >> 8);
  *((uint8_t *)(buffer + byteNr)) = (uint8_t)(value);
}


x86 assembly (clang, -O0):
<pack_add_u32>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x18,%eax
movslq %eax,%rdx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,0x18(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
sar    $0x10,%eax
movslq %eax,%rdx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,0x10(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
sar    $0x8,%eax
movslq %eax,%rdx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,0x8(%rax,%rcx,8)
movslq -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
pop    %rbp
ret

x86 assembly (clang, -O2):
<pack_add_u32>:
mov    %edx,%eax
sar    $0x18,%eax
cltq
movslq %esi,%rcx
mov    %rax,0x18(%rdi,%rcx,8)
mov    %edx,%eax
sar    $0x10,%eax
cltq
mov    %rax,0x10(%rdi,%rcx,8)
movslq %edx,%rax
sar    $0x8,%edx
movslq %edx,%rdx
mov    %rdx,0x8(%rdi,%rcx,8)
mov    %rax,(%rdi,%rcx,8)
ret

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

LLVM IR (-O2):
define void @pack_add_u32(i64* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = ashr i32 %2, 24
%5 = sext i32 %4 to i64
%6 = sext i32 %1 to i64
%7 = getelementptr inbounds i64, i64* %0, i64 %6
%8 = getelementptr inbounds i64, i64* %7, i64 3
store i64 %5, i64* %8
%9 = ashr i32 %2, 16
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i64, i64* %7, i64 2
store i64 %10, i64* %11
%12 = ashr i32 %2, 8
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i64, i64* %7, i64 1
store i64 %13, i64* %14
%15 = sext i32 %2 to i64
store i64 %15, i64* %7
ret void
}