#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ *sk;
};
typedef TYPE_1__ CRYPTO_EX_DATA;

/* Variables and functions */
int /*<<< orphan*/ CRYPTOerror(int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ *sk_void_new_null();
int sk_void_num(int /*<<< orphan*/ *);
int /*<<< orphan*/ sk_void_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sk_void_set(int /*<<< orphan*/ *, int, void *);
int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val) {
  int i;
  if (ad->sk == NULL) {
    if ((ad->sk = sk_void_new_null()) == NULL) {
      CRYPTOerror(ERR_R_MALLOC_FAILURE);
      return (0);
    }
  }
  i = sk_void_num(ad->sk);
  while (i <= idx) {
    if (!sk_void_push(ad->sk, NULL)) {
      CRYPTOerror(ERR_R_MALLOC_FAILURE);
      return (0);
    }
    i++;
  }
  sk_void_set(ad->sk, idx, val);
  return (1);
}


x86 assembly (clang, -O0):
<CRYPTO_set_ex_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11a8 <CRYPTO_set_ex_data+0x58>
mov    $0x0,%al
call   1070 <sk_void_new_null@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11a3 <CRYPTO_set_ex_data+0x53>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1050 <CRYPTOerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    121e <CRYPTO_set_ex_data+0xce>
jmp    11a8 <CRYPTO_set_ex_data+0x58>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <sk_void_num@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1204 <CRYPTO_set_ex_data+0xb4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <sk_void_push@plt>
cmp    $0x0,%eax
jne    11f6 <CRYPTO_set_ex_data+0xa6>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1050 <CRYPTOerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    121e <CRYPTO_set_ex_data+0xce>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b7 <CRYPTO_set_ex_data+0x67>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <sk_void_set@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CRYPTO_set_ex_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
jne    117c <CRYPTO_set_ex_data+0x2c>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <sk_void_new_null@plt>
mov    %rax,%rdi
mov    %rax,(%rbx)
test   %rax,%rax
je     11ca <CRYPTO_set_ex_data+0x7a>
call   1060 <sk_void_num@plt>
cmp    %r15d,%eax
jg     11a3 <CRYPTO_set_ex_data+0x53>
mov    %r15d,%ebp
sub    %eax,%ebp
add    $0x1,%ebp
xchg   %ax,%ax
mov    (%rbx),%rdi
xor    %esi,%esi
call   1030 <sk_void_push@plt>
test   %eax,%eax
je     11b8 <CRYPTO_set_ex_data+0x68>
add    $0xffffffff,%ebp
jne    1190 <CRYPTO_set_ex_data+0x40>
mov    (%rbx),%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1040 <sk_void_set@plt>
mov    $0x1,%ebp
jmp    11d8 <CRYPTO_set_ex_data+0x88>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <CRYPTOerror@plt>
xor    %ebp,%ebp
jmp    11d8 <CRYPTO_set_ex_data+0x88>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1050 <CRYPTOerror@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32* }
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @CRYPTO_set_ex_data(%struct.TYPE_3__* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%11 = load i32*, i32** %10
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %22
13: ; preds = %3
%14 = call i32* (...) @sk_void_new_null()
%15 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %15, i32 0, i32 0
store i32* %14, i32** %16
%17 = icmp eq i32* %14, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* @ERR_R_MALLOC_FAILURE
%20 = call i32 @CRYPTOerror(i32 %19)
store i32 0, i32* %4
br label %50
21: ; preds = %13
br label %22
22: ; preds = %21, %3
%23 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 0
%25 = load i32*, i32** %24
%26 = call i32 @sk_void_num(i32* %25)
store i32 %26, i32* %8
br label %27
27: ; preds = %40, %22
%28 = load i32, i32* %8
%29 = load i32, i32* %6
%30 = icmp sle i32 %28, %29
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%33 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %32, i32 0, i32 0
%34 = load i32*, i32** %33
%35 = call i32 @sk_void_push(i32* %34, i32* null)
%36 = icmp ne i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %31
%38 = load i32, i32* @ERR_R_MALLOC_FAILURE
%39 = call i32 @CRYPTOerror(i32 %38)
store i32 0, i32* %4
br label %50
40: ; preds = %31
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %27
43: ; preds = %27
%44 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%45 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %44, i32 0, i32 0
%46 = load i32*, i32** %45
%47 = load i32, i32* %6
%48 = load i8*, i8** %7
%49 = call i32 @sk_void_set(i32* %46, i32 %47, i8* %48)
store i32 1, i32* %4
br label %50
50: ; preds = %43, %37, %18
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32* }
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @CRYPTO_set_ex_data(%struct.TYPE_3__* nocapture %0, i32 %1, i8* %2) {
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%5 = load i32*, i32** %4
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = tail call i32* (...) @sk_void_new_null()
store i32* %8, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @ERR_R_MALLOC_FAILURE
%12 = tail call i32 @CRYPTOerror(i32 %11)
br label %31
13: ; preds = %7, %3
%14 = phi i32* [ %8, %7 ], [ %5, %3 ]
%15 = tail call i32 @sk_void_num(i32* %14)
%16 = icmp sgt i32 %15, %1
br i1 %16, label %28, label %20
17: ; preds = %20
%18 = add i32 %21, 1
%19 = icmp eq i32 %21, %1
br i1 %19, label %28, label %20
20: ; preds = %13, %17
%21 = phi i32 [ %18, %17 ], [ %15, %13 ]
%22 = load i32*, i32** %4
%23 = tail call i32 @sk_void_push(i32* %22, i32* null)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %17
25: ; preds = %20
%26 = load i32, i32* @ERR_R_MALLOC_FAILURE
%27 = tail call i32 @CRYPTOerror(i32 %26)
br label %31
28: ; preds = %17, %13
%29 = load i32*, i32** %4
%30 = tail call i32 @sk_void_set(i32* %29, i32 %1, i8* %2)
br label %31
31: ; preds = %28, %25, %10
%32 = phi i32 [ 0, %10 ], [ 0, %25 ], [ 1, %28 ]
ret i32 %32
}