extern void TBUF_RECORD_EVENT(unsigned _id, unsigned _p0, unsigned _p1,
                              unsigned _p2, unsigned _p3) {
  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));
  ;
  asm volatile("movl   %0, %%fs:("
               "4"
               "*4+12)(%%edi)\n"
               :
               : "r"(_p3), "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    %r8d,-0x14(%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,-0x18(%rbp)
mov    -0x4(%rbp),%eax
and    $0x7fffffff,%eax
mov    -0x18(%rbp),%edi
mov    %eax,%fs:0xc(%edi)
mov    -0x8(%rbp),%eax
mov    -0x18(%rbp),%edi
mov    %eax,%fs:0x10(%edi)
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%edi
mov    %eax,%fs:0x14(%edi)
mov    -0x10(%rbp),%eax
mov    -0x18(%rbp),%edi
mov    %eax,%fs:0x18(%edi)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%edi
mov    %eax,%fs:0x1c(%edi)
pop    %rbp
ret

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

LLVM IR (-O0):
define void @TBUF_RECORD_EVENT(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = 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 %12, i32* %11
%13 = load i32, i32* %6
%14 = and i32 %13, 2147483647
%15 = load i32, i32* %11
%16 = load i32, i32* %7
%17 = load i32, i32* %11
%18 = load i32, i32* %8
%19 = load i32, i32* %11
%20 = load i32, i32* %9
%21 = load i32, i32* %11
%22 = load i32, i32* %10
%23 = load i32, i32* %11
ret void
}

LLVM IR (-O2):
define void @TBUF_RECORD_EVENT(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = 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}"()
%7 = and i32 %0, 2147483647
tail call void asm sideeffect "movl $0, %fs:(0*4+12)(%edi)\0A", "r,{di},~{dirflag},~{fpsr},~{flags}"(i32 %7, i32 %6)
tail call void asm sideeffect "movl $0, %fs:(1*4+12)(%edi)\0A", "r,{di},~{dirflag},~{fpsr},~{flags}"(i32 %1, i32 %6)
tail call void asm sideeffect "movl $0, %fs:(2*4+12)(%edi)\0A", "r,{di},~{dirflag},~{fpsr},~{flags}"(i32 %2, i32 %6)
tail call void asm sideeffect "movl $0, %fs:(3*4+12)(%edi)\0A", "r,{di},~{dirflag},~{fpsr},~{flags}"(i32 %3, i32 %6)
tail call void asm sideeffect "movl $0, %fs:(4*4+12)(%edi)\0A", "r,{di},~{dirflag},~{fpsr},~{flags}"(i32 %4, i32 %6)
ret void
}