#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 unsigned char ulong;
typedef unsigned char u4;
typedef unsigned char u1;

/* Variables and functions */
ulong endian4(unsigned char u1, unsigned char u2, unsigned char u3,
              unsigned char u4, int endian) {
  if (endian)
    return ((u1 << 24) & 0xFF000000) | ((u2 << 16) & 0xFF0000) |
           ((u3 << 8) & 0xFF00) | ((u4)&0xFF);
  else
    return ((u4 << 24) & 0xFF000000) | ((u3 << 16) & 0xFF0000) |
           ((u2 << 8) & 0xFF00) | ((u1)&0xFF);
}


x86 assembly (clang, -O0):
<endian4>:
push   %rbp
mov    %rsp,%rbp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %dil,%sil
mov    %sil,-0x2(%rbp)
mov    %dl,-0x3(%rbp)
mov    %cl,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %r8d,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1167 <endian4+0x67>
movzbl -0x2(%rbp),%eax
shl    $0x18,%eax
and    $0xff000000,%eax
movzbl -0x3(%rbp),%ecx
shl    $0x10,%ecx
and    $0xff0000,%ecx
or     %ecx,%eax
movzbl -0x4(%rbp),%ecx
shl    $0x8,%ecx
and    $0xff00,%ecx
or     %ecx,%eax
movzbl -0x5(%rbp),%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %al,-0x1(%rbp)
jmp    11a0 <endian4+0xa0>
movzbl -0x5(%rbp),%eax
shl    $0x18,%eax
and    $0xff000000,%eax
movzbl -0x4(%rbp),%ecx
shl    $0x10,%ecx
and    $0xff0000,%ecx
or     %ecx,%eax
movzbl -0x3(%rbp),%ecx
shl    $0x8,%ecx
and    $0xff00,%ecx
or     %ecx,%eax
movzbl -0x2(%rbp),%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<endian4>:
mov    %edi,%eax
test   %r8d,%r8d
cmovne %ecx,%eax
ret

LLVM IR (-O0):
define zeroext i8 @endian4(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i32 %4) {
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i32
store i8 %0, i8* %7
store i8 %1, i8* %8
store i8 %2, i8* %9
store i8 %3, i8* %10
store i32 %4, i32* %11
%12 = load i32, i32* %11
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %34
14: ; preds = %5
%15 = load i8, i8* %7
%16 = zext i8 %15 to i32
%17 = shl i32 %16, 24
%18 = and i32 %17, -16777216
%19 = load i8, i8* %8
%20 = zext i8 %19 to i32
%21 = shl i32 %20, 16
%22 = and i32 %21, 16711680
%23 = or i32 %18, %22
%24 = load i8, i8* %9
%25 = zext i8 %24 to i32
%26 = shl i32 %25, 8
%27 = and i32 %26, 65280
%28 = or i32 %23, %27
%29 = load i8, i8* %10
%30 = zext i8 %29 to i32
%31 = and i32 %30, 255
%32 = or i32 %28, %31
%33 = trunc i32 %32 to i8
store i8 %33, i8* %6
br label %54
34: ; preds = %5
%35 = load i8, i8* %10
%36 = zext i8 %35 to i32
%37 = shl i32 %36, 24
%38 = and i32 %37, -16777216
%39 = load i8, i8* %9
%40 = zext i8 %39 to i32
%41 = shl i32 %40, 16
%42 = and i32 %41, 16711680
%43 = or i32 %38, %42
%44 = load i8, i8* %8
%45 = zext i8 %44 to i32
%46 = shl i32 %45, 8
%47 = and i32 %46, 65280
%48 = or i32 %43, %47
%49 = load i8, i8* %7
%50 = zext i8 %49 to i32
%51 = and i32 %50, 255
%52 = or i32 %48, %51
%53 = trunc i32 %52 to i8
store i8 %53, i8* %6
br label %54
54: ; preds = %34, %14
%55 = load i8, i8* %6
ret i8 %55
}

LLVM IR (-O2):
define zeroext i8 @endian4(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i32 %4) {
%6 = icmp eq i32 %4, 0
%7 = select i1 %6, i8 %0, i8 %3
ret i8 %7
}