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

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
scalar_t__ utilIsLittleEndian();
void utilWriteInt32(unsigned char *buf, int32_t i) {
  if (utilIsLittleEndian()) {
    buf[0] = ((unsigned char *)&i)[3];
    buf[1] = ((unsigned char *)&i)[2];
    buf[2] = ((unsigned char *)&i)[1];
    buf[3] = ((unsigned char *)&i)[0];
  } else {
    memcpy(buf, (unsigned char *)&i, 4);
  }
}


x86 assembly (clang, -O0):
<utilWriteInt32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1040 <utilIsLittleEndian@plt>
cmp    $0x0,%rax
je     116c <utilWriteInt32+0x4c>
mov    -0x9(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0xa(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0xb(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0xc(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
jmp    117e <utilWriteInt32+0x5e>
mov    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utilWriteInt32>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,0x4(%rsp)
xor    %eax,%eax
call   1040 <utilIsLittleEndian@plt>
test   %rax,%rax
je     113e <utilWriteInt32+0x1e>
bswap  %ebp
mov    %ebp,(%rbx)
jmp    1150 <utilWriteInt32+0x30>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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