#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 /*<<< orphan*/ v;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int swap_nibble(unsigned int);
int main() {
  unsigned int v = 0x50;
  unsigned int r = v;
  int a = 0;
  int s = sizeof(v) * 8 - 1;
  printf("sizeof %d", sizeof(unsigned int));
  for (v = v >> 1; v; v = v >> 1) {
    r <<= 1;
    r |= v & 1;
    s--;
  }
  r <<= s;
  printf("%x\n", r);
  r = 0x5a;
  printf("sw : %d \n", swap_nibble(r));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x50,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1f,-0x14(%rbp)
lea    0xeaf(%rip),%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     119a <main+0x7a>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1164 <main+0x44>
mov    -0x14(%rbp),%ecx
mov    -0xc(%rbp),%eax
shl    %cl,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x5a,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <swap_nibble@plt>
mov    %eax,%esi
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
mov    $0xa000000,%esi
call   1030 <printf@plt>
mov    $0x5a,%edi
call   1040 <swap_nibble@plt>
lea    0xeba(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"sizeof %d\00"
@.str.1 = [4 x i8] c"%x\0A\00"
@.str.2 = [10 x i8] c"sw : %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 80, i32* %2
%6 = load i32, i32* %2
store i32 %6, i32* %3
store i32 0, i32* %4
store i32 31, i32* %5
%7 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = load i32, i32* %2
%9 = lshr i32 %8, 1
store i32 %9, i32* %2
br label %10
10: ; preds = %22, %0
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load i32, i32* %3
%15 = shl i32 %14, 1
store i32 %15, i32* %3
%16 = load i32, i32* %2
%17 = and i32 %16, 1
%18 = load i32, i32* %3
%19 = or i32 %18, %17
store i32 %19, i32* %3
%20 = load i32, i32* %5
%21 = add nsw i32 %20, -1
store i32 %21, i32* %5
br label %22
22: ; preds = %13
%23 = load i32, i32* %2
%24 = lshr i32 %23, 1
store i32 %24, i32* %2
br label %10
25: ; preds = %10
%26 = load i32, i32* %5
%27 = load i32, i32* %3
%28 = shl i32 %27, %26
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
store i32 90, i32* %3
%31 = load i32, i32* %3
%32 = call i32 @swap_nibble(i32 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"sizeof %d\00"
@.str.1 = [4 x i8] c"%x\0A\00"
@.str.2 = [10 x i8] c"sw : %d \0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 4)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 167772160)
%3 = tail call i32 @swap_nibble(i32 90)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %3)
ret i32 0
}