#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*/ CRYPTO_F_CRYPTO_SET_EX_DATA;
int /*<<< orphan*/ CRYPTOerr(int /*<<< orphan*/, 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) {
      CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, ERR_R_MALLOC_FAILURE);
      return (0);
    }
  }
  i = sk_void_num(ad->sk);
  while (i <= idx) {
    if (!sk_void_push(ad->sk, NULL)) {
      CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, 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    11b1 <CRYPTO_set_ex_data+0x61>
mov    $0x0,%al
call   1070 <sk_void_new_null@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11ac <CRYPTO_set_ex_data+0x5c>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
call   1050 <CRYPTOerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1230 <CRYPTO_set_ex_data+0xe0>
jmp    11b1 <CRYPTO_set_ex_data+0x61>
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     1216 <CRYPTO_set_ex_data+0xc6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <sk_void_push@plt>
cmp    $0x0,%eax
jne    1208 <CRYPTO_set_ex_data+0xb8>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
call   1050 <CRYPTOerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1230 <CRYPTO_set_ex_data+0xe0>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c0 <CRYPTO_set_ex_data+0x70>
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     11d3 <CRYPTO_set_ex_data+0x83>
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    11ea <CRYPTO_set_ex_data+0x9a>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
call   1050 <CRYPTOerr@plt>
xor    %ebp,%ebp
jmp    11ea <CRYPTO_set_ex_data+0x9a>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
call   1050 <CRYPTOerr@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32* }
@CRYPTO_F_CRYPTO_SET_EX_DATA = global i32 0
@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 %23
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 %22
18: ; preds = %13
%19 = load i32, i32* @CRYPTO_F_CRYPTO_SET_EX_DATA
%20 = load i32, i32* @ERR_R_MALLOC_FAILURE
%21 = call i32 @CRYPTOerr(i32 %19, i32 %20)
store i32 0, i32* %4
br label %52
22: ; preds = %13
br label %23
23: ; preds = %22, %3
%24 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %24, i32 0, i32 0
%26 = load i32*, i32** %25
%27 = call i32 @sk_void_num(i32* %26)
store i32 %27, i32* %8
br label %28
28: ; preds = %42, %23
%29 = load i32, i32* %8
%30 = load i32, i32* %6
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %45
32: ; preds = %28
%33 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %33, i32 0, i32 0
%35 = load i32*, i32** %34
%36 = call i32 @sk_void_push(i32* %35, i32* null)
%37 = icmp ne i32 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %32
%39 = load i32, i32* @CRYPTO_F_CRYPTO_SET_EX_DATA
%40 = load i32, i32* @ERR_R_MALLOC_FAILURE
%41 = call i32 @CRYPTOerr(i32 %39, i32 %40)
store i32 0, i32* %4
br label %52
42: ; preds = %32
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %28
45: ; preds = %28
%46 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %46, i32 0, i32 0
%48 = load i32*, i32** %47
%49 = load i32, i32* %6
%50 = load i8*, i8** %7
%51 = call i32 @sk_void_set(i32* %48, i32 %49, i8* %50)
store i32 1, i32* %4
br label %52
52: ; preds = %45, %38, %18
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32* }
@CRYPTO_F_CRYPTO_SET_EX_DATA = global i32 0
@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 %14
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 %14
10: ; preds = %7
%11 = load i32, i32* @CRYPTO_F_CRYPTO_SET_EX_DATA
%12 = load i32, i32* @ERR_R_MALLOC_FAILURE
%13 = tail call i32 @CRYPTOerr(i32 %11, i32 %12)
br label %33
14: ; preds = %7, %3
%15 = phi i32* [ %8, %7 ], [ %5, %3 ]
%16 = tail call i32 @sk_void_num(i32* %15)
%17 = icmp sgt i32 %16, %1
br i1 %17, label %30, label %21
18: ; preds = %21
%19 = add i32 %22, 1
%20 = icmp eq i32 %22, %1
br i1 %20, label %30, label %21
21: ; preds = %14, %18
%22 = phi i32 [ %19, %18 ], [ %16, %14 ]
%23 = load i32*, i32** %4
%24 = tail call i32 @sk_void_push(i32* %23, i32* null)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %18
26: ; preds = %21
%27 = load i32, i32* @CRYPTO_F_CRYPTO_SET_EX_DATA
%28 = load i32, i32* @ERR_R_MALLOC_FAILURE
%29 = tail call i32 @CRYPTOerr(i32 %27, i32 %28)
br label %33
30: ; preds = %18, %14
%31 = load i32*, i32** %4
%32 = tail call i32 @sk_void_set(i32* %31, i32 %1, i8* %2)
br label %33
33: ; preds = %30, %26, %10
%34 = phi i32 [ 0, %10 ], [ 0, %26 ], [ 1, %30 ]
ret i32 %34
}