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

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


x86 assembly (clang, -O0):
<utilWriteInt64>:
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     1194 <utilWriteInt64+0x74>
mov    -0x5(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x6(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x7(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x8(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x9(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0xa(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0xb(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0xc(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x7(%rax)
jmp    11a6 <utilWriteInt64+0x86>
mov    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utilWriteInt64>:
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     113f <utilWriteInt64+0x1f>
bswap  %ebp
mov    %ebp,0x4(%rbx)
jmp    1151 <utilWriteInt64+0x31>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1030 <memcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @utilWriteInt64(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 %48
7: ; preds = %2
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds i8, i8* %8, i64 7
%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 6
%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 5
%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 4
%25 = load i8, i8* %24
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 3
store i8 %25, i8* %27
%28 = bitcast i32* %4 to i8*
%29 = getelementptr inbounds i8, i8* %28, i64 3
%30 = load i8, i8* %29
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 4
store i8 %30, i8* %32
%33 = bitcast i32* %4 to i8*
%34 = getelementptr inbounds i8, i8* %33, i64 2
%35 = load i8, i8* %34
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 5
store i8 %35, i8* %37
%38 = bitcast i32* %4 to i8*
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i64 6
store i8 %40, i8* %42
%43 = bitcast i32* %4 to i8*
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 7
store i8 %45, i8* %47
br label %52
48: ; preds = %2
%49 = load i8*, i8** %3
%50 = bitcast i32* %4 to i8*
%51 = call i32 @memcpy(i8* %49, i8* %50, i32 8)
br label %52
52: ; preds = %48, %7
ret void
}

LLVM IR (-O2):
define void @utilWriteInt64(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 %18, 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
%14 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %13, i8* %14
%15 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %11, i8* %15
%16 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %9, i8* %16
%17 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %7, i8* %17
br label %21
18: ; preds = %2
%19 = bitcast i32* %3 to i8*
%20 = call i32 @memcpy(i8* %0, i8* %19, i32 8)
br label %21
21: ; preds = %18, %6
ret void
}