#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 */
int /*<<< orphan*/ printf(char *, int, int);
int reverse_endian(int num) {
  int rev, tmp;
  tmp = num >> 24;
  tmp = tmp & 0xff;
  rev = tmp;
  tmp = num >> 16;
  tmp = tmp & 0xff;
  tmp = tmp << 8;
  rev = tmp | rev;
  tmp = num >> 8;
  tmp = tmp & 0xff;
  tmp = tmp << 16;
  rev = tmp | rev;
  tmp = num;
  tmp = tmp & 0xff;
  tmp = tmp << 24;
  rev = tmp | rev;
  printf("Input: %d\tOutput: %d\n", num, rev);
  return rev;
}


x86 assembly (clang, -O0):
<reverse_endian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x18,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x10,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x18,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_endian>:
push   %rbx
mov    %edi,%esi
mov    %edi,%ebx
bswap  %ebx
lea    0xee2(%rip),%rdi
mov    %ebx,%edx
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Input: %d\09Output: %d\0A\00"
define i32 @reverse_endian(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = ashr i32 %5, 24
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = and i32 %7, 255
store i32 %8, i32* %4
%9 = load i32, i32* %4
store i32 %9, i32* %3
%10 = load i32, i32* %2
%11 = ashr i32 %10, 16
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = and i32 %12, 255
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = shl i32 %14, 8
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = or i32 %16, %17
store i32 %18, i32* %3
%19 = load i32, i32* %2
%20 = ashr i32 %19, 8
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = and i32 %21, 255
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = shl i32 %23, 16
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = load i32, i32* %3
%27 = or i32 %25, %26
store i32 %27, i32* %3
%28 = load i32, i32* %2
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = and i32 %29, 255
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = shl i32 %31, 24
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = load i32, i32* %3
%35 = or i32 %33, %34
store i32 %35, i32* %3
%36 = load i32, i32* %2
%37 = load i32, i32* %3
%38 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %36, i32 %37)
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [22 x i8] c"Input: %d\09Output: %d\0A\00"
define i32 @reverse_endian(i32 %0) {
%2 = tail call i32 @llvm.bswap.i32(i32 %0)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %2)
ret i32 %2
}