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

/* Variables and functions */
int /*<<< orphan*/ endian_16hi8(int /*<<< orphan*/);
int /*<<< orphan*/ endian_16lo8(int /*<<< orphan*/);
int /*<<< orphan*/ endian_32hi16(int /*<<< orphan*/);
int /*<<< orphan*/ endian_32hi8(int /*<<< orphan*/);
int /*<<< orphan*/ endian_32lo8(int /*<<< orphan*/);
void endian_big32(uint8_t ptr[4], uint_least32_t dword) {
  uint_least16_t word = 0;
  word = endian_32hi16(dword);
  ptr[1] = endian_16lo8(word);
  ptr[0] = endian_16hi8(word);
  ptr[2] = endian_32hi8(dword);
  ptr[3] = endian_32lo8(dword);
}


x86 assembly (clang, -O0):
<endian_big32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <endian_32hi16@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <endian_16lo8@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%edi
call   1060 <endian_16hi8@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%edi
call   1040 <endian_32hi8@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0xc(%rbp),%edi
call   1050 <endian_32lo8@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endian_big32>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %esi,%edi
call   1070 <endian_32hi16@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <endian_16lo8@plt>
mov    %eax,0x4(%rbx)
mov    %ebp,%edi
call   1060 <endian_16hi8@plt>
mov    %eax,(%rbx)
mov    %r14d,%edi
call   1040 <endian_32hi8@plt>
mov    %eax,0x8(%rbx)
mov    %r14d,%edi
call   1050 <endian_32lo8@plt>
mov    %eax,0xc(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @endian_big32(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %4
%7 = call i32 @endian_32hi16(i32 %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = call i32 @endian_16lo8(i32 %8)
%10 = load i32*, i32** %3
%11 = getelementptr inbounds i32, i32* %10, i64 1
store i32 %9, i32* %11
%12 = load i32, i32* %5
%13 = call i32 @endian_16hi8(i32 %12)
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 0
store i32 %13, i32* %15
%16 = load i32, i32* %4
%17 = call i32 @endian_32hi8(i32 %16)
%18 = load i32*, i32** %3
%19 = getelementptr inbounds i32, i32* %18, i64 2
store i32 %17, i32* %19
%20 = load i32, i32* %4
%21 = call i32 @endian_32lo8(i32 %20)
%22 = load i32*, i32** %3
%23 = getelementptr inbounds i32, i32* %22, i64 3
store i32 %21, i32* %23
ret void
}

LLVM IR (-O2):
define void @endian_big32(i32* nocapture writeonly %0, i32 %1) {
%3 = tail call i32 @endian_32hi16(i32 %1)
%4 = tail call i32 @endian_16lo8(i32 %3)
%5 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %4, i32* %5
%6 = tail call i32 @endian_16hi8(i32 %3)
store i32 %6, i32* %0
%7 = tail call i32 @endian_32hi8(i32 %1)
%8 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %7, i32* %8
%9 = tail call i32 @endian_32lo8(i32 %1)
%10 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %9, i32* %10
ret void
}