#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_encoding(unsigned char *, long, unsigned char **, long *);
int rl_pfdebug_encoding(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_encoding(str, strlen, value, valuelen);
  if (retval != 0) {
    if (retval == -1) {
      retval = 1;
    } else {
      retval = 6;
    }
    goto cleanup;
  }
  retval = 0;
cleanup:
  free(str);
  return retval;
}


x86 assembly (clang, -O0):
<rl_pfdebug_encoding>:
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   1050 <rl_get@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmp    -0x2c(%rbp),%eax
je     1180 <rl_pfdebug_encoding+0x50>
jmp    11cb <rl_pfdebug_encoding+0x9b>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <rl_str_pfdebug_encoding@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11c4 <rl_pfdebug_encoding+0x94>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11b8 <rl_pfdebug_encoding+0x88>
movl   $0x1,-0x2c(%rbp)
jmp    11bf <rl_pfdebug_encoding+0x8f>
movl   $0x6,-0x2c(%rbp)
jmp    11cb <rl_pfdebug_encoding+0x9b>
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_encoding>:
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   1050 <rl_get@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1180 <rl_pfdebug_encoding+0x50>
mov    (%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <rl_str_pfdebug_encoding@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
setne  %cl
lea    (%rcx,%rcx,4),%ebp
add    $0x1,%ebp
test   %eax,%eax
cmove  %eax,%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_encoding(%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 %36
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_encoding(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 %35
29: ; preds = %21
%30 = load i32, i32* %11
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 1, i32* %11
br label %34
33: ; preds = %29
store i32 6, i32* %11
br label %34
34: ; preds = %33, %32
br label %36
35: ; preds = %21
store i32 0, i32* %11
br label %36
36: ; preds = %35, %34, %20
%37 = load i8*, i8** %12
%38 = call i32 @free(i8* %37)
%39 = load i32, i32* %11
ret i32 %39
}

LLVM IR (-O2):
%struct.rlite = type { i32 }
define i32 @rl_pfdebug_encoding(%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_encoding(i8* %13, i64 %14, i8** %3, i64* %4)
%16 = icmp eq i32 %15, -1
%17 = select i1 %16, i32 1, i32 6
%18 = icmp eq i32 %15, 0
%19 = select i1 %18, i32 0, i32 %17
br label %20
20: ; preds = %12, %5
%21 = phi i32 [ %10, %5 ], [ %19, %12 ]
%22 = load i8*, i8** %6
%23 = call i32 @free(i8* %22)
ret i32 %21
}