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

/* Variables and functions */
int rl_key_delete(struct rlite *, unsigned char const *, long);
int rl_key_delete_value(struct rlite *, unsigned char, long);
int rl_key_get_ignore_expire(struct rlite *, unsigned char const *, long,
                             unsigned char *, int /*<<< orphan*/ *, long *,
                             unsigned long long *, int /*<<< orphan*/ *, int);
unsigned long long rl_mstime();
int rl_key_delete_with_value(struct rlite *db, const unsigned char *key,
                             long keylen) {
  int retval;
  unsigned char identifier;
  long value_page;
  unsigned long long expires;
  retval = rl_key_get_ignore_expire(db, key, keylen, &identifier, NULL,
                                    &value_page, &expires, NULL, 1);
  if (2 != retval)
    goto cleanup;
  ;
  retval = rl_key_delete_value(db, identifier, value_page);
  if (0 != retval)
    goto cleanup;
  ;
  retval = rl_key_delete(db, key, keylen);
  if (0 != retval)
    goto cleanup;
  ;
  retval = expires != 0 && expires <= rl_mstime() ? 3 : 0;
cleanup:
  return retval;
}


x86 assembly (clang, -O0):
<rl_key_delete_with_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x1d(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x28(%rbp),%r9
lea    -0x30(%rbp),%rax
mov    %rax,(%rsp)
movq   $0x0,0x8(%rsp)
movl   $0x1,0x10(%rsp)
call   1040 <rl_key_get_ignore_expire@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x2,%eax
cmp    -0x1c(%rbp),%eax
je     11a1 <rl_key_delete_with_value+0x61>
jmp    122d <rl_key_delete_with_value+0xed>
mov    -0x8(%rbp),%rdi
mov    -0x1d(%rbp),%al
mov    -0x28(%rbp),%rdx
movzbl %al,%esi
call   1060 <rl_key_delete_value@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
je     11c7 <rl_key_delete_with_value+0x87>
jmp    122d <rl_key_delete_with_value+0xed>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <rl_key_delete@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
je     11eb <rl_key_delete_with_value+0xab>
jmp    122d <rl_key_delete_with_value+0xed>
xor    %eax,%eax
cmpq   $0x0,-0x30(%rbp)
mov    %al,-0x31(%rbp)
je     121a <rl_key_delete_with_value+0xda>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <rl_mstime@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
setbe  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%dl
xor    %eax,%eax
mov    $0x3,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rl_key_delete_with_value>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
sub    $0x8,%rsp
lea    0x18(%rsp),%rax
lea    0x17(%rsp),%rcx
lea    0x20(%rsp),%r9
xor    %r8d,%r8d
push   $0x1
push   $0x0
push   %rax
call   1040 <rl_key_get_ignore_expire@plt>
add    $0x20,%rsp
cmp    $0x2,%eax
jne    11c3 <rl_key_delete_with_value+0x83>
movzbl 0xf(%rsp),%esi
mov    0x18(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <rl_key_delete_value@plt>
test   %eax,%eax
jne    11c3 <rl_key_delete_with_value+0x83>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <rl_key_delete@plt>
test   %eax,%eax
jne    11c3 <rl_key_delete_with_value+0x83>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     11c1 <rl_key_delete_with_value+0x81>
xor    %eax,%eax
call   1030 <rl_mstime@plt>
xor    %ecx,%ecx
cmp    %rax,%rbx
setbe  %cl
lea    (%rcx,%rcx,2),%eax
jmp    11c3 <rl_key_delete_with_value+0x83>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rlite = type { i32 }
define i32 @rl_key_delete_with_value(%struct.rlite* %0, i8* %1, i64 %2) {
%4 = alloca %struct.rlite*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8
%9 = alloca i64
%10 = alloca i64
store %struct.rlite* %0, %struct.rlite** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%11 = load %struct.rlite*, %struct.rlite** %4
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = call i32 @rl_key_get_ignore_expire(%struct.rlite* %11, i8* %12, i64 %13, i8* %8, i32* null, i64* %9, i64* %10, i32* null, i32 1)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp ne i32 2, %15
br i1 %16, label %17, label %18
17: ; preds = %3
br label %45
18: ; preds = %3
%19 = load %struct.rlite*, %struct.rlite** %4
%20 = load i8, i8* %8
%21 = load i64, i64* %9
%22 = call i32 @rl_key_delete_value(%struct.rlite* %19, i8 zeroext %20, i64 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp ne i32 0, %23
br i1 %24, label %25, label %26
25: ; preds = %18
br label %45
26: ; preds = %18
%27 = load %struct.rlite*, %struct.rlite** %4
%28 = load i8*, i8** %5
%29 = load i64, i64* %6
%30 = call i32 @rl_key_delete(%struct.rlite* %27, i8* %28, i64 %29)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp ne i32 0, %31
br i1 %32, label %33, label %34
33: ; preds = %26
br label %45
34: ; preds = %26
%35 = load i64, i64* %10
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %34
%38 = load i64, i64* %10
%39 = call i64 (...) @rl_mstime()
%40 = icmp ule i64 %38, %39
br label %41
41: ; preds = %37, %34
%42 = phi i1 [ false, %34 ], [ %40, %37 ]
%43 = zext i1 %42 to i64
%44 = select i1 %42, i32 3, i32 0
store i32 %44, i32* %7
br label %45
45: ; preds = %41, %33, %25, %17
%46 = load i32, i32* %7
ret i32 %46
}

LLVM IR (-O2):
%struct.rlite = type { i32 }
define i32 @rl_key_delete_with_value(%struct.rlite* %0, i8* %1, i64 %2) {
%4 = alloca i8
%5 = alloca i64
%6 = alloca i64
%7 = bitcast i64* %5 to i8*
%8 = bitcast i64* %6 to i8*
%9 = call i32 @rl_key_get_ignore_expire(%struct.rlite* %0, i8* %1, i64 %2, i8* %4, i32* null, i64* %5, i64* %6, i32* null, i32 1)
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %26
11: ; preds = %3
%12 = load i8, i8* %4
%13 = load i64, i64* %5
%14 = call i32 @rl_key_delete_value(%struct.rlite* %0, i8 zeroext %12, i64 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = call i32 @rl_key_delete(%struct.rlite* %0, i8* %1, i64 %2)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i64, i64* %6
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = call i64 (...) @rl_mstime()
%24 = icmp ugt i64 %20, %23
%25 = select i1 %24, i32 0, i32 3
br label %26
26: ; preds = %19, %22, %16, %11, %3
%27 = phi i32 [ %9, %3 ], [ %14, %11 ], [ %17, %16 ], [ 0, %19 ], [ %25, %22 ]
ret i32 %27
}