#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*/ get_msr(int);
int /*<<< orphan*/ get_rsp();
int /*<<< orphan*/ print_u16_nl(char *, int /*<<< orphan*/);
int /*<<< orphan*/ print_u64_nl(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read_ds();
int /*<<< orphan*/ read_es();
int /*<<< orphan*/ read_ss();
int /*<<< orphan*/ read_tr();
int /*<<< orphan*/ write_ds(int);
int /*<<< orphan*/ write_es(int);
int /*<<< orphan*/ write_ss(int);
int /*<<< orphan*/ write_tr(int);
void test_registers() {
  print_u16_nl("ds=", read_ds());
  print_u16_nl("ss=", read_ss());
  print_u16_nl("es=", read_es());
  print_u16_nl("tr=", read_tr());
  write_ds(0x00);
  write_ss(0x00);
  write_es(0x00);
  write_tr(0x00);
  print_u16_nl("ds=", read_ds());
  print_u16_nl("ss=", read_ss());
  print_u16_nl("es=", read_es());
  print_u16_nl("tr=", read_tr());
  print_u64_nl("rsp=", get_rsp());
  print_u64_nl("msr(0xC0000080)=", get_msr(0xC0000080));
}


x86 assembly (clang, -O0):
<test_registers>:
push   %rbp
mov    %rsp,%rbp
mov    $0x0,%al
call   1060 <read_ds@plt>
mov    %eax,%esi
lea    0xe2c(%rip),%rdi
call   10b0 <print_u16_nl@plt>
mov    $0x0,%al
call   1080 <read_ss@plt>
mov    %eax,%esi
lea    0xe1b(%rip),%rdi
call   10b0 <print_u16_nl@plt>
mov    $0x0,%al
call   10d0 <read_es@plt>
mov    %eax,%esi
lea    0xe0a(%rip),%rdi
call   10b0 <print_u16_nl@plt>
mov    $0x0,%al
call   10a0 <read_tr@plt>
mov    %eax,%esi
lea    0xdf9(%rip),%rdi
call   10b0 <print_u16_nl@plt>
xor    %edi,%edi
call   1090 <write_ds@plt>
xor    %edi,%edi
call   1070 <write_ss@plt>
xor    %edi,%edi
call   10e0 <write_es@plt>
xor    %edi,%edi
call   10c0 <write_tr@plt>
mov    $0x0,%al
call   1060 <read_ds@plt>
mov    %eax,%esi
lea    0xdbc(%rip),%rdi
call   10b0 <print_u16_nl@plt>
mov    $0x0,%al
call   1080 <read_ss@plt>
mov    %eax,%esi
lea    0xdab(%rip),%rdi
call   10b0 <print_u16_nl@plt>
mov    $0x0,%al
call   10d0 <read_es@plt>
mov    %eax,%esi
lea    0xd9a(%rip),%rdi
call   10b0 <print_u16_nl@plt>
mov    $0x0,%al
call   10a0 <read_tr@plt>
mov    %eax,%esi
lea    0xd89(%rip),%rdi
call   10b0 <print_u16_nl@plt>
mov    $0x0,%al
call   1030 <get_rsp@plt>
mov    %eax,%esi
lea    0xd78(%rip),%rdi
call   1050 <print_u64_nl@plt>
mov    $0xc0000080,%edi
call   1040 <get_msr@plt>
mov    %eax,%esi
lea    0xd65(%rip),%rdi
call   1050 <print_u64_nl@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_registers>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <read_ds@plt>
lea    0xe2a(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   10b0 <print_u16_nl@plt>
xor    %eax,%eax
call   1080 <read_ss@plt>
lea    0xe16(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
call   10b0 <print_u16_nl@plt>
xor    %eax,%eax
call   10d0 <read_es@plt>
lea    0xe02(%rip),%r12
mov    %r12,%rdi
mov    %eax,%esi
call   10b0 <print_u16_nl@plt>
xor    %eax,%eax
call   10a0 <read_tr@plt>
lea    0xdee(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <print_u16_nl@plt>
xor    %edi,%edi
call   1090 <write_ds@plt>
xor    %edi,%edi
call   1070 <write_ss@plt>
xor    %edi,%edi
call   10e0 <write_es@plt>
xor    %edi,%edi
call   10c0 <write_tr@plt>
xor    %eax,%eax
call   1060 <read_ds@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   10b0 <print_u16_nl@plt>
xor    %eax,%eax
call   1080 <read_ss@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   10b0 <print_u16_nl@plt>
xor    %eax,%eax
call   10d0 <read_es@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   10b0 <print_u16_nl@plt>
xor    %eax,%eax
call   10a0 <read_tr@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <print_u16_nl@plt>
xor    %eax,%eax
call   1030 <get_rsp@plt>
lea    0xd7a(%rip),%rdi
mov    %eax,%esi
call   1050 <print_u64_nl@plt>
mov    $0xc0000080,%edi
call   1040 <get_msr@plt>
lea    0xd67(%rip),%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <print_u64_nl@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"ds=\00"
@.str.1 = [4 x i8] c"ss=\00"
@.str.2 = [4 x i8] c"es=\00"
@.str.3 = [4 x i8] c"tr=\00"
@.str.4 = [5 x i8] c"rsp=\00"
@.str.5 = [17 x i8] c"msr(0xC0000080)=\00"
define void @test_registers() {
%1 = call i32 (...) @read_ds()
%2 = call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = call i32 (...) @read_ss()
%4 = call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = call i32 (...) @read_es()
%6 = call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = call i32 (...) @read_tr()
%8 = call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%9 = call i32 @write_ds(i32 0)
%10 = call i32 @write_ss(i32 0)
%11 = call i32 @write_es(i32 0)
%12 = call i32 @write_tr(i32 0)
%13 = call i32 (...) @read_ds()
%14 = call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 (...) @read_ss()
%16 = call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 (...) @read_es()
%18 = call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = call i32 (...) @read_tr()
%20 = call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = call i32 (...) @get_rsp()
%22 = call i32 @print_u64_nl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = call i32 @get_msr(i32 -1073741696)
%24 = call i32 @print_u64_nl(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %23)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"ds=\00"
@.str.1 = [4 x i8] c"ss=\00"
@.str.2 = [4 x i8] c"es=\00"
@.str.3 = [4 x i8] c"tr=\00"
@.str.4 = [5 x i8] c"rsp=\00"
@.str.5 = [17 x i8] c"msr(0xC0000080)=\00"
define void @test_registers() {
%1 = tail call i32 (...) @read_ds()
%2 = tail call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 (...) @read_ss()
%4 = tail call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32 (...) @read_es()
%6 = tail call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = tail call i32 (...) @read_tr()
%8 = tail call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%9 = tail call i32 @write_ds(i32 0)
%10 = tail call i32 @write_ss(i32 0)
%11 = tail call i32 @write_es(i32 0)
%12 = tail call i32 @write_tr(i32 0)
%13 = tail call i32 (...) @read_ds()
%14 = tail call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = tail call i32 (...) @read_ss()
%16 = tail call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = tail call i32 (...) @read_es()
%18 = tail call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = tail call i32 (...) @read_tr()
%20 = tail call i32 @print_u16_nl(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = tail call i32 (...) @get_rsp()
%22 = tail call i32 @print_u64_nl(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = tail call i32 @get_msr(i32 -1073741696)
%24 = tail call i32 @print_u64_nl(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %23)
ret void
}