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

/* Variables and functions */
scalar_t__ isBigEndian();
int LongVal(int i) {
  {
    (void)((
        int (*)(char failed_static_assertion[(sizeof(int) == 4) ? 1 : -1]))0);
  };
  if (isBigEndian()) {
    unsigned char b1, b2, b3, b4;
    b1 = i & 255;
    b2 = (i >> 8) & 255;
    b3 = (i >> 16) & 255;
    b4 = (i >> 24) & 255;
    return ((int)b1 << 24) + ((int)b2 << 16) + ((int)b3 << 8) + b4;
  } else
    return i;
}


x86 assembly (clang, -O0):
<LongVal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <isBigEndian@plt>
cmp    $0x0,%rax
je     1188 <LongVal+0x78>
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0xa(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0xb(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    %al,-0xc(%rbp)
movzbl -0x9(%rbp),%eax
shl    $0x18,%eax
movzbl -0xa(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
movzbl -0xb(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
movzbl -0xc(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    118e <LongVal+0x7e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LongVal>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <isBigEndian@plt>
test   %rax,%rax
mov    %ebx,%eax
bswap  %eax
cmove  %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @LongVal(i32 %0) {
%2 = tail call i64 (...) @isBigEndian()
%3 = icmp eq i64 %2, 0
%4 = tail call i32 @llvm.bswap.i32(i32 %0)
%5 = select i1 %3, i32 %0, i32 %4
ret i32 %5
}