#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 */
int /*<<< orphan*/ is_big_endian();
int /*<<< orphan*/ memcpy(void *, int *, int);
size_t fixed32_pack(uint32_t value, void *out) {
  if (!is_big_endian()) {
    memcpy(out, &value, 4);
  } else {
    uint8_t *buf = (uint8_t *)out;
    buf[0] = value;
    buf[1] = value >> 8;
    buf[2] = value >> 16;
    buf[3] = value >> 24;
  }
  return 4;
}


x86 assembly (clang, -O0):
<fixed32_pack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <is_big_endian@plt>
cmp    $0x0,%eax
jne    1156 <fixed32_pack+0x36>
mov    -0x10(%rbp),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
jmp    118e <fixed32_pack+0x6e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%ecx
sar    $0x8,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x4(%rbp),%ecx
sar    $0x10,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x4(%rbp),%ecx
sar    $0x18,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    $0x4,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fixed32_pack>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %edi,0x4(%rsp)
xor    %eax,%eax
call   1040 <is_big_endian@plt>
test   %eax,%eax
je     1151 <fixed32_pack+0x31>
mov    %ebp,(%rbx)
mov    %ebp,%eax
sar    $0x8,%eax
mov    %eax,0x4(%rbx)
mov    %ebp,%eax
sar    $0x10,%eax
mov    %eax,0x8(%rbx)
sar    $0x18,%ebp
mov    %ebp,0xc(%rbx)
jmp    1163 <fixed32_pack+0x43>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    $0x4,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @fixed32_pack(i32 %0, i8* %1) {
%3 = alloca i32
store i32 %0, i32* %3
%4 = tail call i32 (...) @is_big_endian()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = call i32 @memcpy(i8* %1, i32* %3, i32 4)
br label %19
8: ; preds = %2
%9 = bitcast i8* %1 to i32*
store i32 %0, i32* %9
%10 = ashr i32 %0, 8
%11 = getelementptr inbounds i8, i8* %1, i64 4
%12 = bitcast i8* %11 to i32*
store i32 %10, i32* %12
%13 = ashr i32 %0, 16
%14 = getelementptr inbounds i8, i8* %1, i64 8
%15 = bitcast i8* %14 to i32*
store i32 %13, i32* %15
%16 = ashr i32 %0, 24
%17 = getelementptr inbounds i8, i8* %1, i64 12
%18 = bitcast i8* %17 to i32*
store i32 %16, i32* %18
br label %19
19: ; preds = %8, %6
ret i64 4
}