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

/* Variables and functions */
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ X509_FILETYPE_PEM;
int /*<<< orphan*/ X509_LOOKUP_file();
int /*<<< orphan*/ X509_STORE_CTX_free(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*/ X509_load_cert_file(int /*<<< orphan*/ *, char const *,
                                       int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int test_509_dup_cert(const char *cert_f) {
  int ret = 0;
  X509_STORE_CTX *sctx = NULL;
  X509_STORE *store = NULL;
  X509_LOOKUP *lookup = NULL;
  store = X509_STORE_new();
  if (store == NULL)
    goto err;
  lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
  if (lookup == NULL)
    goto err;
  if (!X509_load_cert_file(lookup, cert_f, X509_FILETYPE_PEM))
    goto err;
  if (!X509_load_cert_file(lookup, cert_f, X509_FILETYPE_PEM))
    goto err;
  ret = 1;
err:
  X509_STORE_CTX_free(sctx);
  X509_STORE_free(store);
  if (ret != 1)
    ERR_print_errors_fp(stderr);
  return ret;
}


x86 assembly (clang, -O0):
<test_509_dup_cert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1080 <X509_STORE_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b6 <test_509_dup_cert+0x46>
jmp    1233 <test_509_dup_cert+0xc3>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <X509_LOOKUP_file@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1040 <X509_STORE_add_lookup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e4 <test_509_dup_cert+0x74>
jmp    1233 <test_509_dup_cert+0xc3>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
call   1070 <X509_load_cert_file@plt>
cmp    $0x0,%eax
jne    1208 <test_509_dup_cert+0x98>
jmp    1233 <test_509_dup_cert+0xc3>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
call   1070 <X509_load_cert_file@plt>
cmp    $0x0,%eax
jne    122c <test_509_dup_cert+0xbc>
jmp    1233 <test_509_dup_cert+0xc3>
movl   $0x1,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <X509_STORE_CTX_free@plt>
mov    -0x20(%rbp),%rdi
call   1060 <X509_STORE_free@plt>
cmpl   $0x1,-0xc(%rbp)
je     125d <test_509_dup_cert+0xed>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1090 <ERR_print_errors_fp@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_509_dup_cert>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <X509_STORE_new@plt>
mov    %rax,%r15
mov    $0x0,%ebp
test   %rax,%rax
je     11e5 <test_509_dup_cert+0x75>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <X509_LOOKUP_file@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <X509_STORE_add_lookup@plt>
mov    $0x0,%ebp
test   %rax,%rax
je     11e5 <test_509_dup_cert+0x75>
mov    %rax,%r12
mov    0x2e38(%rip),%rbx
mov    (%rbx),%edx
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <X509_load_cert_file@plt>
test   %eax,%eax
je     11e1 <test_509_dup_cert+0x71>
mov    (%rbx),%edx
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <X509_load_cert_file@plt>
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
mov    %ebx,%ebp
jmp    11e5 <test_509_dup_cert+0x75>
xor    %ebx,%ebx
xor    %ebp,%ebp
xor    %edi,%edi
call   1050 <X509_STORE_CTX_free@plt>
mov    %r15,%rdi
call   1060 <X509_STORE_free@plt>
test   %bl,%bl
jne    1206 <test_509_dup_cert+0x96>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1090 <ERR_print_errors_fp@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@X509_FILETYPE_PEM = global i32 0
@stderr = global i32 0
define i32 @test_509_dup_cert(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %3
store i32* null, i32** %4
store i32* null, i32** %5
store i32* null, i32** %6
%7 = call i32* (...) @X509_STORE_new()
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
br label %33
11: ; preds = %1
%12 = load i32*, i32** %5
%13 = call i32 (...) @X509_LOOKUP_file()
%14 = call i32* @X509_STORE_add_lookup(i32* %12, i32 %13)
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %11
br label %33
18: ; preds = %11
%19 = load i32*, i32** %6
%20 = load i8*, i8** %2
%21 = load i32, i32* @X509_FILETYPE_PEM
%22 = call i32 @X509_load_cert_file(i32* %19, i8* %20, i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %18
br label %33
25: ; preds = %18
%26 = load i32*, i32** %6
%27 = load i8*, i8** %2
%28 = load i32, i32* @X509_FILETYPE_PEM
%29 = call i32 @X509_load_cert_file(i32* %26, i8* %27, i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %25
br label %33
32: ; preds = %25
store i32 1, i32* %3
br label %33
33: ; preds = %32, %31, %24, %17, %10
%34 = load i32*, i32** %4
%35 = call i32 @X509_STORE_CTX_free(i32* %34)
%36 = load i32*, i32** %5
%37 = call i32 @X509_STORE_free(i32* %36)
%38 = load i32, i32* %3
%39 = icmp ne i32 %38, 1
br i1 %39, label %40, label %43
40: ; preds = %33
%41 = load i32, i32* @stderr
%42 = call i32 @ERR_print_errors_fp(i32 %41)
br label %43
43: ; preds = %40, %33
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@X509_FILETYPE_PEM = global i32 0
@stderr = global i32 0
define i32 @test_509_dup_cert(i8* %0) {
%2 = tail call i32* (...) @X509_STORE_new()
%3 = icmp eq i32* %2, null
br i1 %3, label %17, 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 = icmp eq i32* %6, null
br i1 %7, label %17, label %8
8: ; preds = %4
%9 = load i32, i32* @X509_FILETYPE_PEM
%10 = tail call i32 @X509_load_cert_file(i32* %6, i8* %0, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = load i32, i32* @X509_FILETYPE_PEM
%14 = tail call i32 @X509_load_cert_file(i32* %6, i8* %0, i32 %13)
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %12, %8, %4, %1
%18 = phi i1 [ false, %8 ], [ false, %4 ], [ false, %1 ], [ %15, %12 ]
%19 = phi i32 [ 0, %8 ], [ 0, %4 ], [ 0, %1 ], [ %16, %12 ]
%20 = tail call i32 @X509_STORE_CTX_free(i32* null)
%21 = tail call i32 @X509_STORE_free(i32* %2)
br i1 %18, label %25, label %22
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = tail call i32 @ERR_print_errors_fp(i32 %23)
br label %25
25: ; preds = %22, %17
ret i32 %19
}