#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 {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct lsm_tree {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, long, long);
int /*<<< orphan*/ process_input(struct lsm_tree *, char *);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
void workload(struct lsm_tree *tree, char *filename) {
  struct timeval tval_before, tval_after, tval_result;
  gettimeofday(&tval_before, NULL);
  assert(filename);
  FILE *fptr = fopen(filename, "r");
  char *buf = malloc(256);
  while (fgets(buf, 256, fptr)) {
    process_input(tree, buf);
  }
  gettimeofday(&tval_after, NULL);
  timersub(&tval_after, &tval_before, &tval_result);
  printf("Time elapsed: %ld.%06ld\n", (long)tval_result.tv_sec,
         (long)tval_result.tv_usec);
}


x86 assembly (clang, -O0):
<workload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x48(%rbp)
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11f6 <workload+0x76>
mov    -0x8(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   10a0 <process_input@plt>
jmp    11c8 <workload+0x48>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1090 <timersub@plt>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    0xddf(%rip),%rdi
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<workload>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %rbx,%rdi
call   1060 <assert@plt>
lea    0xe56(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f2 <workload+0x72>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10a0 <process_input@plt>
mov    %rbx,%rdi
jmp    11d0 <workload+0x50>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x10(%rsp),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1090 <timersub@plt>
mov    (%rsp),%rdx
mov    0x8(%rsp),%rsi
lea    0xde1(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.lsm_tree = type { i32 }
%struct.timeval = type { i64, i64 }
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"Time elapsed: %ld.%06ld\0A\00"
define void @workload(%struct.lsm_tree* %0, i8* %1) {
%3 = alloca %struct.lsm_tree*
%4 = alloca i8*
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca i32*
%9 = alloca i8*
store %struct.lsm_tree* %0, %struct.lsm_tree** %3
store i8* %1, i8** %4
%10 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%11 = load i8*, i8** %4
%12 = call i32 @assert(i8* %11)
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %8
%15 = call i8* @malloc(i32 256)
store i8* %15, i8** %9
br label %16
16: ; preds = %21, %2
%17 = load i8*, i8** %9
%18 = load i32*, i32** %8
%19 = call i64 @fgets(i8* %17, i32 256, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load %struct.lsm_tree*, %struct.lsm_tree** %3
%23 = load i8*, i8** %9
%24 = call i32 @process_input(%struct.lsm_tree* %22, i8* %23)
br label %16
25: ; preds = %16
%26 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%27 = call i32 @timersub(%struct.timeval* %6, %struct.timeval* %5, %struct.timeval* %7)
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%31 = load i64, i64* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %29, i64 %31)
ret void
}

LLVM IR (-O2):
%struct.lsm_tree = type { i32 }
%struct.timeval = type { i64, i64 }
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"Time elapsed: %ld.%06ld\0A\00"
define void @workload(%struct.lsm_tree* %0, i8* %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%10 = tail call i32 @assert(i8* %1)
%11 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%13 = tail call i64 @fgets(i8* %12, i32 256, i32* %11)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %2, %15
%16 = tail call i32 @process_input(%struct.lsm_tree* %0, i8* %12)
%17 = tail call i64 @fgets(i8* %12, i32 256, i32* %11)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %15
19: ; preds = %15, %2
%20 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%21 = call i32 @timersub(%struct.timeval* %4, %struct.timeval* %3, %struct.timeval* %5)
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%25 = load i64, i64* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %23, i64 %25)
ret void
}