#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_getreg(unsigned char *, long, int *, long **,
                          unsigned char **, long *);
int rl_pfdebug_getreg(struct rlite *db, const unsigned char *key, long keylen,
                      int *size, long **elements) {
  int retval;
  unsigned char *value = NULL;
  long valuelen = 0;
  retval = rl_get(db, key, keylen, &value, &valuelen);
  if (0 != retval)
    goto cleanup;
  ;
  retval =
      rl_str_pfdebug_getreg(value, valuelen, size, elements, &value, &valuelen);
  if (retval != 0) {
    if (retval == -1) {
      retval = 1;
    } else if (retval == -3) {
      retval = 4;
    } else {
      retval = 6;
    }
    goto cleanup;
  }
  retval = 0;
cleanup:
  free(value);
  return retval;
}


x86 assembly (clang, -O0):
<rl_pfdebug_getreg>:
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)
movq   $0x0,-0x40(%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     1188 <rl_pfdebug_getreg+0x58>
jmp    11f6 <rl_pfdebug_getreg+0xc6>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    -0x38(%rbp),%r8
lea    -0x40(%rbp),%r9
call   1050 <rl_str_pfdebug_getreg@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11ef <rl_pfdebug_getreg+0xbf>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11c8 <rl_pfdebug_getreg+0x98>
movl   $0x1,-0x2c(%rbp)
jmp    11ea <rl_pfdebug_getreg+0xba>
cmpl   $0xfffffffd,-0x2c(%rbp)
jne    11de <rl_pfdebug_getreg+0xae>
movl   $0x4,-0x2c(%rbp)
jmp    11e5 <rl_pfdebug_getreg+0xb5>
movl   $0x6,-0x2c(%rbp)
jmp    11ea <rl_pfdebug_getreg+0xba>
jmp    11f6 <rl_pfdebug_getreg+0xc6>
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_getreg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %rcx,%rbx
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rcx
lea    0x8(%rsp),%r8
call   1040 <rl_get@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1197 <rl_pfdebug_getreg+0x67>
mov    (%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %rsp,%r8
lea    0x8(%rsp),%r9
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <rl_str_pfdebug_getreg@plt>
add    $0x3,%eax
mov    $0x6,%ebp
cmp    $0x3,%eax
ja     1197 <rl_pfdebug_getreg+0x67>
cltq
lea    0xe6c(%rip),%rcx
mov    (%rcx,%rax,4),%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_getreg(%struct.rlite* %0, i8* %1, i64 %2, i32* %3, i64** %4) {
%6 = alloca %struct.rlite*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%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 i32* %3, i32** %9
store i64** %4, i64*** %10
store i8* null, i8** %12
store i64 0, i64* %13
%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 %41
21: ; preds = %5
%22 = load i8*, i8** %12
%23 = load i64, i64* %13
%24 = load i32*, i32** %9
%25 = load i64**, i64*** %10
%26 = call i32 @rl_str_pfdebug_getreg(i8* %22, i64 %23, i32* %24, i64** %25, i8** %12, i64* %13)
store i32 %26, i32* %11
%27 = load i32, i32* %11
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %40
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 %39
33: ; preds = %29
%34 = load i32, i32* %11
%35 = icmp eq i32 %34, -3
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 4, i32* %11
br label %38
37: ; preds = %33
store i32 6, i32* %11
br label %38
38: ; preds = %37, %36
br label %39
39: ; preds = %38, %32
br label %41
40: ; preds = %21
store i32 0, i32* %11
br label %41
41: ; preds = %40, %39, %20
%42 = load i8*, i8** %12
%43 = call i32 @free(i8* %42)
%44 = load i32, i32* %11
ret i32 %44
}

LLVM IR (-O2):
%struct.rlite = type { i32 }
@switch.table.rl_pfdebug_getreg = [4 x i32] [i32 4, i32 6, i32 1, i32 0]
define i32 @rl_pfdebug_getreg(%struct.rlite* %0, i8* %1, i64 %2, i32* %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*
store i64 0, i64* %7
%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 %22
12: ; preds = %5
%13 = load i8*, i8** %6
%14 = load i64, i64* %7
%15 = call i32 @rl_str_pfdebug_getreg(i8* %13, i64 %14, i32* %3, i64** %4, i8** %6, i64* %7)
%16 = add i32 %15, 3
%17 = icmp ult i32 %16, 4
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = sext i32 %16 to i64
%20 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.rl_pfdebug_getreg, i64 0, i64 %19
%21 = load i32, i32* %20
br label %22
22: ; preds = %12, %18, %5
%23 = phi i32 [ %10, %5 ], [ %21, %18 ], [ 6, %12 ]
%24 = load i8*, i8** %6
%25 = call i32 @free(i8* %24)
ret i32 %23
}