#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 /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int write_u32_to_buf(uint8_t **ptr, uint32_t val) {
  *(*ptr)++ = (val >> 24) & 0xff;
  *(*ptr)++ = (val >> 16) & 0xff;
  *(*ptr)++ = (val >> 8) & 0xff;
  *(*ptr)++ = val & 0xff;
  return 4;
}


x86 assembly (clang, -O0):
<write_u32_to_buf>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x4,%rsi
mov    %rsi,(%rdx)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x4,%rsi
mov    %rsi,(%rdx)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x4,%rsi
mov    %rsi,(%rdx)
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x4,%rsi
mov    %rsi,(%rdx)
mov    %ecx,(%rax)
mov    $0x4,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_u32_to_buf>:
push   %rbx
mov    %esi,%eax
mov    %esi,%ecx
movzbl %ah,%ebx
movzbl %al,%esi
shr    $0x18,%eax
mov    (%rdi),%rdx
mov    %eax,(%rdx)
shr    $0x10,%ecx
movzbl %cl,%eax
mov    %eax,0x4(%rdx)
mov    %ebx,0x8(%rdx)
lea    0x10(%rdx),%rax
mov    %rax,(%rdi)
mov    %esi,0xc(%rdx)
mov    $0x4,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @write_u32_to_buf(i32** %0, i32 %1) {
%3 = alloca i32**
%4 = alloca i32
store i32** %0, i32*** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = ashr i32 %5, 24
%7 = and i32 %6, 255
%8 = load i32**, i32*** %3
%9 = load i32*, i32** %8
%10 = getelementptr inbounds i32, i32* %9, i32 1
store i32* %10, i32** %8
store i32 %7, i32* %9
%11 = load i32, i32* %4
%12 = ashr i32 %11, 16
%13 = and i32 %12, 255
%14 = load i32**, i32*** %3
%15 = load i32*, i32** %14
%16 = getelementptr inbounds i32, i32* %15, i32 1
store i32* %16, i32** %14
store i32 %13, i32* %15
%17 = load i32, i32* %4
%18 = ashr i32 %17, 8
%19 = and i32 %18, 255
%20 = load i32**, i32*** %3
%21 = load i32*, i32** %20
%22 = getelementptr inbounds i32, i32* %21, i32 1
store i32* %22, i32** %20
store i32 %19, i32* %21
%23 = load i32, i32* %4
%24 = and i32 %23, 255
%25 = load i32**, i32*** %3
%26 = load i32*, i32** %25
%27 = getelementptr inbounds i32, i32* %26, i32 1
store i32* %27, i32** %25
store i32 %24, i32* %26
ret i32 4
}

LLVM IR (-O2):
define i32 @write_u32_to_buf(i32** nocapture %0, i32 %1) {
%3 = lshr i32 %1, 24
%4 = load i32*, i32** %0
%5 = getelementptr inbounds i32, i32* %4, i64 1
store i32 %3, i32* %4
%6 = lshr i32 %1, 16
%7 = and i32 %6, 255
%8 = getelementptr inbounds i32, i32* %4, i64 2
store i32 %7, i32* %5
%9 = lshr i32 %1, 8
%10 = and i32 %9, 255
%11 = getelementptr inbounds i32, i32* %4, i64 3
store i32 %10, i32* %8
%12 = and i32 %1, 255
%13 = getelementptr inbounds i32, i32* %4, i64 4
store i32* %13, i32** %0
store i32 %12, i32* %11
ret i32 4
}