#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, unsigned long long, char const *);
unsigned long long rdtsc_ordered();
int syscall(int, char const *, struct stat *);
__attribute__((always_)) int stat_printk(const char *s, struct stat *stats) {
  unsigned long long before, after;
  int result;
  before = rdtsc_ordered();
  result = syscall(547, s, stats);
  after = rdtsc_ordered();
  printf("cs530\tstat\tuser\t%d\t%lld\t\"%s\"\n", result, after - before, s);
  return result;
}


x86 assembly (clang, -O0):
<stat_printk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rdtsc_ordered@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x223,%edi
call   1040 <syscall@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <rdtsc_ordered@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
sub    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stat_printk>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <rdtsc_ordered@plt>
mov    %rax,%r15
mov    $0x223,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <syscall@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <rdtsc_ordered@plt>
sub    %r15,%rax
lea    0xe96(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1030 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [30 x i8] c"cs530\09stat\09user\09%d\09%lld\09\22%s\22\0A\00"
define i32 @stat_printk(i8* %0, %struct.stat* %1) {
%3 = alloca i8*
%4 = alloca %struct.stat*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
store %struct.stat* %1, %struct.stat** %4
%8 = call i64 (...) @rdtsc_ordered()
store i64 %8, i64* %5
%9 = load i8*, i8** %3
%10 = load %struct.stat*, %struct.stat** %4
%11 = call i32 @syscall(i32 547, i8* %9, %struct.stat* %10)
store i32 %11, i32* %7
%12 = call i64 (...) @rdtsc_ordered()
store i64 %12, i64* %6
%13 = load i32, i32* %7
%14 = load i64, i64* %6
%15 = load i64, i64* %5
%16 = sub i64 %14, %15
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %13, i64 %16, i8* %17)
%19 = load i32, i32* %7
ret i32 %19
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [30 x i8] c"cs530\09stat\09user\09%d\09%lld\09\22%s\22\0A\00"
define i32 @stat_printk(i8* %0, %struct.stat* %1) {
%3 = tail call i64 (...) @rdtsc_ordered()
%4 = tail call i32 @syscall(i32 547, i8* %0, %struct.stat* %1)
%5 = tail call i64 (...) @rdtsc_ordered()
%6 = sub i64 %5, %3
%7 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %4, i64 %6, i8* %0)
ret i32 %4
}