__attribute__((always_)) unsigned long long rdtsc_ordered(void) {
  asm volatile("661:\n\t"
               ""
               "\n662:\n"
               ".skip -(("
               "(("
               "665"
               "1"
               "f-"
               "664"
               "1"
               "f"
               ") ^ ((("
               "665"
               "1"
               "f-"
               "664"
               "1"
               "f"
               ") ^ ("
               "665"
               "2"
               "f-"
               "664"
               "2"
               "f"
               ")) & -(-(("
               "665"
               "1"
               "f-"
               "664"
               "1"
               "f"
               ") - ("
               "665"
               "2"
               "f-"
               "664"
               "2"
               "f"
               ")))))"
               " - ("
               "662b-661b"
               ")) > 0) * "
               "("
               "(("
               "665"
               "1"
               "f-"
               "664"
               "1"
               "f"
               ") ^ ((("
               "665"
               "1"
               "f-"
               "664"
               "1"
               "f"
               ") ^ ("
               "665"
               "2"
               "f-"
               "664"
               "2"
               "f"
               ")) & -(-(("
               "665"
               "1"
               "f-"
               "664"
               "1"
               "f"
               ") - ("
               "665"
               "2"
               "f-"
               "664"
               "2"
               "f"
               ")))))"
               " - ("
               "662b-661b"
               ")), 0x90\n"
               "663"
               ":\n"
               ".pushsection .altinstructions,\"a\"\n"
               " .long 661b - .\n"
               " .long "
               "664"
               "1"
               "f - .\n"
               " .word "
               "( 3*32+17)"
               "\n"
               " .byte "
               "663"
               "b-661b"
               "\n"
               " .byte "
               "665"
               "1"
               "f-"
               "664"
               "1"
               "f"
               "\n"
               " .byte "
               "663"
               "b-662b"
               "\n"
               " .long 661b - .\n"
               " .long "
               "664"
               "2"
               "f - .\n"
               " .word "
               "( 3*32+18)"
               "\n"
               " .byte "
               "663"
               "b-661b"
               "\n"
               " .byte "
               "665"
               "2"
               "f-"
               "664"
               "2"
               "f"
               "\n"
               " .byte "
               "663"
               "b-662b"
               "\n"
               ".popsection\n"
               ".pushsection .altinstr_replacement, \"ax\"\n"
               "664"
               "1"
               ":\n\t"
               "mfence"
               "\n"
               "665"
               "1"
               ":\n\t"
               "664"
               "2"
               ":\n\t"
               "lfence"
               "\n"
               "665"
               "2"
               ":\n\t"
               ".popsection" ::
                   : "memory");
  return rdtsc();
}


x86 assembly (clang, -O0):
<rdtsc_ordered>:
push   %rbp
mov    %rsp,%rbp
nop
nop
nop
mov    $0x0,%al
call   1030 <rdtsc@plt>
cltq
pop    %rbp
ret

x86 assembly (clang, -O2):
<rdtsc_ordered>:
push   %rax
nop
nop
nop
xor    %eax,%eax
call   1030 <rdtsc@plt>
cltq
pop    %rcx
ret

LLVM IR (-O0):
define i64 @rdtsc_ordered() {
%1 = call i32 (...) @rdtsc()
%2 = sext i32 %1 to i64
ret i64 %2
}

LLVM IR (-O2):
define i64 @rdtsc_ordered() {
tail call void asm sideeffect "661:\0A\09\0A662:\0A.skip -((((6651f-6641f) ^ (((6651f-6641f) ^ (6652f-6642f)) & -(-((6651f-6641f) - (6652f-6642f))))) - (662b-661b)) > 0) * (((6651f-6641f) ^ (((6651f-6641f) ^ (6652f-6642f)) & -(-((6651f-6641f) - (6652f-6642f))))) - (662b-661b)), 0x90\0A663:\0A.pushsection .altinstructions,\22a\22\0A .long 661b - .\0A .long 6641f - .\0A .word ( 3*32+17)\0A .byte 663b-661b\0A .byte 6651f-6641f\0A .byte 663b-662b\0A .long 661b - .\0A .long 6642f - .\0A .word ( 3*32+18)\0A .byte 663b-661b\0A .byte 6652f-6642f\0A .byte 663b-662b\0A.popsection\0A.pushsection .altinstr_replacement, \22ax\22\0A6641:\0A\09mfence\0A6651:\0A\096642:\0A\09lfence\0A6652:\0A\09.popsection", "~{memory},~{dirflag},~{fpsr},~{flags}"()
%1 = tail call i32 (...) @rdtsc()
%2 = sext i32 %1 to i64
ret i64 %2
}