#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 */
typedef struct TYPE_7__ TYPE_3__;
typedef struct TYPE_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ X509;
struct TYPE_7__ {
  TYPE_2__ *location;
  int /*<<< orphan*/ method;
};
struct TYPE_5__ {
  int /*<<< orphan*/ ia5;
};
struct TYPE_6__ {
  scalar_t__ type;
  TYPE_1__ d;
};
typedef int /*<<< orphan*/ AUTHORITY_INFO_ACCESS;
typedef TYPE_3__ ACCESS_DESCRIPTION;

/* Variables and functions */
int /*<<< orphan*/ ACCESS_DESCRIPTION_free;
scalar_t__ GEN_URI;
int /*<<< orphan*/ NID_info_access;
int const OBJ_obj2nid(int /*<<< orphan*/);
int /*<<< orphan*/ *X509_get_ext_d2i(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                     int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
char **malloc(int);
int sk_ACCESS_DESCRIPTION_num(int /*<<< orphan*/ *);
int /*<<< orphan*/ sk_ACCESS_DESCRIPTION_pop_free(int /*<<< orphan*/ *,
                                                  int /*<<< orphan*/);
TYPE_3__ *sk_ACCESS_DESCRIPTION_value(int /*<<< orphan*/ *, int);
char *ssl_ia5string_strdup(int /*<<< orphan*/);
char **ssl_x509_aias(X509 *crt, const int type) {
  AUTHORITY_INFO_ACCESS *aias;
  char **res;
  int count, i, j;
  aias = X509_get_ext_d2i(crt, NID_info_access, NULL, NULL);
  if (!aias || !(count = sk_ACCESS_DESCRIPTION_num(aias)))
    return NULL;
  res = malloc((count + 1) * sizeof(char *));
  if (!res) {
    sk_ACCESS_DESCRIPTION_pop_free(aias, ACCESS_DESCRIPTION_free);
    return NULL;
  }
  for (i = 0, j = 0; i < count; i++) {
    ACCESS_DESCRIPTION *aia;
    aia = sk_ACCESS_DESCRIPTION_value(aias, i);
    if (aia && OBJ_obj2nid(aia->method) == type &&
        aia->location->type == GEN_URI) {
      res[j] = ssl_ia5string_strdup(aia->location->d.ia5);
      if (res[j])
        j++;
    }
  }
  res[j] = NULL;
  sk_ACCESS_DESCRIPTION_pop_free(aias, ACCESS_DESCRIPTION_free);
  return res;
}


x86 assembly (clang, -O0):
<ssl_x509_aias>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1070 <X509_get_ext_d2i@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11bc <ssl_x509_aias+0x4c>
mov    -0x20(%rbp),%rdi
call   1030 <sk_ACCESS_DESCRIPTION_num@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jne    11c9 <ssl_x509_aias+0x59>
movq   $0x0,-0x8(%rbp)
jmp    12ea <ssl_x509_aias+0x17a>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    120a <ssl_x509_aias+0x9a>
mov    -0x20(%rbp),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
call   1090 <sk_ACCESS_DESCRIPTION_pop_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12ea <ssl_x509_aias+0x17a>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12c0 <ssl_x509_aias+0x150>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1080 <sk_ACCESS_DESCRIPTION_value@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12ad <ssl_x509_aias+0x13d>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edi
call   1040 <OBJ_obj2nid@plt>
cmp    -0x14(%rbp),%eax
jne    12ad <ssl_x509_aias+0x13d>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x2d83(%rip),%rcx
cmp    (%rcx),%rax
jne    12ad <ssl_x509_aias+0x13d>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x8(%rax),%edi
call   1050 <ssl_ia5string_strdup@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     12a8 <ssl_x509_aias+0x138>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12ad <ssl_x509_aias+0x13d>
jmp    12b2 <ssl_x509_aias+0x142>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1218 <ssl_x509_aias+0xa8>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rdi
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
call   1090 <sk_ACCESS_DESCRIPTION_pop_free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_x509_aias>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,0x4(%rsp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <X509_get_ext_d2i@plt>
test   %rax,%rax
je     125a <ssl_x509_aias+0xea>
mov    %rax,%r12
mov    %rax,%rdi
call   1030 <sk_ACCESS_DESCRIPTION_num@plt>
test   %eax,%eax
je     1241 <ssl_x509_aias+0xd1>
mov    %eax,%r13d
lea    0x8(,%r13,8),%edi
call   1060 <malloc@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1246 <ssl_x509_aias+0xd6>
mov    %rax,%r14
test   %r13d,%r13d
jle    1234 <ssl_x509_aias+0xc4>
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    11e8 <ssl_x509_aias+0x78>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,%r13d
je     1234 <ssl_x509_aias+0xc4>
mov    %r12,%rdi
mov    %ebx,%esi
call   1080 <sk_ACCESS_DESCRIPTION_value@plt>
test   %rax,%rax
je     11e0 <ssl_x509_aias+0x70>
mov    %rax,%rbp
mov    0x8(%rax),%edi
call   1040 <OBJ_obj2nid@plt>
cmp    0x4(%rsp),%eax
jne    11e0 <ssl_x509_aias+0x70>
mov    0x0(%rbp),%rax
mov    (%rax),%rcx
mov    0x2dd2(%rip),%rdx
cmp    (%rdx),%rcx
jne    11e0 <ssl_x509_aias+0x70>
mov    0x8(%rax),%edi
call   1050 <ssl_ia5string_strdup@plt>
movslq %r15d,%r15
mov    %rax,(%r14,%r15,8)
cmp    $0x1,%rax
sbb    $0xffffffff,%r15d
jmp    11e0 <ssl_x509_aias+0x70>
movslq %r15d,%rax
movq   $0x0,(%r14,%rax,8)
jmp    1249 <ssl_x509_aias+0xd9>
xor    %r14d,%r14d
jmp    125a <ssl_x509_aias+0xea>
xor    %r14d,%r14d
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1090 <sk_ACCESS_DESCRIPTION_pop_free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_7__ = type { %struct.TYPE_6__*, i32 }
%struct.TYPE_6__ = type { i64, %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32 }
@NID_info_access = global i32 0
@ACCESS_DESCRIPTION_free = global i32 0
@GEN_URI = global i64 0
define i8** @ssl_x509_aias(i32* %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.TYPE_7__*
store i32* %0, i32** %4
store i32 %1, i32* %5
%12 = load i32*, i32** %4
%13 = load i32, i32* @NID_info_access
%14 = call i32* @X509_get_ext_d2i(i32* %12, i32 %13, i32* null, i32* null)
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32*, i32** %6
%19 = call i32 @sk_ACCESS_DESCRIPTION_num(i32* %18)
store i32 %19, i32* %8
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %17, %2
store i8** null, i8*** %3
br label %96
22: ; preds = %17
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 8
%27 = trunc i64 %26 to i32
%28 = call i8** @malloc(i32 %27)
store i8** %28, i8*** %7
%29 = load i8**, i8*** %7
%30 = icmp ne i8** %29, null
br i1 %30, label %35, label %31
31: ; preds = %22
%32 = load i32*, i32** %6
%33 = load i32, i32* @ACCESS_DESCRIPTION_free
%34 = call i32 @sk_ACCESS_DESCRIPTION_pop_free(i32* %32, i32 %33)
store i8** null, i8*** %3
br label %96
35: ; preds = %22
store i32 0, i32* %9
store i32 0, i32* %10
br label %36
36: ; preds = %84, %35
%37 = load i32, i32* %9
%38 = load i32, i32* %8
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %87
40: ; preds = %36
%41 = load i32*, i32** %6
%42 = load i32, i32* %9
%43 = call %struct.TYPE_7__* @sk_ACCESS_DESCRIPTION_value(i32* %41, i32 %42)
store %struct.TYPE_7__* %43, %struct.TYPE_7__** %11
%44 = load %struct.TYPE_7__*, %struct.TYPE_7__** %11
%45 = icmp ne %struct.TYPE_7__* %44, null
br i1 %45, label %46, label %83
46: ; preds = %40
%47 = load %struct.TYPE_7__*, %struct.TYPE_7__** %11
%48 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %47, i32 0, i32 1
%49 = load i32, i32* %48
%50 = call i32 @OBJ_obj2nid(i32 %49)
%51 = load i32, i32* %5
%52 = icmp eq i32 %50, %51
br i1 %52, label %53, label %83
53: ; preds = %46
%54 = load %struct.TYPE_7__*, %struct.TYPE_7__** %11
%55 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %54, i32 0, i32 0
%56 = load %struct.TYPE_6__*, %struct.TYPE_6__** %55
%57 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %56, i32 0, i32 0
%58 = load i64, i64* %57
%59 = load i64, i64* @GEN_URI
%60 = icmp eq i64 %58, %59
br i1 %60, label %61, label %83
61: ; preds = %53
%62 = load %struct.TYPE_7__*, %struct.TYPE_7__** %11
%63 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %62, i32 0, i32 0
%64 = load %struct.TYPE_6__*, %struct.TYPE_6__** %63
%65 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %64, i32 0, i32 1
%66 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i8* @ssl_ia5string_strdup(i32 %67)
%69 = load i8**, i8*** %7
%70 = load i32, i32* %10
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8*, i8** %69, i64 %71
store i8* %68, i8** %72
%73 = load i8**, i8*** %7
%74 = load i32, i32* %10
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8*, i8** %73, i64 %75
%77 = load i8*, i8** %76
%78 = icmp ne i8* %77, null
br i1 %78, label %79, label %82
79: ; preds = %61
%80 = load i32, i32* %10
%81 = add nsw i32 %80, 1
store i32 %81, i32* %10
br label %82
82: ; preds = %79, %61
br label %83
83: ; preds = %82, %53, %46, %40
br label %84
84: ; preds = %83
%85 = load i32, i32* %9
%86 = add nsw i32 %85, 1
store i32 %86, i32* %9
br label %36
87: ; preds = %36
%88 = load i8**, i8*** %7
%89 = load i32, i32* %10
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8*, i8** %88, i64 %90
store i8* null, i8** %91
%92 = load i32*, i32** %6
%93 = load i32, i32* @ACCESS_DESCRIPTION_free
%94 = call i32 @sk_ACCESS_DESCRIPTION_pop_free(i32* %92, i32 %93)
%95 = load i8**, i8*** %7
store i8** %95, i8*** %3
br label %96
96: ; preds = %87, %31, %21
%97 = load i8**, i8*** %3
ret i8** %97
}

LLVM IR (-O2):
%struct.TYPE_7__ = type { %struct.TYPE_6__*, i32 }
%struct.TYPE_6__ = type { i64, %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32 }
@NID_info_access = global i32 0
@ACCESS_DESCRIPTION_free = global i32 0
@GEN_URI = global i64 0
define noalias i8** @ssl_x509_aias(i32* %0, i32 %1) {
%3 = load i32, i32* @NID_info_access
%4 = tail call i32* @X509_get_ext_d2i(i32* %0, i32 %3, i32* null, i32* null)
%5 = icmp eq i32* %4, null
br i1 %5, label %54, label %6
6: ; preds = %2
%7 = tail call i32 @sk_ACCESS_DESCRIPTION_num(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %54, label %9
9: ; preds = %6
%10 = shl i32 %7, 3
%11 = add i32 %10, 8
%12 = tail call i8** @malloc(i32 %11)
%13 = icmp eq i8** %12, null
br i1 %13, label %50, label %14
14: ; preds = %9
%15 = icmp sgt i32 %7, 0
br i1 %15, label %16, label %46
16: ; preds = %14, %42
%17 = phi i32 [ %43, %42 ], [ 0, %14 ]
%18 = phi i32 [ %44, %42 ], [ 0, %14 ]
%19 = tail call %struct.TYPE_7__* @sk_ACCESS_DESCRIPTION_value(i32* %4, i32 %18)
%20 = icmp eq %struct.TYPE_7__* %19, null
br i1 %20, label %42, label %21
21: ; preds = %16
%22 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %19, i64 0, i32 1
%23 = load i32, i32* %22
%24 = tail call i32 @OBJ_obj2nid(i32 %23)
%25 = icmp eq i32 %24, %1
br i1 %25, label %26, label %42
26: ; preds = %21
%27 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %19, i64 0, i32 0
%28 = load %struct.TYPE_6__*, %struct.TYPE_6__** %27
%29 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %28, i64 0, i32 0
%30 = load i64, i64* %29
%31 = load i64, i64* @GEN_URI
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %42
33: ; preds = %26
%34 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %28, i64 0, i32 1, i32 0
%35 = load i32, i32* %34
%36 = tail call i8* @ssl_ia5string_strdup(i32 %35)
%37 = sext i32 %17 to i64
%38 = getelementptr inbounds i8*, i8** %12, i64 %37
store i8* %36, i8** %38
%39 = icmp ne i8* %36, null
%40 = zext i1 %39 to i32
%41 = add nsw i32 %17, %40
br label %42
42: ; preds = %33, %26, %21, %16
%43 = phi i32 [ %17, %26 ], [ %17, %21 ], [ %17, %16 ], [ %41, %33 ]
%44 = add nuw nsw i32 %18, 1
%45 = icmp eq i32 %44, %7
br i1 %45, label %46, label %16
46: ; preds = %42, %14
%47 = phi i32 [ 0, %14 ], [ %43, %42 ]
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %12, i64 %48
store i8* null, i8** %49
br label %50
50: ; preds = %9, %46
%51 = phi i8** [ %12, %46 ], [ null, %9 ]
%52 = load i32, i32* @ACCESS_DESCRIPTION_free
%53 = tail call i32 @sk_ACCESS_DESCRIPTION_pop_free(i32* %4, i32 %52)
br label %54
54: ; preds = %50, %2, %6
%55 = phi i8** [ null, %6 ], [ null, %2 ], [ %51, %50 ]
ret i8** %55
}