#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 aaip_state {
  int dummy;
};

/* Variables and functions */
size_t aaip_count_bytes(unsigned char *, int /*<<< orphan*/);
int aaip_decode_attrs(struct aaip_state **, size_t, size_t, unsigned char *,
                      size_t, size_t *, int);
int aaip_get_decoded_attrs(struct aaip_state **, size_t *, char ***, size_t **,
                           char ***, int);
int /*<<< orphan*/ attrs_cleanout_name(char *, size_t *, char **, size_t *,
                                       char **, int);
int iso_aa_get_attrs(unsigned char *aa_string, size_t *num_attrs, char ***names,
                     size_t **value_lengths, char ***values, int flag) {
  struct aaip_state *aaip = NULL;
  unsigned char *rpt;
  size_t len, todo, consumed;
  int is_done = 0, first_round = 1, ret;
  if (flag & (1 << 15))
    aaip_get_decoded_attrs(&aaip, num_attrs, names, value_lengths, values,
                           1 << 15);
  *num_attrs = 0;
  *names = NULL;
  *value_lengths = NULL;
  *values = NULL;
  if (flag & (1 << 15))
    return 1;
  rpt = aa_string;
  len = aaip_count_bytes(rpt, 0);
  while (!is_done) {
    todo = len - (rpt - aa_string);
    if (todo > 2048)
      todo = 2048;
    if (todo == 0) {
      ret = 0xE830FEAC;
      goto ex;
    }
    ret = aaip_decode_attrs(&aaip, (size_t)1000000, (size_t)100000, rpt, todo,
                            &consumed, first_round);
    rpt += consumed;
    first_round = 0;
    if (ret == 1)
      continue;
    if (ret == 2)
      break;
    ret = 0xE830FEAC;
    goto ex;
  }
  if ((size_t)(rpt - aa_string) != len) {
    ret = 0xE830FEAC;
    goto ex;
  }
  ret =
      aaip_get_decoded_attrs(&aaip, num_attrs, names, value_lengths, values, 0);
  if (ret != 1) {
    ret = 0xE830FEAC;
    goto ex;
  }
  if (!(flag & 1)) {
    attrs_cleanout_name("", num_attrs, *names, *value_lengths, *values,
                        !!(flag & 4));
  }
  ret = 1;
ex:;
  aaip_decode_attrs(&aaip, (size_t)1000000, (size_t)100000, rpt, todo,
                    &consumed, 1 << 15);
  return ret;
}


x86 assembly (clang, -O0):
<iso_aa_get_attrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x1,-0x68(%rbp)
mov    -0x34(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     11a9 <iso_aa_get_attrs+0x69>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    -0x40(%rbp),%rdi
mov    $0x8000,%r9d
call   1030 <aaip_get_decoded_attrs@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x34(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     11f2 <iso_aa_get_attrs+0xb2>
movl   $0x1,-0x4(%rbp)
jmp    139a <iso_aa_get_attrs+0x25a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
xor    %esi,%esi
call   1060 <aaip_count_bytes@plt>
mov    %rax,-0x50(%rbp)
cmpl   $0x0,-0x64(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    121f <iso_aa_get_attrs+0xdf>
jmp    12c7 <iso_aa_get_attrs+0x187>
mov    -0x50(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
sub    %rcx,%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x800,-0x58(%rbp)
jbe    124b <iso_aa_get_attrs+0x10b>
movq   $0x800,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1262 <iso_aa_get_attrs+0x122>
movl   $0xe830feac,-0x6c(%rbp)
jmp    136e <iso_aa_get_attrs+0x22e>
mov    -0x48(%rbp),%rcx
mov    -0x58(%rbp),%r8
mov    -0x68(%rbp),%eax
lea    -0x40(%rbp),%rdi
mov    $0xf4240,%esi
mov    $0x186a0,%edx
lea    -0x60(%rbp),%r9
mov    %eax,(%rsp)
call   1050 <aaip_decode_attrs@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x60(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x68(%rbp)
cmpl   $0x1,-0x6c(%rbp)
jne    12ac <iso_aa_get_attrs+0x16c>
jmp    1209 <iso_aa_get_attrs+0xc9>
cmpl   $0x2,-0x6c(%rbp)
jne    12bb <iso_aa_get_attrs+0x17b>
jmp    12c7 <iso_aa_get_attrs+0x187>
movl   $0xe830feac,-0x6c(%rbp)
jmp    136e <iso_aa_get_attrs+0x22e>
mov    -0x48(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    -0x50(%rbp),%rax
je     12e8 <iso_aa_get_attrs+0x1a8>
movl   $0xe830feac,-0x6c(%rbp)
jmp    136e <iso_aa_get_attrs+0x22e>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    -0x40(%rbp),%rdi
xor    %r9d,%r9d
call   1030 <aaip_get_decoded_attrs@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x1,-0x6c(%rbp)
je     131d <iso_aa_get_attrs+0x1dd>
movl   $0xe830feac,-0x6c(%rbp)
jmp    136e <iso_aa_get_attrs+0x22e>
mov    -0x34(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1367 <iso_aa_get_attrs+0x227>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
mov    -0x30(%rbp),%rax
mov    (%rax),%r8
mov    -0x34(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r9d
lea    0xc9e(%rip),%rdi
call   1040 <attrs_cleanout_name@plt>
movl   $0x1,-0x6c(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x58(%rbp),%r8
lea    -0x40(%rbp),%rdi
mov    $0xf4240,%esi
mov    $0x186a0,%edx
lea    -0x60(%rbp),%r9
movl   $0x8000,(%rsp)
call   1050 <aaip_decode_attrs@plt>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iso_aa_get_attrs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,%rbx
movq   $0x0,0x10(%rsp)
test   $0x8000,%r9d
jne    12bd <iso_aa_get_attrs+0x17d>
mov    %rdi,%r12
mov    %r9d,0x1c(%rsp)
mov    %rbx,0x40(%rsp)
movq   $0x0,(%rbx)
mov    %rbp,0x20(%rsp)
movq   $0x0,0x0(%rbp)
mov    %r15,0x30(%rsp)
movq   $0x0,(%r15)
mov    %r14,0x38(%rsp)
movq   $0x0,(%r14)
xor    %esi,%esi
call   1060 <aaip_count_bytes@plt>
mov    %rax,%r13
mov    $0x1,%ecx
lea    0x28(%rsp),%r15
mov    %r12,%rbx
mov    $0xe830feac,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rbp
sub    %rbx,%rbp
add    %r13,%rbp
cmp    $0x800,%rbp
mov    $0x800,%eax
cmovae %rax,%rbp
test   %rbp,%rbp
je     1295 <iso_aa_get_attrs+0x155>
mov    %ecx,(%rsp)
mov    $0xf4240,%esi
mov    $0x186a0,%edx
lea    0x10(%rsp),%rdi
mov    %rbx,%rcx
mov    %rbp,%r8
mov    %r15,%r9
call   1050 <aaip_decode_attrs@plt>
add    0x28(%rsp),%rbx
xor    %ecx,%ecx
cmp    $0x1,%eax
je     11d0 <iso_aa_get_attrs+0x90>
cmp    $0x2,%eax
jne    1295 <iso_aa_get_attrs+0x155>
mov    %rbx,%rax
sub    %r12,%rax
cmp    %r13,%rax
jne    1295 <iso_aa_get_attrs+0x155>
lea    0x10(%rsp),%rdi
mov    0x40(%rsp),%r15
mov    %r15,%rsi
mov    0x20(%rsp),%rdx
mov    0x30(%rsp),%r13
mov    %r13,%rcx
mov    0x38(%rsp),%r12
mov    %r12,%r8
xor    %r9d,%r9d
call   1030 <aaip_get_decoded_attrs@plt>
cmp    $0x1,%eax
jne    1295 <iso_aa_get_attrs+0x155>
mov    $0x1,%r14d
mov    0x1c(%rsp),%r9d
test   $0x1,%r9b
jne    1295 <iso_aa_get_attrs+0x155>
mov    0x20(%rsp),%rax
mov    (%rax),%rdx
mov    0x0(%r13),%rcx
mov    (%r12),%r8
shr    $0x2,%r9d
and    $0x1,%r9d
lea    0xd73(%rip),%rdi
mov    %r15,%rsi
call   1040 <attrs_cleanout_name@plt>
movl   $0x8000,(%rsp)
lea    0x10(%rsp),%rdi
lea    0x28(%rsp),%r9
mov    $0xf4240,%esi
mov    $0x186a0,%edx
mov    %rbx,%rcx
mov    %rbp,%r8
call   1050 <aaip_decode_attrs@plt>
jmp    12fc <iso_aa_get_attrs+0x1bc>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
mov    %r14,%r8
mov    $0x8000,%r9d
call   1030 <aaip_get_decoded_attrs@plt>
movq   $0x0,(%rbx)
movq   $0x0,0x0(%rbp)
movq   $0x0,(%r15)
movq   $0x0,(%r14)
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.aaip_state = type { i32 }
@.str = [1 x i8] zeroinitializer
define i32 @iso_aa_get_attrs(i8* %0, i64* %1, i8*** %2, i64** %3, i8*** %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64*
%10 = alloca i8***
%11 = alloca i64**
%12 = alloca i8***
%13 = alloca i32
%14 = alloca %struct.aaip_state*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i8* %0, i8** %8
store i64* %1, i64** %9
store i8*** %2, i8**** %10
store i64** %3, i64*** %11
store i8*** %4, i8**** %12
store i32 %5, i32* %13
store %struct.aaip_state* null, %struct.aaip_state** %14
store i32 0, i32* %19
store i32 1, i32* %20
%22 = load i32, i32* %13
%23 = and i32 %22, 32768
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %6
%26 = load i64*, i64** %9
%27 = load i8***, i8**** %10
%28 = load i64**, i64*** %11
%29 = load i8***, i8**** %12
%30 = call i32 @aaip_get_decoded_attrs(%struct.aaip_state** %14, i64* %26, i8*** %27, i64** %28, i8*** %29, i32 32768)
br label %31
31: ; preds = %25, %6
%32 = load i64*, i64** %9
store i64 0, i64* %32
%33 = load i8***, i8**** %10
store i8** null, i8*** %33
%34 = load i64**, i64*** %11
store i64* null, i64** %34
%35 = load i8***, i8**** %12
store i8** null, i8*** %35
%36 = load i32, i32* %13
%37 = and i32 %36, 32768
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %31
store i32 1, i32* %7
br label %122
40: ; preds = %31
%41 = load i8*, i8** %8
store i8* %41, i8** %15
%42 = load i8*, i8** %15
%43 = call i64 @aaip_count_bytes(i8* %42, i32 0)
store i64 %43, i64* %16
br label %44
44: ; preds = %73, %40
%45 = load i32, i32* %19
%46 = icmp ne i32 %45, 0
%47 = xor i1 %46, true
br i1 %47, label %48, label %79
48: ; preds = %44
%49 = load i64, i64* %16
%50 = load i8*, i8** %15
%51 = load i8*, i8** %8
%52 = ptrtoint i8* %50 to i64
%53 = ptrtoint i8* %51 to i64
%54 = sub i64 %52, %53
%55 = sub i64 %49, %54
store i64 %55, i64* %17
%56 = load i64, i64* %17
%57 = icmp ugt i64 %56, 2048
br i1 %57, label %58, label %59
58: ; preds = %48
store i64 2048, i64* %17
br label %59
59: ; preds = %58, %48
%60 = load i64, i64* %17
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59
store i32 -399442260, i32* %21
br label %117
63: ; preds = %59
%64 = load i8*, i8** %15
%65 = load i64, i64* %17
%66 = load i32, i32* %20
%67 = call i32 @aaip_decode_attrs(%struct.aaip_state** %14, i64 1000000, i64 100000, i8* %64, i64 %65, i64* %18, i32 %66)
store i32 %67, i32* %21
%68 = load i64, i64* %18
%69 = load i8*, i8** %15
%70 = getelementptr inbounds i8, i8* %69, i64 %68
store i8* %70, i8** %15
store i32 0, i32* %20
%71 = load i32, i32* %21
%72 = icmp eq i32 %71, 1
br i1 %72, label %73, label %74
73: ; preds = %63
br label %44
74: ; preds = %63
%75 = load i32, i32* %21
%76 = icmp eq i32 %75, 2
br i1 %76, label %77, label %78
77: ; preds = %74
br label %79
78: ; preds = %74
store i32 -399442260, i32* %21
br label %117
79: ; preds = %77, %44
%80 = load i8*, i8** %15
%81 = load i8*, i8** %8
%82 = ptrtoint i8* %80 to i64
%83 = ptrtoint i8* %81 to i64
%84 = sub i64 %82, %83
%85 = load i64, i64* %16
%86 = icmp ne i64 %84, %85
br i1 %86, label %87, label %88
87: ; preds = %79
store i32 -399442260, i32* %21
br label %117
88: ; preds = %79
%89 = load i64*, i64** %9
%90 = load i8***, i8**** %10
%91 = load i64**, i64*** %11
%92 = load i8***, i8**** %12
%93 = call i32 @aaip_get_decoded_attrs(%struct.aaip_state** %14, i64* %89, i8*** %90, i64** %91, i8*** %92, i32 0)
store i32 %93, i32* %21
%94 = load i32, i32* %21
%95 = icmp ne i32 %94, 1
br i1 %95, label %96, label %97
96: ; preds = %88
store i32 -399442260, i32* %21
br label %117
97: ; preds = %88
%98 = load i32, i32* %13
%99 = and i32 %98, 1
%100 = icmp ne i32 %99, 0
br i1 %100, label %116, label %101
101: ; preds = %97
%102 = load i64*, i64** %9
%103 = load i8***, i8**** %10
%104 = load i8**, i8*** %103
%105 = load i64**, i64*** %11
%106 = load i64*, i64** %105
%107 = load i8***, i8**** %12
%108 = load i8**, i8*** %107
%109 = load i32, i32* %13
%110 = and i32 %109, 4
%111 = icmp ne i32 %110, 0
%112 = xor i1 %111, true
%113 = xor i1 %112, true
%114 = zext i1 %113 to i32
%115 = call i32 @attrs_cleanout_name(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i64* %102, i8** %104, i64* %106, i8** %108, i32 %114)
br label %116
116: ; preds = %101, %97
store i32 1, i32* %21
br label %117
117: ; preds = %116, %96, %87, %78, %62
%118 = load i8*, i8** %15
%119 = load i64, i64* %17
%120 = call i32 @aaip_decode_attrs(%struct.aaip_state** %14, i64 1000000, i64 100000, i8* %118, i64 %119, i64* %18, i32 32768)
%121 = load i32, i32* %21
store i32 %121, i32* %7
br label %122
122: ; preds = %117, %39
%123 = load i32, i32* %7
ret i32 %123
}

LLVM IR (-O2):
%struct.aaip_state = type { i32 }
@.str = [1 x i8] zeroinitializer
define i32 @iso_aa_get_attrs(i8* %0, i64* %1, i8*** %2, i64** %3, i8*** %4, i32 %5) {
%7 = alloca %struct.aaip_state*
%8 = alloca i64
%9 = bitcast %struct.aaip_state** %7 to i8*
store %struct.aaip_state* null, %struct.aaip_state** %7
%10 = bitcast i64* %8 to i8*
%11 = and i32 %5, 32768
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %6
%14 = call i32 @aaip_get_decoded_attrs(%struct.aaip_state** %7, i64* %1, i8*** %2, i64** %3, i8*** %4, i32 32768)
store i64 0, i64* %1
store i8** null, i8*** %2
store i64* null, i64** %3
store i8** null, i8*** %4
br label %52
15: ; preds = %6
store i64 0, i64* %1
store i8** null, i8*** %2
store i64* null, i64** %3
store i8** null, i8*** %4
%16 = tail call i64 @aaip_count_bytes(i8* %0, i32 0)
%17 = ptrtoint i8* %0 to i64
br label %18
18: ; preds = %27, %15
%19 = phi i8* [ %0, %15 ], [ %30, %27 ]
%20 = phi i32 [ 1, %15 ], [ 0, %27 ]
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %17, %21
%23 = add i64 %22, %16
%24 = icmp ult i64 %23, 2048
%25 = select i1 %24, i64 %23, i64 2048
%26 = icmp eq i64 %25, 0
br i1 %26, label %48, label %27
27: ; preds = %18
%28 = call i32 @aaip_decode_attrs(%struct.aaip_state** %7, i64 1000000, i64 100000, i8* %19, i64 %25, i64* %8, i32 %20)
%29 = load i64, i64* %8
%30 = getelementptr inbounds i8, i8* %19, i64 %29
switch i32 %28, label %48 [
i32 1, label %18
i32 2, label %31
]
31: ; preds = %27
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %32, %17
%34 = icmp eq i64 %33, %16
br i1 %34, label %35, label %48
35: ; preds = %31
%36 = call i32 @aaip_get_decoded_attrs(%struct.aaip_state** %7, i64* %1, i8*** %2, i64** %3, i8*** %4, i32 0)
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = and i32 %5, 1
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = load i8**, i8*** %2
%43 = load i64*, i64** %3
%44 = load i8**, i8*** %4
%45 = lshr i32 %5, 2
%46 = and i32 %45, 1
%47 = call i32 @attrs_cleanout_name(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i64* %1, i8** %42, i64* %43, i8** %44, i32 %46)
br label %48
48: ; preds = %27, %18, %38, %41, %35, %31
%49 = phi i8* [ %30, %31 ], [ %30, %35 ], [ %30, %41 ], [ %30, %38 ], [ %30, %27 ], [ %19, %18 ]
%50 = phi i32 [ -399442260, %31 ], [ -399442260, %35 ], [ 1, %41 ], [ 1, %38 ], [ -399442260, %18 ], [ -399442260, %27 ]
%51 = call i32 @aaip_decode_attrs(%struct.aaip_state** %7, i64 1000000, i64 100000, i8* %49, i64 %25, i64* %8, i32 32768)
br label %52
52: ; preds = %13, %48
%53 = phi i32 [ %50, %48 ], [ 1, %13 ]
ret i32 %53
}