#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, int *);
void reg1(void) {
  uint32_t reg1 = 0;
  printf("\ninput reg1: ");
  if (scanf("%x", &reg1)) {
    printf("CPL: %u \n", (reg1 & (0b11 << 29)) >> 29);
    printf("CPT: %u \n", (reg1 & (0b11 << 27)) >> 27);
    printf("P: %u \n", (reg1 & (0xFFF << 15)) >> 15);
    printf("M: %u \n", (reg1 & (0xFFF << 3)) >> 3);
  }
}


x86 assembly (clang, -O0):
<reg1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x0,%rax
je     11bf <reg1+0x9f>
mov    -0x4(%rbp),%esi
and    $0x60000000,%esi
sar    $0x1d,%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
and    $0x18000000,%esi
sar    $0x1b,%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
and    $0x7ff8000,%esi
sar    $0xf,%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
and    $0x7ff8,%esi
sar    $0x3,%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reg1>:
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     11b3 <reg1+0x93>
mov    0x4(%rsp),%esi
shr    $0x1d,%esi
and    $0x3,%esi
lea    0xeb3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%esi
shr    $0x1b,%esi
and    $0x3,%esi
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%esi
shr    $0xf,%esi
and    $0xfff,%esi
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x4(%rsp),%esi
shr    $0x3,%esi
and    $0xfff,%esi
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [14 x i8] c"\0Ainput reg1: \00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [10 x i8] c"CPL: %u \0A\00"
@.str.3 = [10 x i8] c"CPT: %u \0A\00"
@.str.4 = [8 x i8] c"P: %u \0A\00"
@.str.5 = [8 x i8] c"M: %u \0A\00"
define void @reg1() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %0
%6 = load i32, i32* %1
%7 = and i32 %6, 1610612736
%8 = ashr i32 %7, 29
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %1
%11 = and i32 %10, 402653184
%12 = ashr i32 %11, 27
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %1
%15 = and i32 %14, 134184960
%16 = ashr i32 %15, 15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %1
%19 = and i32 %18, 32760
%20 = ashr i32 %19, 3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %5, %0
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"\0Ainput reg1: \00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [10 x i8] c"CPL: %u \0A\00"
@.str.3 = [10 x i8] c"CPT: %u \0A\00"
@.str.4 = [8 x i8] c"P: %u \0A\00"
@.str.5 = [8 x i8] c"M: %u \0A\00"
define void @reg1() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %0
%7 = load i32, i32* %1
%8 = lshr i32 %7, 29
%9 = and i32 %8, 3
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %1
%12 = lshr i32 %11, 27
%13 = and i32 %12, 3
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %1
%16 = lshr i32 %15, 15
%17 = and i32 %16, 4095
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %1
%20 = lshr i32 %19, 3
%21 = and i32 %20, 4095
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %6, %0
ret void
}