#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 uint32_t;

/* Variables and functions */
int htonl(int);
void _uint32_t_tbetb(uint32_t x, char *buffer, int offset) {
  x = htonl(x);
  *(buffer + offset) = (char)((x >> 24) & 0xFF);
  *(buffer + offset + 1) = (char)((x >> 16) & 0xFF);
  *(buffer + offset + 2) = (char)((x >> 8) & 0xFF);
  *(buffer + offset + 3) = (char)(x & 0xFF);
}


x86 assembly (clang, -O0):
<_uint32_t_tbetb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,0x2(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,0x3(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_uint32_t_tbetb>:
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
call   1030 <htonl@plt>
movslq %ebx,%rcx
bswap  %eax
mov    %eax,(%r14,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @_uint32_t_tbetb(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = call i32 @htonl(i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = ashr i32 %9, 24
%11 = and i32 %10, 255
%12 = trunc i32 %11 to i8
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8 %12, i8* %16
%17 = load i32, i32* %4
%18 = ashr i32 %17, 16
%19 = and i32 %18, 255
%20 = trunc i32 %19 to i8
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 %20, i8* %25
%26 = load i32, i32* %4
%27 = ashr i32 %26, 8
%28 = and i32 %27, 255
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %5
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8 %29, i8* %34
%35 = load i32, i32* %4
%36 = and i32 %35, 255
%37 = trunc i32 %36 to i8
%38 = load i8*, i8** %5
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 3
store i8 %37, i8* %42
ret void
}

LLVM IR (-O2):
define void @_uint32_t_tbetb(i32 %0, i8* nocapture writeonly %1, i32 %2) {
%4 = tail call i32 @htonl(i32 %0)
%5 = lshr i32 %4, 24
%6 = trunc i32 %5 to i8
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 %6, i8* %8
%9 = lshr i32 %4, 16
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %10, i8* %11
%12 = lshr i32 %4, 8
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds i8, i8* %8, i64 2
store i8 %13, i8* %14
%15 = trunc i32 %4 to i8
%16 = getelementptr inbounds i8, i8* %8, i64 3
store i8 %15, i8* %16
ret void
}