extern void TBUF_RECORD_EVENT(char *str, 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"((unsigned)str), "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    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-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    -0x8(%rbp),%rax
mov    -0x18(%rbp),%edi
mov    %eax,%fs:0xc(%edi)
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%edi
mov    %eax,%fs:0x10(%edi)
mov    -0x10(%rbp),%eax
mov    -0x18(%rbp),%edi
mov    %eax,%fs:0x14(%edi)
mov    -0x14(%rbp),%eax
mov    -0x18(%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    %rdi,%r11
mov    %fs:0x0,%esi
add    $0x20,%esi
mov    %esi,%edi
and    $0x1fffff,%esi
mov    %esi,%fs:0x0
rdtsc
mov    %eax,%fs:(%edi)
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(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %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 i8*, i8** %5
%12 = ptrtoint i8* %11 to i32
%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(i8* %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 = ptrtoint i8* %0 to i64
%7 = trunc i64 %6 to i32
tail call void asm sideeffect "movl $0, %fs:(0*4+12)(%edi)\0A", "r,{di},~{dirflag},~{fpsr},~{flags}"(i32 %7, 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
}