long long rb_htonll(long long lll) {
  long long nll = 0;
  unsigned char *cp = (unsigned char *)&nll;
  cp[0] = (lll >> 56) & 0xFF;
  cp[1] = (lll >> 48) & 0xFF;
  cp[2] = (lll >> 40) & 0xFF;
  cp[3] = (lll >> 32) & 0xFF;
  cp[4] = (lll >> 24) & 0xFF;
  cp[5] = (lll >> 16) & 0xFF;
  cp[6] = (lll >> 8) & 0xFF;
  cp[7] = (lll >> 0) & 0xFF;
  return nll;
}


x86 assembly (clang, -O0):
<rb_htonll>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
sar    $0x38,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
sar    $0x30,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x8(%rbp),%rax
sar    $0x28,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x8(%rbp),%rax
sar    $0x20,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x8(%rbp),%rax
sar    $0x18,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x8(%rbp),%rax
sar    $0x10,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x8(%rbp),%rax
sar    $0x8,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x8(%rbp),%rax
sar    $0x0,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<rb_htonll>:
mov    %rdi,%rax
bswap  %rax
ret

LLVM IR (-O0):
define i64 @rb_htonll(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
store i64 %0, i64* %2
store i64 0, i64* %3
%5 = bitcast i64* %3 to i8*
store i8* %5, i8** %4
%6 = load i64, i64* %2
%7 = ashr i64 %6, 56
%8 = and i64 %7, 255
%9 = trunc i64 %8 to i8
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 %9, i8* %11
%12 = load i64, i64* %2
%13 = ashr i64 %12, 48
%14 = and i64 %13, 255
%15 = trunc i64 %14 to i8
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 %15, i8* %17
%18 = load i64, i64* %2
%19 = ashr i64 %18, 40
%20 = and i64 %19, 255
%21 = trunc i64 %20 to i8
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 2
store i8 %21, i8* %23
%24 = load i64, i64* %2
%25 = ashr i64 %24, 32
%26 = and i64 %25, 255
%27 = trunc i64 %26 to i8
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 3
store i8 %27, i8* %29
%30 = load i64, i64* %2
%31 = ashr i64 %30, 24
%32 = and i64 %31, 255
%33 = trunc i64 %32 to i8
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 4
store i8 %33, i8* %35
%36 = load i64, i64* %2
%37 = ashr i64 %36, 16
%38 = and i64 %37, 255
%39 = trunc i64 %38 to i8
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 5
store i8 %39, i8* %41
%42 = load i64, i64* %2
%43 = ashr i64 %42, 8
%44 = and i64 %43, 255
%45 = trunc i64 %44 to i8
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i64 6
store i8 %45, i8* %47
%48 = load i64, i64* %2
%49 = ashr i64 %48, 0
%50 = and i64 %49, 255
%51 = trunc i64 %50 to i8
%52 = load i8*, i8** %4
%53 = getelementptr inbounds i8, i8* %52, i64 7
store i8 %51, i8* %53
%54 = load i64, i64* %3
ret i64 %54
}

LLVM IR (-O2):
define i64 @rb_htonll(i64 %0) {
%2 = tail call i64 @llvm.bswap.i64(i64 %0)
ret i64 %2
}