int main(void) {
  unsigned short csw = -1;
  unsigned int csl = -1;
  unsigned long csq = -1;
  unsigned short csw_mem = -1;
  __asm__ __volatile__("movw %%cs, %0\n"
                       "movl %%cs, %1\n"
                       "movq %%cs, %2\n"
                       "movw %%cs, %3\n"
                       : "=r"(csw), "=r"(csl), "=r"(csq), "=m"(csw_mem));
  printf("cs(w)=%u\n", csw);
  printf("cs(l)=%u\n", csl);
  printf("cs(q)=%lu\n", csq);
  printf("cs(w_mem)=%u\n", csw_mem);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0xffff,-0x6(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
movw   $0xffff,-0x1a(%rbp)
mov    %cs,%dx
mov    %cs,%ecx
mov    %cs,%rax
mov    %cs,-0x1a(%rbp)
mov    %dx,-0x6(%rbp)
mov    %ecx,-0xc(%rbp)
mov    %rax,-0x18(%rbp)
movzwl -0x6(%rbp),%esi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzwl -0x1a(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movw   $0xffff,0x6(%rsp)
mov    %cs,%ax
mov    %cs,%ebx
mov    %cs,%r14
mov    %cs,0x6(%rsp)
movzwl %ax,%esi
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
movzwl 0x6(%rsp),%esi
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"cs(w)=%u\0A\00"
@.str.1 = [10 x i8] c"cs(l)=%u\0A\00"
@.str.2 = [11 x i8] c"cs(q)=%lu\0A\00"
@.str.3 = [14 x i8] c"cs(w_mem)=%u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i32
%4 = alloca i64
%5 = alloca i16
store i32 0, i32* %1
store i16 -1, i16* %2
store i32 -1, i32* %3
store i64 -1, i64* %4
store i16 -1, i16* %5
%6 = call { i16, i32, i64 } asm sideeffect "movw %cs, $0\0Amovl %cs, $1\0Amovq %cs, $2\0Amovw %cs, $3\0A", "=r,=r,=r,=*m,~{dirflag},~{fpsr},~{flags}"(i16* elementtype(i16) %5)
%7 = extractvalue { i16, i32, i64 } %6, 0
%8 = extractvalue { i16, i32, i64 } %6, 1
%9 = extractvalue { i16, i32, i64 } %6, 2
store i16 %7, i16* %2
store i32 %8, i32* %3
store i64 %9, i64* %4
%10 = load i16, i16* %2
%11 = zext i16 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i64, i64* %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %15)
%17 = load i16, i16* %5
%18 = zext i16 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"cs(w)=%u\0A\00"
@.str.1 = [10 x i8] c"cs(l)=%u\0A\00"
@.str.2 = [11 x i8] c"cs(q)=%lu\0A\00"
@.str.3 = [14 x i8] c"cs(w_mem)=%u\0A\00"
define i32 @main() {
%1 = alloca i16
%2 = bitcast i16* %1 to i8*
store i16 -1, i16* %1
%3 = call { i16, i32, i64 } asm sideeffect "movw %cs, $0\0Amovl %cs, $1\0Amovq %cs, $2\0Amovw %cs, $3\0A", "=r,=r,=r,=*m,~{dirflag},~{fpsr},~{flags}"(i16* elementtype(i16) %1)
%4 = extractvalue { i16, i32, i64 } %3, 0
%5 = extractvalue { i16, i32, i64 } %3, 1
%6 = extractvalue { i16, i32, i64 } %3, 2
%7 = zext i16 %4 to i32
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %6)
%11 = load i16, i16* %1
%12 = zext i16 %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %12)
ret i32 0
}