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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int32_t WriteUint32Be(uint32_t value, void *out) {
  assert(out != NULL);
  uint8_t *buf = (uint8_t *)out;
  buf[0] = (uint8_t)(value >> 24);
  buf[1] = (uint8_t)(value >> 16);
  buf[2] = (uint8_t)(value >> 8);
  buf[3] = (uint8_t)(value >> 0);
  return 4;
}


x86 assembly (clang, -O0):
<WriteUint32Be>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x18,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x4(%rbp),%eax
sar    $0x0,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    $0x4,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteUint32Be>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1030 <assert@plt>
mov    %ebp,%eax
sar    $0x18,%eax
cltq
mov    %rax,(%rbx)
mov    %ebp,%eax
sar    $0x10,%eax
cltq
mov    %rax,0x8(%rbx)
movslq %ebp,%rax
sar    $0x8,%ebp
movslq %ebp,%rcx
mov    %rcx,0x10(%rbx)
mov    %rax,0x18(%rbx)
mov    $0x4,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @WriteUint32Be(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %4
%11 = bitcast i8* %10 to i64*
store i64* %11, i64** %5
%12 = load i32, i32* %3
%13 = ashr i32 %12, 24
%14 = sext i32 %13 to i64
%15 = load i64*, i64** %5
%16 = getelementptr inbounds i64, i64* %15, i64 0
store i64 %14, i64* %16
%17 = load i32, i32* %3
%18 = ashr i32 %17, 16
%19 = sext i32 %18 to i64
%20 = load i64*, i64** %5
%21 = getelementptr inbounds i64, i64* %20, i64 1
store i64 %19, i64* %21
%22 = load i32, i32* %3
%23 = ashr i32 %22, 8
%24 = sext i32 %23 to i64
%25 = load i64*, i64** %5
%26 = getelementptr inbounds i64, i64* %25, i64 2
store i64 %24, i64* %26
%27 = load i32, i32* %3
%28 = ashr i32 %27, 0
%29 = sext i32 %28 to i64
%30 = load i64*, i64** %5
%31 = getelementptr inbounds i64, i64* %30, i64 3
store i64 %29, i64* %31
ret i32 4
}

LLVM IR (-O2):
define i32 @WriteUint32Be(i32 %0, i8* writeonly %1) {
%3 = icmp ne i8* %1, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = bitcast i8* %1 to i64*
%7 = ashr i32 %0, 24
%8 = sext i32 %7 to i64
store i64 %8, i64* %6
%9 = ashr i32 %0, 16
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 8
%12 = bitcast i8* %11 to i64*
store i64 %10, i64* %12
%13 = ashr i32 %0, 8
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 16
%16 = bitcast i8* %15 to i64*
store i64 %14, i64* %16
%17 = sext i32 %0 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 24
%19 = bitcast i8* %18 to i64*
store i64 %17, i64* %19
ret i32 4
}