#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 */
typedef int /*<<< orphan*/ X509_STORE;
typedef int /*<<< orphan*/ X509_LOOKUP;

/* Variables and functions */
int /*<<< orphan*/ X509_FILETYPE_PEM;
int /*<<< orphan*/ X509_LOOKUP_file();
int X509_LOOKUP_load_file(int /*<<< orphan*/ *, char const *,
                          int /*<<< orphan*/);
int /*<<< orphan*/ *X509_STORE_add_lookup(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/);
int /*<<< orphan*/ X509_STORE_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *X509_STORE_new();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
X509_STORE *init_cert_store(char const *crt_file) {
  int ret = 0;
  X509_STORE *store = X509_STORE_new();
  if (store != NULL) {
    X509_LOOKUP *lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
    ret = X509_LOOKUP_load_file(lookup, crt_file, X509_FILETYPE_PEM);
    if (ret != 1) {
      fprintf(stderr, "Cannot load store (%s), ret = %d\n", crt_file, ret);
      X509_STORE_free(store);
      exit(1);
    }
  } else {
    fprintf(stderr, "Cannot get a new X509 store\n");
    exit(1);
  }
  return store;
}


x86 assembly (clang, -O0):
<init_cert_store>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1070 <X509_STORE_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1210 <init_cert_store+0xa0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <X509_LOOKUP_file@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1040 <X509_STORE_add_lookup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
call   1080 <X509_LOOKUP_load_file@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     120b <init_cert_store+0x9b>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <X509_STORE_free@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1231 <init_cert_store+0xc1>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_cert_store>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1070 <X509_STORE_new@plt>
test   %rax,%rax
je     11bb <init_cert_store+0x4b>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <X509_LOOKUP_file@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <X509_STORE_add_lookup@plt>
mov    0x2e52(%rip),%rcx
mov    (%rcx),%edx
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <X509_LOOKUP_load_file@plt>
cmp    $0x1,%eax
jne    11dc <init_cert_store+0x6c>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2df5(%rip),%rcx
mov    (%rcx),%edi
lea    0xe14(%rip),%rsi
mov    %r14,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <X509_STORE_free@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@X509_FILETYPE_PEM = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"Cannot load store (%s), ret = %d\0A\00"
@.str.1 = [29 x i8] c"Cannot get a new X509 store\0A\00"
define i32* @init_cert_store(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = call i32* (...) @X509_STORE_new()
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %28
9: ; preds = %1
%10 = load i32*, i32** %4
%11 = call i32 (...) @X509_LOOKUP_file()
%12 = call i32* @X509_STORE_add_lookup(i32* %10, i32 %11)
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = load i8*, i8** %2
%15 = load i32, i32* @X509_FILETYPE_PEM
%16 = call i32 @X509_LOOKUP_load_file(i32* %13, i8* %14, i32 %15)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %27
19: ; preds = %9
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %2
%22 = load i32, i32* %3
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %22)
%24 = load i32*, i32** %4
%25 = call i32 @X509_STORE_free(i32* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %9
br label %32
28: ; preds = %1
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %27
%33 = load i32*, i32** %4
ret i32* %33
}

LLVM IR (-O2):
@X509_FILETYPE_PEM = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"Cannot load store (%s), ret = %d\0A\00"
@.str.1 = [29 x i8] c"Cannot get a new X509 store\0A\00"
define i32* @init_cert_store(i8* %0) {
%2 = tail call i32* (...) @X509_STORE_new()
%3 = icmp eq i32* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = tail call i32 (...) @X509_LOOKUP_file()
%6 = tail call i32* @X509_STORE_add_lookup(i32* %2, i32 %5)
%7 = load i32, i32* @X509_FILETYPE_PEM
%8 = tail call i32 @X509_LOOKUP_load_file(i32* %6, i8* %0, i32 %7)
%9 = icmp eq i32 %8, 1
br i1 %9, label %15, label %10
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %8)
%13 = tail call i32 @X509_STORE_free(i32* %2)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %4
ret i32* %2
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
}