#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 iovec {
  int iov_len;
  void *iov_base;
};
typedef int /*<<< orphan*/ X509_STORE;
typedef int /*<<< orphan*/ X509_LOOKUP;

/* Variables and functions */
int /*<<< orphan*/ X509_FILETYPE_PEM;
int X509_LOOKUP_add_mem(int /*<<< orphan*/ *, struct iovec *,
                        int /*<<< orphan*/);
int /*<<< orphan*/ X509_LOOKUP_mem();
int /*<<< orphan*/ *X509_STORE_add_lookup(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/);
int X509_STORE_load_mem(X509_STORE *ctx, void *buf, int len) {
  X509_LOOKUP *lookup;
  struct iovec iov;
  lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_mem());
  if (lookup == NULL)
    return (0);
  iov.iov_base = buf;
  iov.iov_len = len;
  if (X509_LOOKUP_add_mem(lookup, &iov, X509_FILETYPE_PEM) != 1)
    return (0);
  return (1);
}


x86 assembly (clang, -O0):
<X509_STORE_load_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1040 <X509_LOOKUP_mem@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1030 <X509_STORE_add_lookup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1178 <X509_STORE_load_mem+0x48>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <X509_STORE_load_mem+0x88>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rsi
call   1050 <X509_LOOKUP_add_mem@plt>
cmp    $0x1,%eax
je     11b1 <X509_STORE_load_mem+0x81>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <X509_STORE_load_mem+0x88>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<X509_STORE_load_mem>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <X509_LOOKUP_mem@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <X509_STORE_add_lookup@plt>
test   %rax,%rax
je     1183 <X509_STORE_load_mem+0x53>
mov    %r15,0x10(%rsp)
mov    %r14d,0x8(%rsp)
mov    0x2e84(%rip),%rcx
mov    (%rcx),%edx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1050 <X509_LOOKUP_add_mem@plt>
xor    %ebx,%ebx
cmp    $0x1,%eax
sete   %bl
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.iovec = type { i32, i8* }
@X509_FILETYPE_PEM = global i32 0
define i32 @X509_STORE_load_mem(i32* %0, i8* %1, i32 %2) {
%4 = alloca %struct.iovec
%5 = bitcast %struct.iovec* %4 to i8*
%6 = tail call i32 (...) @X509_LOOKUP_mem()
%7 = tail call i32* @X509_STORE_add_lookup(i32* %0, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %16, label %9
9: ; preds = %3
%10 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i64 0, i32 1
store i8* %1, i8** %10
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i64 0, i32 0
store i32 %2, i32* %11
%12 = load i32, i32* @X509_FILETYPE_PEM
%13 = call i32 @X509_LOOKUP_add_mem(i32* %7, %struct.iovec* %4, i32 %12)
%14 = icmp eq i32 %13, 1
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %9, %3
%17 = phi i32 [ 0, %3 ], [ %15, %9 ]
ret i32 %17
}