#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 /*<<< orphan*/ free(unsigned char *);
int rl_get(struct rlite *, unsigned char const *, long, unsigned char **,
           long *);
int rl_key_get(struct rlite *, unsigned char const *, long,
               int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
               unsigned long long *, int /*<<< orphan*/ *);
int rl_set(struct rlite *, unsigned char const *, long, unsigned char *, long,
           int /*<<< orphan*/, unsigned long long);
int rl_str_pfdebug_todense(unsigned char *, long, unsigned char **, long *);
int rl_pfdebug_todense(struct rlite *db, const unsigned char *key, long keylen,
                       int *converted) {
  int retval;
  unsigned char *str = NULL;
  long strlen;
  unsigned long long expires = 0;
  retval = rl_get(db, key, keylen, &str, &strlen);
  if (0 != retval)
    goto cleanup;
  ;
  retval = rl_str_pfdebug_todense(str, strlen, &str, &strlen);
  if (retval != 0 && retval != 1) {
    if (retval == -1) {
      retval = 1;
    } else {
      retval = 6;
    }
    goto cleanup;
  }
  *converted = retval;
  if (retval == 1) {
    retval = rl_key_get(db, key, keylen, NULL, NULL, NULL, &expires, NULL);
    if (2 != retval && 3 != retval)
      goto cleanup;
    ;
    retval = rl_set(db, key, keylen, str, strlen, 0, expires);
    if (0 != retval)
      goto cleanup;
    ;
  }
  retval = 0;
cleanup:
  free(str);
  return retval;
}


x86 assembly (clang, -O0):
<rl_pfdebug_todense>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1050 <rl_get@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
je     11a4 <rl_pfdebug_todense+0x54>
jmp    1299 <rl_pfdebug_todense+0x149>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1070 <rl_str_pfdebug_todense@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11f2 <rl_pfdebug_todense+0xa2>
cmpl   $0x1,-0x24(%rbp)
je     11f2 <rl_pfdebug_todense+0xa2>
cmpl   $0xffffffff,-0x24(%rbp)
jne    11e6 <rl_pfdebug_todense+0x96>
movl   $0x1,-0x24(%rbp)
jmp    11ed <rl_pfdebug_todense+0x9d>
movl   $0x6,-0x24(%rbp)
jmp    1299 <rl_pfdebug_todense+0x149>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x1,-0x24(%rbp)
jne    1292 <rl_pfdebug_todense+0x142>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r9d
lea    -0x40(%rbp),%rax
mov    %r9,%rcx
mov    %r9,%r8
mov    %rax,(%rsp)
movq   $0x0,0x8(%rsp)
call   1040 <rl_key_get@plt>
mov    %eax,-0x24(%rbp)
mov    $0x2,%eax
cmp    -0x24(%rbp),%eax
je     1256 <rl_pfdebug_todense+0x106>
mov    $0x3,%eax
cmp    -0x24(%rbp),%eax
je     1256 <rl_pfdebug_todense+0x106>
jmp    1299 <rl_pfdebug_todense+0x149>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%rax
xor    %r9d,%r9d
mov    %rax,(%rsp)
call   1060 <rl_set@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
je     128d <rl_pfdebug_todense+0x13d>
jmp    1299 <rl_pfdebug_todense+0x149>
jmp    1292 <rl_pfdebug_todense+0x142>
movl   $0x0,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rl_pfdebug_todense>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
call   1050 <rl_get@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1225 <rl_pfdebug_todense+0xd5>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1070 <rl_str_pfdebug_todense@plt>
cmp    $0x2,%eax
jae    1217 <rl_pfdebug_todense+0xc7>
mov    %eax,(%r12)
cmp    $0x1,%eax
jne    1213 <rl_pfdebug_todense+0xc3>
lea    0x18(%rsp),%rax
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x0
push   %rax
call   1040 <rl_key_get@plt>
add    $0x10,%rsp
mov    %eax,%ebp
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    1225 <rl_pfdebug_todense+0xd5>
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%r8
sub    $0x8,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %r9d,%r9d
push   0x20(%rsp)
call   1060 <rl_set@plt>
add    $0x10,%rsp
mov    %eax,%ebp
test   %eax,%eax
jne    1225 <rl_pfdebug_todense+0xd5>
xor    %ebp,%ebp
jmp    1225 <rl_pfdebug_todense+0xd5>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
setne  %cl
lea    (%rcx,%rcx,4),%ebp
add    $0x1,%ebp
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.rlite = type { i32 }
define i32 @rl_pfdebug_todense(%struct.rlite* %0, i8* %1, i64 %2, i32* nocapture writeonly %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%9 = bitcast i64* %6 to i8*
%10 = bitcast i64* %7 to i8*
store i64 0, i64* %7
%11 = call i32 @rl_get(%struct.rlite* %0, i8* %1, i64 %2, i8** %5, i64* %6)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %4
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = call i32 @rl_str_pfdebug_todense(i8* %14, i64 %15, i8** %5, i64* %6)
%17 = icmp ult i32 %16, 2
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = icmp eq i32 %16, -1
%20 = select i1 %19, i32 1, i32 6
br label %34
21: ; preds = %13
store i32 %16, i32* %3
%22 = icmp eq i32 %16, 1
br i1 %22, label %23, label %33
23: ; preds = %21
%24 = call i32 @rl_key_get(%struct.rlite* %0, i8* %1, i64 %2, i32* null, i32* null, i32* null, i64* %7, i32* null)
%25 = and i32 %24, -2
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = load i64, i64* %6
%30 = load i64, i64* %7
%31 = call i32 @rl_set(%struct.rlite* %0, i8* %1, i64 %2, i8* %28, i64 %29, i32 0, i64 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27, %21
br label %34
34: ; preds = %18, %27, %23, %4, %33
%35 = phi i32 [ %11, %4 ], [ %24, %23 ], [ %31, %27 ], [ 0, %33 ], [ %20, %18 ]
%36 = load i8*, i8** %5
%37 = call i32 @free(i8* %36)
ret i32 %35
}