extern void TBUF_RECORD_EVENT(unsigned _id, unsigned _p0, unsigned _p1) {
  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));
  ;
}


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    %fs:0x0,%esi
add    $0x20,%esi
mov    %esi,%edi
and    $0x1fffff,%esi
mov    %esi,%fs:0x0
rdtsc
mov    %eax,%fs:(%edi)
mov    %edi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0x7fffffff,%eax
mov    -0x10(%rbp),%edi
mov    %eax,%fs:0xc(%edi)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%edi
mov    %eax,%fs:0x10(%edi)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%edi
mov    %eax,%fs:0x14(%edi)
pop    %rbp
ret

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

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

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