#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 */
int /*<<< orphan*/ NID_anyExtendedKeyUsage;
int X509_TRUST_UNTRUSTED;
TYPE_1__ *X509_TRUST_get0(int);
int X509_TRUST_get_by_id(int);
int default_trust(int, int /*<<< orphan*/ *, int);
int obj_trust(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/);
int stub1(TYPE_1__ *, int /*<<< orphan*/ *, int);
int trust_compat(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/);
int X509_check_trust(X509 *x, int id, int flags) {
  X509_TRUST *pt;
  int idx;
  if (id == -1)
    return 1;
  if (id == 0) {
    int rv;
    rv = obj_trust(NID_anyExtendedKeyUsage, x, 0);
    if (rv != X509_TRUST_UNTRUSTED)
      return rv;
    return trust_compat(NULL, x, 0);
  }
  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    1178 <X509_check_trust+0x28>
movl   $0x1,-0x4(%rbp)
jmp    121c <X509_check_trust+0xcc>
cmpl   $0x0,-0x14(%rbp)
jne    11cd <X509_check_trust+0x7d>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1050 <obj_trust@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2e45(%rip),%rcx
cmp    (%rcx),%eax
je     11b6 <X509_check_trust+0x66>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121c <X509_check_trust+0xcc>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
xor    %edx,%edx
call   1070 <trust_compat@plt>
mov    %eax,-0x4(%rbp)
jmp    121c <X509_check_trust+0xcc>
mov    -0x14(%rbp),%edi
call   1030 <X509_TRUST_get_by_id@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11f9 <X509_check_trust+0xa9>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <default_trust@plt>
mov    %eax,-0x4(%rbp)
jmp    121c <X509_check_trust+0xcc>
mov    -0x24(%rbp),%edi
call   1060 <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     1190 <X509_check_trust+0x40>
mov    %esi,%ebp
mov    %rdi,%rbx
test   %esi,%esi
jne    119a <X509_check_trust+0x4a>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <obj_trust@plt>
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%eax
jne    1195 <X509_check_trust+0x45>
xor    %edi,%edi
mov    %rbx,%rsi
xor    %edx,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <trust_compat@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %edx,%r14d
mov    %ebp,%edi
call   1030 <X509_TRUST_get_by_id@plt>
cmp    $0xffffffff,%eax
je     11c2 <X509_check_trust+0x72>
mov    %eax,%edi
call   1060 <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    %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)* }
@NID_anyExtendedKeyUsage = global i32 0
@X509_TRUST_UNTRUSTED = global i32 0
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
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 1, i32* %4
br label %49
14: ; preds = %3
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = load i32, i32* @NID_anyExtendedKeyUsage
%19 = load i32*, i32** %5
%20 = call i32 @obj_trust(i32 %18, i32* %19, i32 0)
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = load i32, i32* @X509_TRUST_UNTRUSTED
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = load i32, i32* %10
store i32 %25, i32* %4
br label %49
26: ; preds = %17
%27 = load i32*, i32** %5
%28 = call i32 @trust_compat(i32* null, i32* %27, i32 0)
store i32 %28, i32* %4
br label %49
29: ; preds = %14
%30 = load i32, i32* %6
%31 = call i32 @X509_TRUST_get_by_id(i32 %30)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i32, i32* %6
%36 = load i32*, i32** %5
%37 = load i32, i32* %7
%38 = call i32 @default_trust(i32 %35, i32* %36, i32 %37)
store i32 %38, i32* %4
br label %49
39: ; preds = %29
%40 = load i32, i32* %9
%41 = call %struct.TYPE_4__* @X509_TRUST_get0(i32 %40)
store %struct.TYPE_4__* %41, %struct.TYPE_4__** %8
%42 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%43 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %42, i32 0, i32 0
%44 = load i32 (%struct.TYPE_4__*, i32*, i32)*, i32 (%struct.TYPE_4__*, i32*, i32)** %43
%45 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%46 = load i32*, i32** %5
%47 = load i32, i32* %7
%48 = call i32 %44(%struct.TYPE_4__* %45, i32* %46, i32 %47)
store i32 %48, i32* %4
br label %49
49: ; preds = %39, %34, %26, %24, %13
%50 = load i32, i32* %4
ret i32 %50
}

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