#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 sk_num(int /*<<< orphan*/ *);
void *sk_value(int /*<<< orphan*/ *, int);
void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx) {
  if (ad->sk == NULL)
    return (0);
  else if (idx >= sk_num(ad->sk))
    return (0);
  else
    return (sk_value(ad->sk, idx));
}


x86 assembly (clang, -O0):
<CRYPTO_get_ex_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    114a <CRYPTO_get_ex_data+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    1189 <CRYPTO_get_ex_data+0x69>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <sk_num@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jl     1176 <CRYPTO_get_ex_data+0x56>
movq   $0x0,-0x8(%rbp)
jmp    1189 <CRYPTO_get_ex_data+0x69>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
call   1030 <sk_value@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CRYPTO_get_ex_data>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1149 <CRYPTO_get_ex_data+0x29>
mov    %esi,%ebp
call   1040 <sk_num@plt>
cmp    %ebp,%eax
jle    1149 <CRYPTO_get_ex_data+0x29>
mov    (%rbx),%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <sk_value@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32* }
define i8* @CRYPTO_get_ex_data(%struct.TYPE_3__* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca %struct.TYPE_3__*
%5 = alloca i32
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %4
store i32 %1, i32* %5
%6 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%8 = load i32*, i32** %7
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* null, i8** %3
br label %25
11: ; preds = %2
%12 = load i32, i32* %5
%13 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 0
%15 = load i32*, i32** %14
%16 = call i32 @sk_num(i32* %15)
%17 = icmp sge i32 %12, %16
br i1 %17, label %18, label %19
18: ; preds = %11
store i8* null, i8** %3
br label %25
19: ; preds = %11
%20 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i32 0, i32 0
%22 = load i32*, i32** %21
%23 = load i32, i32* %5
%24 = call i8* @sk_value(i32* %22, i32 %23)
store i8* %24, i8** %3
br label %25
25: ; preds = %19, %18, %10
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32* }
define i8* @CRYPTO_get_ex_data(%struct.TYPE_3__* nocapture %0, i32 %1) {
%3 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%4 = load i32*, i32** %3
%5 = icmp eq i32* %4, null
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = tail call i32 @sk_num(i32* %4)
%8 = icmp sgt i32 %7, %1
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32*, i32** %3
%11 = tail call i8* @sk_value(i32* %10, i32 %1)
br label %12
12: ; preds = %6, %2, %9
%13 = phi i8* [ %11, %9 ], [ null, %2 ], [ null, %6 ]
ret i8* %13
}