#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 */
uint8_t *write_u32(uint8_t *p, size_t *s, const uint32_t v) {
  *p++ = (v >> 24) & 0xFF;
  *p++ = (v >> 16) & 0xFF;
  *p++ = (v >> 8) & 0xFF;
  *p++ = (v >> 0) & 0xFF;
  if (s != NULL)
    *s -= 4;
  return (p);
}


x86 assembly (clang, -O0):
<write_u32>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x0,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     119c <write_u32+0x9c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
sub    $0x4,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_u32>:
push   %rbx
mov    %rdi,%rax
mov    %edx,%ecx
movzbl %dh,%ebx
movzbl %dl,%edi
shr    $0x18,%edx
mov    %edx,(%rax)
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ecx,0x4(%rax)
mov    %ebx,0x8(%rax)
mov    %edi,0xc(%rax)
test   %rsi,%rsi
je     1129 <write_u32+0x29>
addq   $0xfffffffffffffffc,(%rsi)
add    $0x10,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i32* @write_u32(i32* %0, i64* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i64*
%6 = alloca i32
store i32* %0, i32** %4
store i64* %1, i64** %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = ashr i32 %7, 24
%9 = and i32 %8, 255
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i32 1
store i32* %11, i32** %4
store i32 %9, i32* %10
%12 = load i32, i32* %6
%13 = ashr i32 %12, 16
%14 = and i32 %13, 255
%15 = load i32*, i32** %4
%16 = getelementptr inbounds i32, i32* %15, i32 1
store i32* %16, i32** %4
store i32 %14, i32* %15
%17 = load i32, i32* %6
%18 = ashr i32 %17, 8
%19 = and i32 %18, 255
%20 = load i32*, i32** %4
%21 = getelementptr inbounds i32, i32* %20, i32 1
store i32* %21, i32** %4
store i32 %19, i32* %20
%22 = load i32, i32* %6
%23 = ashr i32 %22, 0
%24 = and i32 %23, 255
%25 = load i32*, i32** %4
%26 = getelementptr inbounds i32, i32* %25, i32 1
store i32* %26, i32** %4
store i32 %24, i32* %25
%27 = load i64*, i64** %5
%28 = icmp ne i64* %27, null
br i1 %28, label %29, label %33
29: ; preds = %3
%30 = load i64*, i64** %5
%31 = load i64, i64* %30
%32 = sub i64 %31, 4
store i64 %32, i64* %30
br label %33
33: ; preds = %29, %3
%34 = load i32*, i32** %4
ret i32* %34
}

LLVM IR (-O2):
define i32* @write_u32(i32* writeonly %0, i64* %1, i32 %2) {
%4 = lshr i32 %2, 24
%5 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %4, i32* %0
%6 = lshr i32 %2, 16
%7 = and i32 %6, 255
%8 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %7, i32* %5
%9 = lshr i32 %2, 8
%10 = and i32 %9, 255
%11 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %10, i32* %8
%12 = and i32 %2, 255
store i32 %12, i32* %11
%13 = icmp eq i64* %1, null
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = load i64, i64* %1
%16 = add i64 %15, -4
store i64 %16, i64* %1
br label %17
17: ; preds = %14, %3
%18 = getelementptr inbounds i32, i32* %0, i64 4
ret i32* %18
}