#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 */

/* Variables and functions */
int /*<<< orphan*/ SYS_getpid;
unsigned int ccnt_read();
int /*<<< orphan*/ syscall(int /*<<< orphan*/);
float cpu_syscall_overhead(float ccnt_overhead) {
  unsigned start, end;
  float total = 0;
  int i;
  for (i = 0; i < 10000; i++) {
    start = ccnt_read();
    syscall(SYS_getpid);
    end = ccnt_read();
    total += (float)(end - start - ccnt_overhead);
  }
  return total / 10000;
}


x86 assembly (clang, -O0):
<cpu_syscall_overhead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2710,-0x14(%rbp)
jge    1199 <cpu_syscall_overhead+0x79>
xor    %eax,%eax
mov    %al,-0x15(%rbp)
call   1030 <ccnt_read@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
call   1040 <syscall@plt>
mov    -0x15(%rbp),%al
call   1030 <ccnt_read@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    %ecx,%eax
cvtsi2ss %rax,%xmm0
subss  -0x4(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113c <cpu_syscall_overhead+0x1c>
movss  -0x10(%rbp),%xmm0
movss  0xe5a(%rip),%xmm1
divss  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_syscall_overhead>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movss  %xmm0,0xc(%rsp)
xorps  %xmm0,%xmm0
mov    $0x2710,%ebp
mov    0x2eb3(%rip),%r14
nopl   (%rax)
movss  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <ccnt_read@plt>
mov    %eax,%ebx
mov    (%r14),%edi
call   1040 <syscall@plt>
xor    %eax,%eax
call   1030 <ccnt_read@plt>
sub    %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
subss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
movss  0x8(%rsp),%xmm0
add    $0xffffffff,%ebp
jne    1140 <cpu_syscall_overhead+0x20>
divss  0xe6f(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SYS_getpid = global i32 0
define float @cpu_syscall_overhead(float %0) {
%2 = alloca float
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca i32
store float %0, float* %2
store float 0.000000e+00, float* %5
store i32 0, i32* %6
br label %7
7: ; preds = %23, %1
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 10000
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = call i32 (...) @ccnt_read()
store i32 %11, i32* %3
%12 = load i32, i32* @SYS_getpid
%13 = call i32 @syscall(i32 %12)
%14 = call i32 (...) @ccnt_read()
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = sub i32 %15, %16
%18 = uitofp i32 %17 to float
%19 = load float, float* %2
%20 = fsub float %18, %19
%21 = load float, float* %5
%22 = fadd float %21, %20
store float %22, float* %5
br label %23
23: ; preds = %10
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %7
26: ; preds = %7
%27 = load float, float* %5
%28 = fdiv float %27, 1.000000e+04
ret float %28
}

LLVM IR (-O2):
@SYS_getpid = global i32 0
define float @cpu_syscall_overhead(float %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 0, %1 ], [ %13, %2 ]
%4 = phi float [ 0.000000e+00, %1 ], [ %12, %2 ]
%5 = tail call i32 (...) @ccnt_read()
%6 = load i32, i32* @SYS_getpid
%7 = tail call i32 @syscall(i32 %6)
%8 = tail call i32 (...) @ccnt_read()
%9 = sub i32 %8, %5
%10 = uitofp i32 %9 to float
%11 = fsub float %10, %0
%12 = fadd float %4, %11
%13 = add nuw nsw i32 %3, 1
%14 = icmp eq i32 %13, 10000
br i1 %14, label %15, label %2
15: ; preds = %2
%16 = fdiv float %12, 1.000000e+04
ret float %16
}