#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 hashtable {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ hashtable_insert(struct hashtable *, char *, char *, int,
                                    int);
int /*<<< orphan*/ printf(char *);
int read(int, ...);
int /*<<< orphan*/ stampa(char *, int);
void log_replay(int fd, struct hashtable *db) {
  char key[128], value[128];
  int k_len, v_len;
  while (1) {
    if (read(fd, &k_len, sizeof(int)) != sizeof(int))
      break;
    if (read(fd, &v_len, sizeof(int)) != sizeof(int))
      break;
    if (read(fd, key, k_len) != k_len)
      break;
    if (read(fd, value, v_len) != v_len)
      break;
    hashtable_insert(db, key, value, k_len, v_len);
    printf("replay key\n");
    stampa(key, k_len);
  }
}


x86 assembly (clang, -O0):
<log_replay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x114(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
cltq
cmp    $0x4,%rax
je     1179 <log_replay+0x39>
jmp    1237 <log_replay+0xf7>
mov    -0x4(%rbp),%edi
lea    -0x118(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
cltq
cmp    $0x4,%rax
je     11a0 <log_replay+0x60>
jmp    1237 <log_replay+0xf7>
mov    -0x4(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    -0x114(%rbp),%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    -0x114(%rbp),%eax
je     11c8 <log_replay+0x88>
jmp    1237 <log_replay+0xf7>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x118(%rbp),%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    -0x118(%rbp),%eax
je     11f0 <log_replay+0xb0>
jmp    1237 <log_replay+0xf7>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
lea    -0x110(%rbp),%rdx
mov    -0x114(%rbp),%ecx
mov    -0x118(%rbp),%r8d
call   1060 <hashtable_insert@plt>
lea    0xde5(%rip),%rdi
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x114(%rbp),%esi
call   1040 <stampa@plt>
jmp    1152 <log_replay+0x12>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_replay>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1219 <log_replay+0xd9>
lea    0xc(%rsp),%r14
lea    0x90(%rsp),%rbx
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    $0x4,%edx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1219 <log_replay+0xd9>
mov    0x8(%rsp),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <read@plt>
cmp    0x8(%rsp),%eax
jne    1219 <log_replay+0xd9>
mov    0xc(%rsp),%edx
mov    %ebp,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <read@plt>
cmp    0xc(%rsp),%eax
jne    1219 <log_replay+0xd9>
mov    0x8(%rsp),%ecx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %eax,%r8d
call   1060 <hashtable_insert@plt>
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1040 <stampa@plt>
mov    $0x4,%edx
mov    %ebp,%edi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <read@plt>
cmp    $0x4,%eax
je     1190 <log_replay+0x50>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hashtable = type { i32 }
@.str = [12 x i8] c"replay key\0A\00"
define void @log_replay(i32 %0, %struct.hashtable* %1) {
%3 = alloca i32
%4 = alloca %struct.hashtable*
%5 = alloca [128 x i8]
%6 = alloca [128 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store %struct.hashtable* %1, %struct.hashtable** %4
br label %9
9: ; preds = %2, %37
%10 = load i32, i32* %3
%11 = call i32 (i32, ...) @read(i32 %10, i32* %7, i64 4)
%12 = sext i32 %11 to i64
%13 = icmp ne i64 %12, 4
br i1 %13, label %14, label %15
14: ; preds = %9
br label %48
15: ; preds = %9
%16 = load i32, i32* %3
%17 = call i32 (i32, ...) @read(i32 %16, i32* %8, i64 4)
%18 = sext i32 %17 to i64
%19 = icmp ne i64 %18, 4
br i1 %19, label %20, label %21
20: ; preds = %15
br label %48
21: ; preds = %15
%22 = load i32, i32* %3
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%24 = load i32, i32* %7
%25 = call i32 (i32, ...) @read(i32 %22, i8* %23, i32 %24)
%26 = load i32, i32* %7
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %21
br label %48
29: ; preds = %21
%30 = load i32, i32* %3
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%32 = load i32, i32* %8
%33 = call i32 (i32, ...) @read(i32 %30, i8* %31, i32 %32)
%34 = load i32, i32* %8
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %29
br label %48
37: ; preds = %29
%38 = load %struct.hashtable*, %struct.hashtable** %4
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = call i32 @hashtable_insert(%struct.hashtable* %38, i8* %39, i8* %40, i32 %41, i32 %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%46 = load i32, i32* %7
%47 = call i32 @stampa(i8* %45, i32 %46)
br label %9
48: ; preds = %36, %28, %20, %14
ret void
}

LLVM IR (-O2):
%struct.hashtable = type { i32 }
@str = [11 x i8] c"replay key\00"
define void @log_replay(i32 %0, %struct.hashtable* %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = call i32 (i32, ...) @read(i32 %0, i32* %5, i64 4)
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %34
13: ; preds = %2, %26
%14 = call i32 (i32, ...) @read(i32 %0, i32* %6, i64 4)
%15 = icmp eq i32 %14, 4
br i1 %15, label %16, label %34
16: ; preds = %13
%17 = load i32, i32* %5
%18 = call i32 (i32, ...) @read(i32 %0, i8* %7, i32 %17)
%19 = load i32, i32* %5
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %16
%22 = load i32, i32* %6
%23 = call i32 (i32, ...) @read(i32 %0, i8* %8, i32 %22)
%24 = load i32, i32* %6
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %21
%27 = load i32, i32* %5
%28 = call i32 @hashtable_insert(%struct.hashtable* %1, i8* %7, i8* %8, i32 %27, i32 %23)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%30 = load i32, i32* %5
%31 = call i32 @stampa(i8* %7, i32 %30)
%32 = call i32 (i32, ...) @read(i32 %0, i32* %5, i64 4)
%33 = icmp eq i32 %32, 4
br i1 %33, label %13, label %34
34: ; preds = %26, %13, %16, %21, %2
ret void
}