#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*/ _set_key_value(struct hashmap *, void *, void *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, double);
void test_performance_store(struct hashmap *hm) {
  struct timeval t0, t1;
  int i;
  int n = 100000;
  gettimeofday(&t0, NULL);
  for (i = 0; i < n; i++) {
    _set_key_value(hm, (void *)i, (void *)i);
  }
  gettimeofday(&t1, NULL);
  printf("Stored %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_store>:
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   1040 <gettimeofday@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1182 <test_performance_store+0x52>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rsi
movslq -0x2c(%rbp),%rdx
call   1050 <_set_key_value@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1157 <test_performance_store+0x27>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <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  0xe52(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_performance_store>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
call   1050 <_set_key_value@plt>
add    $0x1,%rbx
cmp    $0x186a0,%rbx
jne    1150 <test_performance_store+0x20>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movsd  0x8(%rsp),%xmm1
subsd  0x18(%rsp),%xmm1
mov    0x10(%rsp),%eax
sub    0x20(%rsp),%eax
cvtsi2sd %eax,%xmm0
mulsd  0xe69(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0xe66(%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 = [32 x i8] c"Stored %d keys in %.2g seconds\0A\00"
define void @test_performance_store(%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 = %21, %1
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %24
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 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i8*
%20 = call i32 @_set_key_value(%struct.hashmap* %13, i8* %16, i8* %19)
br label %21
21: ; preds = %12
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %8
24: ; preds = %8
%25 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%26 = load i32, i32* %6
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%28 = load double, double* %27
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%30 = load double, double* %29
%31 = fsub double %28, %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%35 = load i32, i32* %34
%36 = sub nsw i32 %33, %35
%37 = sitofp i32 %36 to double
%38 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %37, double %31)
%39 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %26, double %38)
ret void
}

LLVM IR (-O2):
%struct.hashmap = type { i32 }
%struct.timeval = type { double, i32 }
@.str = [32 x i8] c"Stored %d keys in %.2g seconds\0A\00"
define void @test_performance_store(%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 @_set_key_value(%struct.hashmap* %0, i8* %9, 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 ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 100000, double %26)
ret void
}