#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 */
long rand();
int rl_key_delete_with_value(struct rlite *, unsigned char const *, long);
int rl_key_get(struct rlite *, unsigned char const *, long, unsigned char *,
               int /*<<< orphan*/ *, long *, int /*<<< orphan*/ *, long *);
int rl_key_set(struct rlite *, unsigned char const *, long, char, long,
               unsigned long long, long);
int rl_multi_string_set(struct rlite *, long *, unsigned char *, long);
int rl_set(struct rlite *db, const unsigned char *key, long keylen,
           unsigned char *value, long valuelen, int nx,
           unsigned long long expires) {
  int retval;
  long page_number;
  unsigned char type;
  long value_page, version;
  retval =
      rl_key_get(db, key, keylen, &type, NULL, &value_page, NULL, &version);
  if (retval == 2) {
    if (nx) {
      goto cleanup;
    } else {
      retval = rl_key_delete_with_value(db, key, keylen);
      if (0 != retval)
        goto cleanup;
      ;
    }
  } else {
    version = rand();
  }
  retval = rl_multi_string_set(db, &page_number, value, valuelen);
  if (0 != retval)
    goto cleanup;
  ;
  retval = rl_key_set(db, key, keylen, 'T', page_number, expires, version + 1);
  if (0 != retval)
    goto cleanup;
  ;
  retval = 0;
cleanup:
  return retval;
}


x86 assembly (clang, -O0):
<rl_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x39(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x48(%rbp),%r9
lea    -0x50(%rbp),%rax
movq   $0x0,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <rl_key_get@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x2,-0x30(%rbp)
jne    11ed <rl_set+0x9d>
cmpl   $0x0,-0x2c(%rbp)
je     11bf <rl_set+0x6f>
jmp    1264 <rl_set+0x114>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <rl_key_delete_with_value@plt>
mov    %eax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%eax
je     11e3 <rl_set+0x93>
jmp    1264 <rl_set+0x114>
jmp    11e8 <rl_set+0x98>
jmp    11f8 <rl_set+0xa8>
mov    $0x0,%al
call   1070 <rand@plt>
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    -0x38(%rbp),%rsi
call   1040 <rl_multi_string_set@plt>
mov    %eax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%eax
je     1220 <rl_set+0xd0>
jmp    1264 <rl_set+0x114>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%r8
mov    0x10(%rbp),%r9
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    $0x54,%ecx
mov    %rax,(%rsp)
call   1060 <rl_key_set@plt>
mov    %eax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%eax
je     125d <rl_set+0x10d>
jmp    1264 <rl_set+0x114>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rl_set>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%ebp
mov    %r8,%r12
mov    %rcx,%r13
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x10(%rsp),%rax
lea    0xf(%rsp),%rcx
lea    0x20(%rsp),%r9
xor    %r8d,%r8d
push   %rax
push   $0x0
call   1030 <rl_key_get@plt>
add    $0x10,%rsp
cmp    $0x2,%eax
jne    11b0 <rl_set+0x60>
mov    $0x2,%eax
test   %ebp,%ebp
jne    1202 <rl_set+0xb2>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <rl_key_delete_with_value@plt>
test   %eax,%eax
jne    1202 <rl_set+0xb2>
jmp    11bc <rl_set+0x6c>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %rax,0x10(%rsp)
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
call   1040 <rl_multi_string_set@plt>
test   %eax,%eax
jne    1202 <rl_set+0xb2>
mov    0x60(%rsp),%r9
mov    0x18(%rsp),%r8
mov    0x10(%rsp),%rax
add    $0x1,%rax
sub    $0x8,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0x54,%ecx
push   %rax
call   1060 <rl_key_set@plt>
add    $0x10,%rsp
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlite = type { i32 }
define i32 @rl_set(%struct.rlite* %0, i8* %1, i64 %2, i8* %3, i64 %4, i32 %5, i64 %6) {
%8 = alloca %struct.rlite*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i64
%15 = alloca i32
%16 = alloca i64
%17 = alloca i8
%18 = alloca i64
%19 = alloca i64
store %struct.rlite* %0, %struct.rlite** %8
store i8* %1, i8** %9
store i64 %2, i64* %10
store i8* %3, i8** %11
store i64 %4, i64* %12
store i32 %5, i32* %13
store i64 %6, i64* %14
%20 = load %struct.rlite*, %struct.rlite** %8
%21 = load i8*, i8** %9
%22 = load i64, i64* %10
%23 = call i32 @rl_key_get(%struct.rlite* %20, i8* %21, i64 %22, i8* %17, i32* null, i64* %18, i32* null, i64* %19)
store i32 %23, i32* %15
%24 = load i32, i32* %15
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %40
26: ; preds = %7
%27 = load i32, i32* %13
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
br label %63
30: ; preds = %26
%31 = load %struct.rlite*, %struct.rlite** %8
%32 = load i8*, i8** %9
%33 = load i64, i64* %10
%34 = call i32 @rl_key_delete_with_value(%struct.rlite* %31, i8* %32, i64 %33)
store i32 %34, i32* %15
%35 = load i32, i32* %15
%36 = icmp ne i32 0, %35
br i1 %36, label %37, label %38
37: ; preds = %30
br label %63
38: ; preds = %30
br label %39
39: ; preds = %38
br label %42
40: ; preds = %7
%41 = call i64 (...) @rand()
store i64 %41, i64* %19
br label %42
42: ; preds = %40, %39
%43 = load %struct.rlite*, %struct.rlite** %8
%44 = load i8*, i8** %11
%45 = load i64, i64* %12
%46 = call i32 @rl_multi_string_set(%struct.rlite* %43, i64* %16, i8* %44, i64 %45)
store i32 %46, i32* %15
%47 = load i32, i32* %15
%48 = icmp ne i32 0, %47
br i1 %48, label %49, label %50
49: ; preds = %42
br label %63
50: ; preds = %42
%51 = load %struct.rlite*, %struct.rlite** %8
%52 = load i8*, i8** %9
%53 = load i64, i64* %10
%54 = load i64, i64* %16
%55 = load i64, i64* %14
%56 = load i64, i64* %19
%57 = add nsw i64 %56, 1
%58 = call i32 @rl_key_set(%struct.rlite* %51, i8* %52, i64 %53, i8 signext 84, i64 %54, i64 %55, i64 %57)
store i32 %58, i32* %15
%59 = load i32, i32* %15
%60 = icmp ne i32 0, %59
br i1 %60, label %61, label %62
61: ; preds = %50
br label %63
62: ; preds = %50
store i32 0, i32* %15
br label %63
63: ; preds = %62, %61, %49, %37, %29
%64 = load i32, i32* %15
ret i32 %64
}

LLVM IR (-O2):
%struct.rlite = type { i32 }
define i32 @rl_set(%struct.rlite* %0, i8* %1, i64 %2, i8* %3, i64 %4, i32 %5, i64 %6) {
%8 = alloca i64
%9 = alloca i8
%10 = alloca i64
%11 = alloca i64
%12 = bitcast i64* %8 to i8*
%13 = bitcast i64* %10 to i8*
%14 = bitcast i64* %11 to i8*
%15 = call i32 @rl_key_get(%struct.rlite* %0, i8* %1, i64 %2, i8* %9, i32* null, i64* %10, i32* null, i64* %11)
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %22
17: ; preds = %7
%18 = icmp eq i32 %5, 0
br i1 %18, label %19, label %32
19: ; preds = %17
%20 = call i32 @rl_key_delete_with_value(%struct.rlite* %0, i8* %1, i64 %2)
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %32
22: ; preds = %7
%23 = call i64 (...) @rand()
store i64 %23, i64* %11
br label %24
24: ; preds = %19, %22
%25 = call i32 @rl_multi_string_set(%struct.rlite* %0, i64* %8, i8* %3, i64 %4)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i64, i64* %8
%29 = load i64, i64* %11
%30 = add nsw i64 %29, 1
%31 = call i32 @rl_key_set(%struct.rlite* %0, i8* %1, i64 %2, i8 signext 84, i64 %28, i64 %6, i64 %30)
br label %32
32: ; preds = %27, %24, %19, %17
%33 = phi i32 [ 2, %17 ], [ %20, %19 ], [ %25, %24 ], [ %31, %27 ]
ret i32 %33
}