#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 timeval {
  double tv_sec;
  int tv_usec;
};
struct hashmap {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ _get_value_by_key(struct hashmap *, void *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, double);
void test_performance_lookup(struct hashmap *hm) {
  struct timeval t0, t1;
  int i;
  int n = 100000;
  gettimeofday(&t0, NULL);
  for (i = 0; i < n; i++) {
    _get_value_by_key(hm, (void *)i);
  }
  gettimeofday(&t1, NULL);
  printf("Looked up %d keys in %.2g seconds\n", n,
         t1.tv_sec - t0.tv_sec + 1E-6 * (t1.tv_usec - t0.tv_usec));
}


x86 assembly (clang, -O0):
<test_performance_lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x186a0,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    117e <test_performance_lookup+0x4e>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rsi
call   1040 <_get_value_by_key@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1157 <test_performance_lookup+0x27>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x30(%rbp),%esi
movsd  -0x28(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
mov    -0x20(%rbp),%eax
sub    -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe56(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_performance_lookup>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <_get_value_by_key@plt>
add    $0x1,%rbx
cmp    $0x186a0,%rbx
jne    1150 <test_performance_lookup+0x20>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movsd  0x8(%rsp),%xmm1
subsd  0x18(%rsp),%xmm1
mov    0x10(%rsp),%eax
sub    0x20(%rsp),%eax
cvtsi2sd %eax,%xmm0
mulsd  0xe6c(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0xe69(%rip),%rdi
mov    $0x186a0,%esi
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.hashmap = type { i32 }
%struct.timeval = type { double, i32 }
@.str = [35 x i8] c"Looked up %d keys in %.2g seconds\0A\00"
define void @test_performance_lookup(%struct.hashmap* %0) {
%2 = alloca %struct.hashmap*
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = alloca i32
store %struct.hashmap* %0, %struct.hashmap** %2
store i32 100000, i32* %6
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
store i32 0, i32* %5
br label %8
8: ; preds = %18, %1
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = load %struct.hashmap*, %struct.hashmap** %2
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i8*
%17 = call i32 @_get_value_by_key(%struct.hashmap* %13, i8* %16)
br label %18
18: ; preds = %12
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %8
21: ; preds = %8
%22 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%23 = load i32, i32* %6
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%25 = load double, double* %24
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%27 = load double, double* %26
%28 = fsub double %25, %27
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%32 = load i32, i32* %31
%33 = sub nsw i32 %30, %32
%34 = sitofp i32 %33 to double
%35 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %34, double %28)
%36 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %23, double %35)
ret void
}

LLVM IR (-O2):
%struct.hashmap = type { i32 }
%struct.timeval = type { double, i32 }
@.str = [35 x i8] c"Looked up %d keys in %.2g seconds\0A\00"
define void @test_performance_lookup(%struct.hashmap* %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %7
7: ; preds = %1, %7
%8 = phi i64 [ 0, %1 ], [ %11, %7 ]
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @_get_value_by_key(%struct.hashmap* %0, i8* %9)
%11 = add nuw nsw i64 %8, 1
%12 = icmp eq i64 %11, 100000
br i1 %12, label %13, label %7
13: ; preds = %7
%14 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%16 = load double, double* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%18 = load double, double* %17
%19 = fsub double %16, %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%23 = load i32, i32* %22
%24 = sub nsw i32 %21, %23
%25 = sitofp i32 %24 to double
%26 = tail call double @llvm.fmuladd.f64(double %25, double 0x3EB0C6F7A0B5ED8D, double %19)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 100000, double %26)
ret void
}