extern void TBUF_RECORD_EVENT(unsigned _id, unsigned _p0, unsigned _p1,
                              unsigned _p2) {
  unsigned addr;
  asm volatile("movl	%%fs:0, %%esi	        \n"
               "addl	$32, %%esi		\n"
               "movl   %%esi, %%edi            \n"
               "andl   $0x1fffff, %%esi	\n"
               "movl	%%esi, %%fs:0     	\n"
               "rdtsc				\n"
               "movl 	%%eax, %%fs:0(%%edi)    \n"
               : "=D"(addr)
               :
               : "eax", "ecx", "edx", "esi");
  ;
  asm volatile("movl   %0, %%fs:("
               "0"
               "*4+12)(%%edi)\n"
               :
               : "r"(_id & 0x7FFFFFFF), "D"(addr));
  ;
  asm volatile("movl   %0, %%fs:("
               "1"
               "*4+12)(%%edi)\n"
               :
               : "r"(_p0), "D"(addr));
  ;
  asm volatile("movl   %0, %%fs:("
               "2"
               "*4+12)(%%edi)\n"
               :
               : "r"(_p1), "D"(addr));
  ;
  asm volatile("movl   %0, %%fs:("
               "3"
               "*4+12)(%%edi)\n"
               :
               : "r"(_p2), "D"(addr));
  ;
}


x86 assembly (clang, -O0):
<TBUF_RECORD_EVENT>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %fs:0x0,%esi
add    $0x20,%esi
mov    %esi,%edi
and    $0x1fffff,%esi
mov    %esi,%fs:0x0
rdtsc
mov    %eax,%fs:(%edi)
mov    %edi,-0x14(%rbp)
mov    -0x4(%rbp),%eax
and    $0x7fffffff,%eax
mov    -0x14(%rbp),%edi
mov    %eax,%fs:0xc(%edi)
mov    -0x8(%rbp),%eax
mov    -0x14(%rbp),%edi
mov    %eax,%fs:0x10(%edi)
mov    -0xc(%rbp),%eax
mov    -0x14(%rbp),%edi
mov    %eax,%fs:0x14(%edi)
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%edi
mov    %eax,%fs:0x18(%edi)
pop    %rbp
ret

x86 assembly (clang, -O2):
<TBUF_RECORD_EVENT>:
mov    %ecx,%r8d
mov    %edx,%r9d
mov    %esi,%r10d
mov    %edi,%r11d
mov    %fs:0x0,%esi
add    $0x20,%esi
mov    %esi,%edi
and    $0x1fffff,%esi
mov    %esi,%fs:0x0
rdtsc
mov    %eax,%fs:(%edi)
and    $0x7fffffff,%r11d
mov    %r11d,%fs:0xc(%edi)
mov    %r10d,%fs:0x10(%edi)
mov    %r9d,%fs:0x14(%edi)
mov    %r8d,%fs:0x18(%edi)
ret

LLVM IR (-O0):
define void @TBUF_RECORD_EVENT(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = call i32 asm sideeffect "movl\09%fs:0, %esi\09 \0Aaddl\09$$32, %esi\09\09\0Amovl %esi, %edi \0Aandl $$0x1fffff, %esi\09\0Amovl\09%esi, %fs:0 \09\0Ardtsc\09\09\09\09\0Amovl \09%eax, %fs:0(%edi) \0A", "={di},~{eax},~{ecx},~{edx},~{esi},~{dirflag},~{fpsr},~{flags}"()
store i32 %10, i32* %9
%11 = load i32, i32* %5
%12 = and i32 %11, 2147483647
%13 = load i32, i32* %9
%14 = load i32, i32* %6
%15 = load i32, i32* %9
%16 = load i32, i32* %7
%17 = load i32, i32* %9
%18 = load i32, i32* %8
%19 = load i32, i32* %9
ret void
}

LLVM IR (-O2):
define void @TBUF_RECORD_EVENT(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 asm sideeffect "movl\09%fs:0, %esi\09 \0Aaddl\09$$32, %esi\09\09\0Amovl %esi, %edi \0Aandl $$0x1fffff, %esi\09\0Amovl\09%esi, %fs:0 \09\0Ardtsc\09\09\09\09\0Amovl \09%eax, %fs:0(%edi) \0A", "={di},~{eax},~{ecx},~{edx},~{esi},~{dirflag},~{fpsr},~{flags}"()
%6 = and i32 %0, 2147483647
tail call void asm sideeffect "movl $0, %fs:(0*4+12)(%edi)\0A", "r,{di},~{dirflag},~{fpsr},~{flags}"(i32 %6, i32 %5)
tail call void asm sideeffect "movl $0, %fs:(1*4+12)(%edi)\0A", "r,{di},~{dirflag},~{fpsr},~{flags}"(i32 %1, i32 %5)
tail call void asm sideeffect "movl $0, %fs:(2*4+12)(%edi)\0A", "r,{di},~{dirflag},~{fpsr},~{flags}"(i32 %2, i32 %5)
tail call void asm sideeffect "movl $0, %fs:(3*4+12)(%edi)\0A", "r,{di},~{dirflag},~{fpsr},~{flags}"(i32 %3, i32 %5)
ret void
}