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

/* Variables and functions */
scalar_t__ htonl(int /*<<< orphan*/);
unsigned char *serialize_int32_t(unsigned char *buffer, int32_t value) {
  value = (int32_t)htonl((uint32_t)value);
  buffer[0] = (value >> 24) & 0xff;
  buffer[1] = (value >> 16) & 0xff;
  buffer[2] = (value >> 8) & 0xff;
  buffer[3] = value & 0xff;
  return buffer + 4;
}


x86 assembly (clang, -O0):
<serialize_int32_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0xc(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialize_int32_t>:
push   %rbx
mov    %rdi,%rbx
mov    %esi,%edi
call   1030 <htonl@plt>
bswap  %eax
mov    %eax,(%rbx)
add    $0x4,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

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