#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_pfadd(unsigned char *, long, int, unsigned char **, long *,
                 unsigned char **, long *);
int rl_pfadd(struct rlite *db, const unsigned char *key, long keylen,
             int elementc, unsigned char **elements, long *elementslen,
             int *updated) {
  int retval;
  unsigned char *value = NULL;
  long valuelen = 0;
  unsigned long long expires = 0;
  retval = rl_get(db, key, keylen, &value, &valuelen);
  if (0 != retval && 3 != retval)
    goto cleanup;
  ;
  if (retval == 0) {
    retval = rl_key_get(db, key, keylen, NULL, NULL, NULL, &expires, NULL);
    if (2 != retval)
      goto cleanup;
    ;
  }
  retval = rl_str_pfadd(value, valuelen, elementc, elements, elementslen,
                        &value, &valuelen);
  if (retval != 0 && retval != 1) {
    if (retval == -1) {
      retval = 1;
    } else {
      retval = 6;
    }
    goto cleanup;
  }
  if (updated) {
    *updated = retval;
  }
  if (retval == 1) {
    retval = rl_set(db, key, keylen, value, valuelen, 0, expires);
    if (0 != retval)
      goto cleanup;
  }
  retval = 0;
cleanup:
  free(value);
  return retval;
}


x86 assembly (clang, -O0):
<rl_pfadd>:
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    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x48(%rbp),%r8
call   1050 <rl_get@plt>
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
cmp    -0x34(%rbp),%eax
je     11c5 <rl_pfadd+0x75>
mov    $0x3,%eax
cmp    -0x34(%rbp),%eax
je     11c5 <rl_pfadd+0x75>
jmp    12d5 <rl_pfadd+0x185>
cmpl   $0x0,-0x34(%rbp)
jne    1217 <rl_pfadd+0xc7>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r9d
lea    -0x50(%rbp),%rax
mov    %r9,%rcx
mov    %r9,%r8
mov    %rax,(%rsp)
movq   $0x0,0x8(%rsp)
call   1040 <rl_key_get@plt>
mov    %eax,-0x34(%rbp)
mov    $0x2,%eax
cmp    -0x34(%rbp),%eax
je     1212 <rl_pfadd+0xc2>
jmp    12d5 <rl_pfadd+0x185>
jmp    1217 <rl_pfadd+0xc7>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    -0x40(%rbp),%r9
lea    -0x48(%rbp),%rax
mov    %rax,(%rsp)
call   1060 <rl_str_pfadd@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1274 <rl_pfadd+0x124>
cmpl   $0x1,-0x34(%rbp)
je     1274 <rl_pfadd+0x124>
cmpl   $0xffffffff,-0x34(%rbp)
jne    1268 <rl_pfadd+0x118>
movl   $0x1,-0x34(%rbp)
jmp    126f <rl_pfadd+0x11f>
movl   $0x6,-0x34(%rbp)
jmp    12d5 <rl_pfadd+0x185>
cmpq   $0x0,0x10(%rbp)
je     1288 <rl_pfadd+0x138>
mov    -0x34(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x1,-0x34(%rbp)
jne    12ce <rl_pfadd+0x17e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x50(%rbp),%rax
xor    %r9d,%r9d
mov    %rax,(%rsp)
call   1070 <rl_set@plt>
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
cmp    -0x34(%rbp),%eax
je     12c9 <rl_pfadd+0x179>
jmp    12d5 <rl_pfadd+0x185>
jmp    12ce <rl_pfadd+0x17e>
movl   $0x0,-0x34(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rl_pfadd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x30(%rsp)
mov    %r8,0x28(%rsp)
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movq   $0x0,0x10(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x10(%rsp),%rcx
lea    0x18(%rsp),%r12
mov    %r12,%r8
call   1050 <rl_get@plt>
cmp    $0x3,%eax
je     11e0 <rl_pfadd+0x90>
mov    %eax,%r13d
test   %eax,%eax
jne    125a <rl_pfadd+0x10a>
lea    0x20(%rsp),%rax
mov    %rax,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <rl_key_get@plt>
mov    %eax,%r13d
cmp    $0x2,%eax
jne    125a <rl_pfadd+0x10a>
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    %r12,(%rsp)
lea    0x10(%rsp),%r9
mov    %ebp,%edx
mov    0x28(%rsp),%rcx
mov    0x30(%rsp),%r8
call   1060 <rl_str_pfadd@plt>
cmp    $0x2,%eax
jae    124a <rl_pfadd+0xfa>
mov    0x70(%rsp),%rcx
test   %rcx,%rcx
je     1215 <rl_pfadd+0xc5>
mov    %eax,(%rcx)
cmp    $0x1,%eax
jne    1245 <rl_pfadd+0xf5>
mov    0x10(%rsp),%rcx
mov    0x18(%rsp),%r8
mov    0x20(%rsp),%rax
mov    %rax,(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %r9d,%r9d
call   1070 <rl_set@plt>
mov    %eax,%r13d
test   %eax,%eax
jne    125a <rl_pfadd+0x10a>
xor    %r13d,%r13d
jmp    125a <rl_pfadd+0x10a>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
setne  %cl
lea    (%rcx,%rcx,4),%r13d
add    $0x1,%r13d
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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