#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int (*check_trust)(TYPE_1__ *, int /*<<< orphan*/ *, int);
};
typedef TYPE_1__ X509_TRUST;
typedef int /*<<< orphan*/ X509;

/* Variables and functions */
TYPE_1__ *X509_TRUST_get0(int);
int X509_TRUST_get_by_id(int);
int default_trust(int, int /*<<< orphan*/ *, int);
int stub1(TYPE_1__ *, int /*<<< orphan*/ *, int);
int X509_check_trust(X509 *x, int id, int flags) {
  X509_TRUST *pt;
  int idx;
  if (id == -1)
    return 1;
  idx = X509_TRUST_get_by_id(id);
  if (idx == -1)
    return default_trust(id, x, flags);
  pt = X509_TRUST_get0(idx);
  return pt->check_trust(pt, x, flags);
}


x86 assembly (clang, -O0):
<X509_check_trust>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1158 <X509_check_trust+0x28>
movl   $0x1,-0x4(%rbp)
jmp    11a7 <X509_check_trust+0x77>
mov    -0x14(%rbp),%edi
call   1030 <X509_TRUST_get_by_id@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1184 <X509_check_trust+0x54>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <default_trust@plt>
mov    %eax,-0x4(%rbp)
jmp    11a7 <X509_check_trust+0x77>
mov    -0x24(%rbp),%edi
call   1050 <X509_TRUST_get0@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   *%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<X509_check_trust>:
push   %rbp
push   %r14
push   %rbx
cmp    $0xffffffff,%esi
je     1166 <X509_check_trust+0x36>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1030 <X509_TRUST_get_by_id@plt>
cmp    $0xffffffff,%eax
je     1170 <X509_check_trust+0x40>
mov    %eax,%edi
call   1050 <X509_TRUST_get0@plt>
mov    (%rax),%rcx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    *%rcx
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <default_trust@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32 (%struct.TYPE_4__*, i32*, i32)* }
define i32 @X509_check_trust(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.TYPE_4__*
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 1, i32* %4
br label %33
13: ; preds = %3
%14 = load i32, i32* %6
%15 = call i32 @X509_TRUST_get_by_id(i32 %14)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i32, i32* %6
%20 = load i32*, i32** %5
%21 = load i32, i32* %7
%22 = call i32 @default_trust(i32 %19, i32* %20, i32 %21)
store i32 %22, i32* %4
br label %33
23: ; preds = %13
%24 = load i32, i32* %9
%25 = call %struct.TYPE_4__* @X509_TRUST_get0(i32 %24)
store %struct.TYPE_4__* %25, %struct.TYPE_4__** %8
%26 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%27 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %26, i32 0, i32 0
%28 = load i32 (%struct.TYPE_4__*, i32*, i32)*, i32 (%struct.TYPE_4__*, i32*, i32)** %27
%29 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%30 = load i32*, i32** %5
%31 = load i32, i32* %7
%32 = call i32 %28(%struct.TYPE_4__* %29, i32* %30, i32 %31)
store i32 %32, i32* %4
br label %33
33: ; preds = %23, %18, %12
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32 (%struct.TYPE_4__*, i32*, i32)* }
define i32 @X509_check_trust(i32* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, -1
br i1 %4, label %15, label %5
5: ; preds = %3
%6 = tail call i32 @X509_TRUST_get_by_id(i32 %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @default_trust(i32 %1, i32* %0, i32 %2)
br label %15
10: ; preds = %5
%11 = tail call %struct.TYPE_4__* @X509_TRUST_get0(i32 %6)
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %11, i64 0, i32 0
%13 = load i32 (%struct.TYPE_4__*, i32*, i32)*, i32 (%struct.TYPE_4__*, i32*, i32)** %12
%14 = tail call i32 %13(%struct.TYPE_4__* %11, i32* %0, i32 %2)
br label %15
15: ; preds = %3, %10, %8
%16 = phi i32 [ %9, %8 ], [ %14, %10 ], [ 1, %3 ]
ret i32 %16
}