void Read_Time_Stamp_Counter(void) {
  printf("\n--- %s() ---\n", __func__);
  unsigned int myEax, myEdx;
  asm volatile("rdtsc\n"
               "movl %%eax, %0\n\t"
               "movl %%edx, %1"
               : "=r"(myEax), "=r"(myEdx)
               :
               : "%eax", "%edx");
  printf("myEax: 0x%08X,  myEdx: 0x%08X\n", myEax, myEdx);
  asm volatile("rdtsc\n"
               "movl %%eax, %0\n"
               "movl %%edx, %1"
               : "=r"(myEax), "=r"(myEdx)
               :
               : "%eax", "%edx");
  printf("myEax: 0x%08X,  myEdx: 0x%08X\n", myEax, myEdx);
}


x86 assembly (clang, -O0):
<Read_Time_Stamp_Counter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xee1(%rip),%rdi
lea    0xee9(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
rdtsc
mov    %eax,%ecx
mov    %edx,%esi
mov    %esi,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %ecx,-0x4(%rbp)
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
rdtsc
mov    %eax,%ecx
mov    %edx,%esi
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %ecx,-0x4(%rbp)
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Read_Time_Stamp_Counter>:
push   %rbx
lea    0xee8(%rip),%rdi
lea    0xef0(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
rdtsc
mov    %eax,%esi
mov    %edx,%ecx
lea    0xef4(%rip),%rbx
mov    %rbx,%rdi
mov    %ecx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
rdtsc
mov    %eax,%esi
mov    %edx,%ecx
mov    %rbx,%rdi
mov    %ecx,%edx
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"\0A--- %s() ---\0A\00"
@__func__.Read_Time_Stamp_Counter = [24 x i8] c"Read_Time_Stamp_Counter\00"
@.str.1 = [31 x i8] c"myEax: 0x%08X, myEdx: 0x%08X\0A\00"
define void @Read_Time_Stamp_Counter() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @__func__.Read_Time_Stamp_Counter, i64 0, i64 0))
%4 = call { i32, i32 } asm sideeffect "rdtsc\0Amovl %eax, $0\0A\09movl %edx, $1", "=r,=r,~{eax},~{edx},~{dirflag},~{fpsr},~{flags}"()
%5 = extractvalue { i32, i32 } %4, 0
%6 = extractvalue { i32, i32 } %4, 1
store i32 %5, i32* %1
store i32 %6, i32* %2
%7 = load i32, i32* %1
%8 = load i32, i32* %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %8)
%10 = call { i32, i32 } asm sideeffect "rdtsc\0Amovl %eax, $0\0Amovl %edx, $1", "=r,=r,~{eax},~{edx},~{dirflag},~{fpsr},~{flags}"()
%11 = extractvalue { i32, i32 } %10, 0
%12 = extractvalue { i32, i32 } %10, 1
store i32 %11, i32* %1
store i32 %12, i32* %2
%13 = load i32, i32* %1
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"\0A--- %s() ---\0A\00"
@__func__.Read_Time_Stamp_Counter = [24 x i8] c"Read_Time_Stamp_Counter\00"
@.str.1 = [31 x i8] c"myEax: 0x%08X, myEdx: 0x%08X\0A\00"
define void @Read_Time_Stamp_Counter() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @__func__.Read_Time_Stamp_Counter, i64 0, i64 0))
%2 = tail call { i32, i32 } asm sideeffect "rdtsc\0Amovl %eax, $0\0A\09movl %edx, $1", "=r,=r,~{eax},~{edx},~{dirflag},~{fpsr},~{flags}"()
%3 = extractvalue { i32, i32 } %2, 0
%4 = extractvalue { i32, i32 } %2, 1
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %4)
%6 = tail call { i32, i32 } asm sideeffect "rdtsc\0Amovl %eax, $0\0Amovl %edx, $1", "=r,=r,~{eax},~{edx},~{dirflag},~{fpsr},~{flags}"()
%7 = extractvalue { i32, i32 } %6, 0
%8 = extractvalue { i32, i32 } %6, 1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %8)
ret void
}