#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 */
typedef int __u64;

/* Variables and functions */
int /*<<< orphan*/ __NR_getgid;
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ syscall(int /*<<< orphan*/);
int time_get_ns();
void test_hash_kmalloc(int cpu) {
  __u64 start_time;
  int i;
  start_time = time_get_ns();
  for (i = 0; i < 1000000; i++) {
    syscall(__NR_getgid);
  }
  printf("%d:hash_map_perf kmalloc %lld events per sec\n", cpu,
         1000000 * 1000000000ll / (time_get_ns() - start_time));
}


x86 assembly (clang, -O0):
<test_hash_kmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1050 <time_get_ns@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xf4240,-0xc(%rbp)
jge    1175 <test_hash_kmalloc+0x45>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
call   1040 <syscall@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114c <test_hash_kmalloc+0x1c>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <time_get_ns@plt>
mov    -0x10(%rbp),%esi
sub    -0x8(%rbp),%eax
movslq %eax,%rcx
movabs $0x38d7ea4c68000,%rax
cqto
idiv   %rcx
mov    %eax,%edx
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_hash_kmalloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
xor    %eax,%eax
call   1050 <time_get_ns@plt>
mov    %eax,%r15d
mov    $0xf4240,%ebx
mov    0x2e90(%rip),%rbp
mov    0x0(%rbp),%edi
call   1040 <syscall@plt>
add    $0xffffffff,%ebx
jne    1150 <test_hash_kmalloc+0x20>
xor    %eax,%eax
call   1050 <time_get_ns@plt>
sub    %r15d,%eax
movslq %eax,%rcx
movabs $0x38d7ea4c68000,%rax
xor    %edx,%edx
idiv   %rcx
lea    0xe80(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@__NR_getgid = global i32 0
@.str = [46 x i8] c"%d:hash_map_perf kmalloc %lld events per sec\0A\00"
define void @test_hash_kmalloc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 (...) @time_get_ns()
store i32 %5, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %12, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1000000
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = load i32, i32* @__NR_getgid
%11 = call i32 @syscall(i32 %10)
br label %12
12: ; preds = %9
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
br label %6
15: ; preds = %6
%16 = load i32, i32* %2
%17 = call i32 (...) @time_get_ns()
%18 = load i32, i32* %3
%19 = sub nsw i32 %17, %18
%20 = sext i32 %19 to i64
%21 = sdiv i64 1000000000000000, %20
%22 = trunc i64 %21 to i32
%23 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %22)
ret void
}

LLVM IR (-O2):
@__NR_getgid = global i32 0
@.str = [46 x i8] c"%d:hash_map_perf kmalloc %lld events per sec\0A\00"
define void @test_hash_kmalloc(i32 %0) {
%2 = tail call i32 (...) @time_get_ns()
br label %3
3: ; preds = %1, %3
%4 = phi i32 [ 0, %1 ], [ %7, %3 ]
%5 = load i32, i32* @__NR_getgid
%6 = tail call i32 @syscall(i32 %5)
%7 = add nuw nsw i32 %4, 1
%8 = icmp eq i32 %7, 1000000
br i1 %8, label %9, label %3
9: ; preds = %3
%10 = tail call i32 (...) @time_get_ns()
%11 = sub nsw i32 %10, %2
%12 = sext i32 %11 to i64
%13 = sdiv i64 1000000000000000, %12
%14 = trunc i64 %13 to i32
%15 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %14)
ret void
}