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

/* Variables and functions */
void write_word(uint32_t val, uint8_t *buf, int offset) {
  buf[offset + 0] = val & 0xff;
  buf[offset + 1] = (val >> 8) & 0xff;
  buf[offset + 2] = (val >> 16) & 0xff;
  buf[offset + 3] = (val >> 24) & 0xff;
}


x86 assembly (clang, -O0):
<write_word>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edx
and    $0xff,%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4(%rbp),%edx
sar    $0x10,%edx
and    $0xff,%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4(%rbp),%edx
sar    $0x18,%edx
and    $0xff,%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_word>:
mov    %edi,%eax
movzbl %al,%ecx
movslq %edx,%rdx
mov    %ecx,(%rsi,%rdx,4)
movzbl %ah,%ecx
mov    %ecx,0x4(%rsi,%rdx,4)
mov    %edi,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ecx,0x8(%rsi,%rdx,4)
shr    $0x18,%eax
mov    %eax,0xc(%rsi,%rdx,4)
ret

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

LLVM IR (-O2):
define void @write_word(i32 %0, i32* nocapture writeonly %1, i32 %2) {
%4 = and i32 %0, 255
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds i32, i32* %1, i64 %5
store i32 %4, i32* %6
%7 = lshr i32 %0, 8
%8 = and i32 %7, 255
%9 = add nsw i32 %2, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %1, i64 %10
store i32 %8, i32* %11
%12 = lshr i32 %0, 16
%13 = and i32 %12, 255
%14 = add nsw i32 %2, 2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %1, i64 %15
store i32 %13, i32* %16
%17 = lshr i32 %0, 24
%18 = add nsw i32 %2, 3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %1, i64 %19
store i32 %17, i32* %20
ret void
}