#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 */
char getchar();
int /*<<< orphan*/ printf(char *, unsigned long, ...);
int /*<<< orphan*/ scanf(char *, unsigned long *);
int main(void) {
  unsigned long int hex, upper, lower, middle_1, middle_2;
  printf("Enter a eight-digit hex value %c \n", 26);
  scanf("%x", &hex);
  lower = hex & 0x000000FF;
  middle_2 = hex & 0x0000FF00;
  middle_2 >>= 8;
  middle_1 = hex & 0x00FF0000;
  middle_1 >>= 16;
  upper = hex & 0xFF000000;
  upper >>= 24;
  printf("0x%04X is composed of %2X, %2X, %2X and %02X\n", hex, upper, middle_1,
         middle_2, lower);
  while (getchar() != '\n')
    continue;
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x1a,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rax
and    $0xff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
and    $0xff00,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
shr    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
and    $0xff0000,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
shr    $0x10,%rax
mov    %rax,-0x28(%rbp)
movabs $0xff000000,%rax
and    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x18,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11fc <main+0xcc>
jmp    11e4 <main+0xb4>
mov    $0x0,%al
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
mov    $0x1a,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%rax
movzbl %al,%r9d
movzbl %ah,%ebx
mov    %eax,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %eax,%edx
shr    $0x18,%edx
lea    0xead(%rip),%rdi
mov    %rax,%rsi
mov    %rbx,%r8
xor    %eax,%eax
call   1030 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    1190 <main+0x60>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Enter a eight-digit hex value %c \0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [46 x i8] c"0x%04X is composed of %2X, %2X, %2X and %02X\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i64 26)
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%9 = load i64, i64* %2
%10 = and i64 %9, 255
store i64 %10, i64* %4
%11 = load i64, i64* %2
%12 = and i64 %11, 65280
store i64 %12, i64* %6
%13 = load i64, i64* %6
%14 = lshr i64 %13, 8
store i64 %14, i64* %6
%15 = load i64, i64* %2
%16 = and i64 %15, 16711680
store i64 %16, i64* %5
%17 = load i64, i64* %5
%18 = lshr i64 %17, 16
store i64 %18, i64* %5
%19 = load i64, i64* %2
%20 = and i64 %19, 4278190080
store i64 %20, i64* %3
%21 = load i64, i64* %3
%22 = lshr i64 %21, 24
store i64 %22, i64* %3
%23 = load i64, i64* %2
%24 = load i64, i64* %3
%25 = load i64, i64* %5
%26 = load i64, i64* %6
%27 = load i64, i64* %4
%28 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i64 %23, i64 %24, i64 %25, i64 %26, i64 %27)
br label %29
29: ; preds = %33, %0
%30 = call signext i8 (...) @getchar()
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br i1 %32, label %33, label %34
33: ; preds = %29
br label %29
34: ; preds = %29
%35 = call signext i8 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"Enter a eight-digit hex value %c \0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [46 x i8] c"0x%04X is composed of %2X, %2X, %2X and %02X\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i64 26)
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%5 = load i64, i64* %1
%6 = and i64 %5, 255
%7 = lshr i64 %5, 8
%8 = and i64 %7, 255
%9 = lshr i64 %5, 16
%10 = and i64 %9, 255
%11 = lshr i64 %5, 24
%12 = and i64 %11, 255
%13 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i64 %5, i64 %12, i64 %10, i64 %8, i64 %6)
br label %14
14: ; preds = %14, %0
%15 = call signext i8 (...) @getchar()
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %14
17: ; preds = %14
%18 = call signext i8 (...) @getchar()
ret i32 0
}