#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 selector(int);
int /*<<< orphan*/ write_byte(int);
int /*<<< orphan*/ write_word(int);
void select_page_register(int r, int addr) {
  int sel;
  sel = selector(addr);
  if (r != 7) {
    write_byte(0xf5);
    write_byte((char)(0x40 | (7 << 3) | r));
  }
  write_byte(0x32);
  write_word(sel);
  if (r != 7)
    write_byte(0xf1);
}


x86 assembly (clang, -O0):
<select_page_register>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <selector@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x7,-0x4(%rbp)
je     116b <select_page_register+0x3b>
mov    $0xf5,%edi
call   1050 <write_byte@plt>
mov    -0x4(%rbp),%eax
or     $0x78,%eax
movsbl %al,%edi
call   1050 <write_byte@plt>
mov    $0x32,%edi
call   1050 <write_byte@plt>
mov    -0xc(%rbp),%edi
call   1040 <write_word@plt>
cmpl   $0x7,-0x4(%rbp)
je     1191 <select_page_register+0x61>
mov    $0xf1,%edi
call   1050 <write_byte@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_page_register>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %esi,%edi
call   1030 <selector@plt>
mov    %eax,%ebx
cmp    $0x7,%ebp
jne    115a <select_page_register+0x2a>
mov    $0x32,%edi
call   1050 <write_byte@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <write_word@plt>
mov    $0xf5,%edi
call   1050 <write_byte@plt>
movsbl %bpl,%edi
or     $0x78,%edi
call   1050 <write_byte@plt>
mov    $0x32,%edi
call   1050 <write_byte@plt>
mov    %ebx,%edi
call   1040 <write_word@plt>
mov    $0xf1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <write_byte@plt>

LLVM IR (-O0):
define void @select_page_register(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = call i32 @selector(i32 %6)
store i32 %7, i32* %5
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 7
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = call i32 @write_byte(i32 245)
%12 = load i32, i32* %3
%13 = or i32 120, %12
%14 = trunc i32 %13 to i8
%15 = sext i8 %14 to i32
%16 = call i32 @write_byte(i32 %15)
br label %17
17: ; preds = %10, %2
%18 = call i32 @write_byte(i32 50)
%19 = load i32, i32* %5
%20 = call i32 @write_word(i32 %19)
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 7
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @write_byte(i32 241)
br label %25
25: ; preds = %23, %17
ret void
}

LLVM IR (-O2):
define void @select_page_register(i32 %0, i32 %1) {
%3 = tail call i32 @selector(i32 %1)
%4 = icmp eq i32 %0, 7
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i32 @write_byte(i32 245)
%7 = shl i32 %0, 24
%8 = ashr exact i32 %7, 24
%9 = or i32 %8, 120
%10 = tail call i32 @write_byte(i32 %9)
%11 = tail call i32 @write_byte(i32 50)
%12 = tail call i32 @write_word(i32 %3)
%13 = tail call i32 @write_byte(i32 241)
br label %17
14: ; preds = %2
%15 = tail call i32 @write_byte(i32 50)
%16 = tail call i32 @write_word(i32 %3)
br label %17
17: ; preds = %14, %5
ret void
}