#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*/ ERR_clear_error();
int /*<<< orphan*/ X509_FILETYPE_DEFAULT;
int /*<<< orphan*/ X509_FILETYPE_PEM;
int /*<<< orphan*/ X509_LOOKUP_add_dir(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *,
                                       int /*<<< orphan*/);
int /*<<< orphan*/ X509_LOOKUP_file();
int /*<<< orphan*/ X509_LOOKUP_hash_dir();
int /*<<< orphan*/ X509_LOOKUP_load_file(int /*<<< orphan*/ *, char *,
                                         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*/ warnx(char *, ...);
X509_STORE *read_cacerts(char *file) {
  X509_STORE *store;
  X509_LOOKUP *lookup;
  if ((store = X509_STORE_new()) == NULL) {
    warnx("Malloc failed");
    goto end;
  }
  if ((lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file())) == NULL) {
    warnx("Unable to load CA certs from file %s", file);
    goto end;
  }
  if (file) {
    if (!X509_LOOKUP_load_file(lookup, file, X509_FILETYPE_PEM)) {
      warnx("Unable to load CA certs from file %s", file);
      goto end;
    }
  } else
    X509_LOOKUP_load_file(lookup, NULL, X509_FILETYPE_DEFAULT);
  if ((lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir())) == NULL) {
    warnx("Unable to load CA certs from file %s", file);
    goto end;
  }
  X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);
  ERR_clear_error();
  return store;
end:
  X509_STORE_free(store);
  return NULL;
}


x86 assembly (clang, -O0):
<read_cacerts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <X509_STORE_new@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c4 <read_cacerts+0x34>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <warnx@plt>
jmp    12c8 <read_cacerts+0x138>
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)
cmp    $0x0,%rax
jne    1203 <read_cacerts+0x73>
mov    -0x10(%rbp),%rsi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <warnx@plt>
jmp    12c8 <read_cacerts+0x138>
cmpq   $0x0,-0x10(%rbp)
je     1249 <read_cacerts+0xb9>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2dcb(%rip),%rax
mov    (%rax),%edx
call   10b0 <X509_LOOKUP_load_file@plt>
cmp    $0x0,%eax
jne    1244 <read_cacerts+0xb4>
mov    -0x10(%rbp),%rsi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1050 <warnx@plt>
jmp    12c8 <read_cacerts+0x138>
jmp    125f <read_cacerts+0xcf>
mov    -0x20(%rbp),%rdi
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <X509_LOOKUP_load_file@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1080 <X509_LOOKUP_hash_dir@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1040 <X509_STORE_add_lookup@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    129e <read_cacerts+0x10e>
mov    -0x10(%rbp),%rsi
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1050 <warnx@plt>
jmp    12c8 <read_cacerts+0x138>
mov    -0x20(%rbp),%rdi
mov    0x2d47(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <X509_LOOKUP_add_dir@plt>
mov    $0x0,%al
call   1070 <ERR_clear_error@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d9 <read_cacerts+0x149>
mov    -0x18(%rbp),%rdi
call   1090 <X509_STORE_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_cacerts>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   10a0 <X509_STORE_new@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11db <read_cacerts+0x4b>
xor    %eax,%eax
call   1030 <X509_LOOKUP_file@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <X509_STORE_add_lookup@plt>
test   %rax,%rax
je     1230 <read_cacerts+0xa0>
test   %r14,%r14
je     11eb <read_cacerts+0x5b>
mov    0x2e20(%rip),%rcx
mov    (%rcx),%edx
mov    %rax,%rdi
mov    %r14,%rsi
call   10b0 <X509_LOOKUP_load_file@plt>
test   %eax,%eax
jne    11fe <read_cacerts+0x6e>
jmp    1230 <read_cacerts+0xa0>
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1050 <warnx@plt>
jmp    1241 <read_cacerts+0xb1>
mov    0x2dfe(%rip),%rcx
mov    (%rcx),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   10b0 <X509_LOOKUP_load_file@plt>
xor    %eax,%eax
call   1080 <X509_LOOKUP_hash_dir@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <X509_STORE_add_lookup@plt>
test   %rax,%rax
je     1230 <read_cacerts+0xa0>
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <X509_LOOKUP_add_dir@plt>
xor    %eax,%eax
call   1070 <ERR_clear_error@plt>
jmp    124b <read_cacerts+0xbb>
lea    0xdd7(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <warnx@plt>
mov    %rbx,%rdi
call   1090 <X509_STORE_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Malloc failed\00"
@.str.1 = [37 x i8] c"Unable to load CA certs from file %s\00"
@X509_FILETYPE_PEM = global i32 0
@X509_FILETYPE_DEFAULT = global i32 0
define i32* @read_cacerts(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
store i8* %0, i8** %3
%6 = call i32* (...) @X509_STORE_new()
store i32* %6, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %49
10: ; preds = %1
%11 = load i32*, i32** %4
%12 = call i32 (...) @X509_LOOKUP_file()
%13 = call i32* @X509_STORE_add_lookup(i32* %11, i32 %12)
store i32* %13, i32** %5
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %49
18: ; preds = %10
%19 = load i8*, i8** %3
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i32*, i32** %5
%23 = load i8*, i8** %3
%24 = load i32, i32* @X509_FILETYPE_PEM
%25 = call i32 @X509_LOOKUP_load_file(i32* %22, i8* %23, i32 %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %21
%28 = load i8*, i8** %3
%29 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %49
30: ; preds = %21
br label %35
31: ; preds = %18
%32 = load i32*, i32** %5
%33 = load i32, i32* @X509_FILETYPE_DEFAULT
%34 = call i32 @X509_LOOKUP_load_file(i32* %32, i8* null, i32 %33)
br label %35
35: ; preds = %31, %30
%36 = load i32*, i32** %4
%37 = call i32 (...) @X509_LOOKUP_hash_dir()
%38 = call i32* @X509_STORE_add_lookup(i32* %36, i32 %37)
store i32* %38, i32** %5
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i8*, i8** %3
%42 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %41)
br label %49
43: ; preds = %35
%44 = load i32*, i32** %5
%45 = load i32, i32* @X509_FILETYPE_DEFAULT
%46 = call i32 @X509_LOOKUP_add_dir(i32* %44, i32* null, i32 %45)
%47 = call i32 (...) @ERR_clear_error()
%48 = load i32*, i32** %4
store i32* %48, i32** %2
br label %52
49: ; preds = %40, %27, %15, %8
%50 = load i32*, i32** %4
%51 = call i32 @X509_STORE_free(i32* %50)
store i32* null, i32** %2
br label %52
52: ; preds = %49, %43
%53 = load i32*, i32** %2
ret i32* %53
}

LLVM IR (-O2):
@.str = [14 x i8] c"Malloc failed\00"
@.str.1 = [37 x i8] c"Unable to load CA certs from file %s\00"
@X509_FILETYPE_PEM = global i32 0
@X509_FILETYPE_DEFAULT = global i32 0
define i32* @read_cacerts(i8* %0) {
%2 = tail call i32* (...) @X509_STORE_new()
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %33
6: ; preds = %1
%7 = tail call i32 (...) @X509_LOOKUP_file()
%8 = tail call i32* @X509_STORE_add_lookup(i32* %2, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %33
12: ; preds = %6
%13 = icmp eq i8* %0, null
br i1 %13, label %20, label %14
14: ; preds = %12
%15 = load i32, i32* @X509_FILETYPE_PEM
%16 = tail call i32 @X509_LOOKUP_load_file(i32* %8, i8* %0, i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %33
20: ; preds = %12
%21 = load i32, i32* @X509_FILETYPE_DEFAULT
%22 = tail call i32 @X509_LOOKUP_load_file(i32* %8, i8* null, i32 %21)
br label %23
23: ; preds = %14, %20
%24 = tail call i32 (...) @X509_LOOKUP_hash_dir()
%25 = tail call i32* @X509_STORE_add_lookup(i32* %2, i32 %24)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %33
29: ; preds = %23
%30 = load i32, i32* @X509_FILETYPE_DEFAULT
%31 = tail call i32 @X509_LOOKUP_add_dir(i32* %25, i32* null, i32 %30)
%32 = tail call i32 (...) @ERR_clear_error()
br label %35
33: ; preds = %27, %18, %10, %4
%34 = tail call i32 @X509_STORE_free(i32* %2)
br label %35
35: ; preds = %33, %29
%36 = phi i32* [ null, %33 ], [ %2, %29 ]
ret i32* %36
}