#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_str_pfdebug_decode(unsigned char *, long, unsigned char **, long *);
int rl_pfdebug_decode(struct rlite *db, const unsigned char *key, long keylen,
                      unsigned char **value, long *valuelen) {
  int retval;
  unsigned char *str = NULL;
  long strlen;
  retval = rl_get(db, key, keylen, &str, &strlen);
  if (0 != retval)
    goto cleanup;
  ;
  retval = rl_str_pfdebug_decode(str, strlen, value, valuelen);
  if (retval != 0) {
    if (retval == -1 || retval == -2) {
      retval = 1;
    } else {
      retval = 6;
    }
    goto cleanup;
  }
  retval = 0;
cleanup:
  free(str);
  return retval;
}


x86 assembly (clang, -O0):
<rl_pfdebug_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x40(%rbp),%r8
call   1040 <rl_get@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmp    -0x2c(%rbp),%eax
je     1180 <rl_pfdebug_decode+0x50>
jmp    11d5 <rl_pfdebug_decode+0xa5>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <rl_str_pfdebug_decode@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11ce <rl_pfdebug_decode+0x9e>
cmpl   $0xffffffff,-0x2c(%rbp)
je     11b6 <rl_pfdebug_decode+0x86>
cmpl   $0xfffffffe,-0x2c(%rbp)
jne    11c2 <rl_pfdebug_decode+0x92>
movl   $0x1,-0x2c(%rbp)
jmp    11c9 <rl_pfdebug_decode+0x99>
movl   $0x6,-0x2c(%rbp)
jmp    11d5 <rl_pfdebug_decode+0xa5>
movl   $0x0,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rl_pfdebug_decode>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %rcx,%rbx
movq   $0x0,(%rsp)
mov    %rsp,%rcx
lea    0x8(%rsp),%r8
call   1040 <rl_get@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1183 <rl_pfdebug_decode+0x53>
mov    (%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <rl_str_pfdebug_decode@plt>
test   %eax,%eax
je     1181 <rl_pfdebug_decode+0x51>
xor    %ecx,%ecx
cmp    $0xfffffffe,%eax
setb   %cl
lea    (%rcx,%rcx,4),%ebp
add    $0x1,%ebp
jmp    1183 <rl_pfdebug_decode+0x53>
xor    %ebp,%ebp
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlite = type { i32 }
define i32 @rl_pfdebug_decode(%struct.rlite* %0, i8* %1, i64 %2, i8** %3, i64* %4) {
%6 = alloca %struct.rlite*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8**
%10 = alloca i64*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
store %struct.rlite* %0, %struct.rlite** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i8** %3, i8*** %9
store i64* %4, i64** %10
store i8* null, i8** %12
%14 = load %struct.rlite*, %struct.rlite** %6
%15 = load i8*, i8** %7
%16 = load i64, i64* %8
%17 = call i32 @rl_get(%struct.rlite* %14, i8* %15, i64 %16, i8** %12, i64* %13)
store i32 %17, i32* %11
%18 = load i32, i32* %11
%19 = icmp ne i32 0, %18
br i1 %19, label %20, label %21
20: ; preds = %5
br label %39
21: ; preds = %5
%22 = load i8*, i8** %12
%23 = load i64, i64* %13
%24 = load i8**, i8*** %9
%25 = load i64*, i64** %10
%26 = call i32 @rl_str_pfdebug_decode(i8* %22, i64 %23, i8** %24, i64* %25)
store i32 %26, i32* %11
%27 = load i32, i32* %11
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %21
%30 = load i32, i32* %11
%31 = icmp eq i32 %30, -1
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* %11
%34 = icmp eq i32 %33, -2
br i1 %34, label %35, label %36
35: ; preds = %32, %29
store i32 1, i32* %11
br label %37
36: ; preds = %32
store i32 6, i32* %11
br label %37
37: ; preds = %36, %35
br label %39
38: ; preds = %21
store i32 0, i32* %11
br label %39
39: ; preds = %38, %37, %20
%40 = load i8*, i8** %12
%41 = call i32 @free(i8* %40)
%42 = load i32, i32* %11
ret i32 %42
}

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