#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 uint64_t;
typedef int uint32_t;

/* Variables and functions */
int htonl(int);
int /*<<< orphan*/ isBigEndian();
uint64_t htonll(uint64_t value) {
  if (!isBigEndian()) {
    uint32_t high_part = htonl((uint32_t)(value >> 32));
    uint32_t low_part = htonl((uint32_t)(value & 0xFFFFFFFFULL));
    value = low_part & 0xffffffffULL;
    value = (value << 32) | high_part;
    value = (uint64_t)(((uint64_t)low_part) << 32) | high_part;
    return (uint64_t)(((uint64_t)low_part) << 32) | high_part;
  } else {
    return value;
  }
}


x86 assembly (clang, -O0):
<htonll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <isBigEndian@plt>
cmp    $0x0,%eax
jne    11b1 <htonll+0x91>
mov    -0x8(%rbp),%edi
mov    $0x20,%ecx
sar    %cl,%edi
call   1040 <htonl@plt>
mov    %eax,-0xc(%rbp)
movslq -0x8(%rbp),%rax
movabs $0xffffffff,%rcx
and    %rcx,%rax
mov    %eax,%edi
call   1040 <htonl@plt>
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
movabs $0xffffffff,%rcx
and    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x20,%ecx
shl    %cl,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x20,%ecx
shl    %cl,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x20,%ecx
shl    %cl,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <htonll+0x97>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htonll>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <isBigEndian@plt>
test   %eax,%eax
jne    113a <htonll+0x1a>
call   1040 <htonl@plt>
mov    %ebx,%edi
call   1040 <htonl@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @htonll(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i32 (...) @isBigEndian()
%7 = icmp ne i32 %6, 0
br i1 %7, label %33, label %8
8: ; preds = %1
%9 = load i32, i32* %3
%10 = ashr i32 %9, 32
%11 = call i32 @htonl(i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = and i64 %13, 4294967295
%15 = trunc i64 %14 to i32
%16 = call i32 @htonl(i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = and i64 %18, 4294967295
%20 = trunc i64 %19 to i32
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = shl i32 %21, 32
%23 = load i32, i32* %4
%24 = or i32 %22, %23
store i32 %24, i32* %3
%25 = load i32, i32* %5
%26 = shl i32 %25, 32
%27 = load i32, i32* %4
%28 = or i32 %26, %27
store i32 %28, i32* %3
%29 = load i32, i32* %5
%30 = shl i32 %29, 32
%31 = load i32, i32* %4
%32 = or i32 %30, %31
store i32 %32, i32* %2
br label %35
33: ; preds = %1
%34 = load i32, i32* %3
store i32 %34, i32* %2
br label %35
35: ; preds = %33, %8
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
define i32 @htonll(i32 returned %0) {
%2 = tail call i32 (...) @isBigEndian()
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @htonl(i32 poison)
%6 = tail call i32 @htonl(i32 %0)
br label %7
7: ; preds = %1, %4
ret i32 %0
}