#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__ value;

/* Variables and functions */
int write_raw_byte(char, void *, int);
int write_raw_little_endian32(unsigned long value, void *_buffer, int offset) {
  offset = write_raw_byte((char)((value)&0xFF), _buffer, offset);
  offset = write_raw_byte((char)((value >> 8) & 0xFF), _buffer, offset);
  offset = write_raw_byte((char)((value >> 16) & 0xFF), _buffer, offset);
  offset = write_raw_byte((char)((value >> 24) & 0xFF), _buffer, offset);
  return offset;
}


x86 assembly (clang, -O0):
<write_raw_little_endian32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
and    $0xff,%rax
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
movsbl %al,%edi
call   1030 <write_raw_byte@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x8,%rax
and    $0xff,%rax
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
movsbl %al,%edi
call   1030 <write_raw_byte@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x10,%rax
and    $0xff,%rax
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
movsbl %al,%edi
call   1030 <write_raw_byte@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x18,%rax
and    $0xff,%rax
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
movsbl %al,%edi
call   1030 <write_raw_byte@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_raw_little_endian32>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl %bl,%edi
call   1030 <write_raw_byte@plt>
mov    %ebx,%ecx
shr    $0x8,%ecx
movsbl %cl,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write_raw_byte@plt>
mov    %ebx,%ecx
shr    $0x10,%ecx
movsbl %cl,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write_raw_byte@plt>
sar    $0x18,%ebx
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <write_raw_byte@plt>

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

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