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

/* Variables and functions */
int EXFLAG_XKUSAGE;
int /*<<< orphan*/ OCSP_F_OCSP_CHECK_DELEGATED;
int /*<<< orphan*/ OCSP_R_MISSING_OCSPSIGNING_USAGE;
int /*<<< orphan*/ OCSPerr(int /*<<< orphan*/, int /*<<< orphan*/);
int X509_get_extended_key_usage(int /*<<< orphan*/ *);
int X509_get_extension_flags(int /*<<< orphan*/ *);
int XKU_OCSP_SIGN;
int ocsp_check_delegated(X509 *x, int flags) {
  if ((X509_get_extension_flags(x) & EXFLAG_XKUSAGE) &&
      (X509_get_extended_key_usage(x) & XKU_OCSP_SIGN))
    return 1;
  OCSPerr(OCSP_F_OCSP_CHECK_DELEGATED, OCSP_R_MISSING_OCSPSIGNING_USAGE);
  return 0;
}


x86 assembly (clang, -O0):
<ocsp_check_delegated>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <X509_get_extension_flags@plt>
mov    0x2e79(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1181 <ocsp_check_delegated+0x51>
mov    -0x10(%rbp),%rdi
call   1040 <X509_get_extended_key_usage@plt>
mov    0x2e76(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1181 <ocsp_check_delegated+0x51>
movl   $0x1,-0x4(%rbp)
jmp    119f <ocsp_check_delegated+0x6f>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1050 <OCSPerr@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ocsp_check_delegated>:
push   %rbx
mov    %rdi,%rbx
call   1030 <X509_get_extension_flags@plt>
mov    0x2e88(%rip),%rcx
test   %eax,(%rcx)
je     1160 <ocsp_check_delegated+0x30>
mov    %rbx,%rdi
call   1040 <X509_get_extended_key_usage@plt>
mov    %eax,%ecx
mov    0x2e8b(%rip),%rdx
mov    $0x1,%eax
test   %ecx,(%rdx)
je     1160 <ocsp_check_delegated+0x30>
pop    %rbx
ret
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
call   1050 <OCSPerr@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EXFLAG_XKUSAGE = global i32 0
@XKU_OCSP_SIGN = global i32 0
@OCSP_F_OCSP_CHECK_DELEGATED = global i32 0
@OCSP_R_MISSING_OCSPSIGNING_USAGE = global i32 0
define i32 @ocsp_check_delegated(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%6 = load i32*, i32** %4
%7 = call i32 @X509_get_extension_flags(i32* %6)
%8 = load i32, i32* @EXFLAG_XKUSAGE
%9 = and i32 %7, %8
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32*, i32** %4
%13 = call i32 @X509_get_extended_key_usage(i32* %12)
%14 = load i32, i32* @XKU_OCSP_SIGN
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 1, i32* %3
br label %22
18: ; preds = %11, %2
%19 = load i32, i32* @OCSP_F_OCSP_CHECK_DELEGATED
%20 = load i32, i32* @OCSP_R_MISSING_OCSPSIGNING_USAGE
%21 = call i32 @OCSPerr(i32 %19, i32 %20)
store i32 0, i32* %3
br label %22
22: ; preds = %18, %17
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@EXFLAG_XKUSAGE = global i32 0
@XKU_OCSP_SIGN = global i32 0
@OCSP_F_OCSP_CHECK_DELEGATED = global i32 0
@OCSP_R_MISSING_OCSPSIGNING_USAGE = global i32 0
define i32 @ocsp_check_delegated(i32* %0, i32 %1) {
%3 = tail call i32 @X509_get_extension_flags(i32* %0)
%4 = load i32, i32* @EXFLAG_XKUSAGE
%5 = and i32 %4, %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = tail call i32 @X509_get_extended_key_usage(i32* %0)
%9 = load i32, i32* @XKU_OCSP_SIGN
%10 = and i32 %9, %8
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7, %2
%13 = load i32, i32* @OCSP_F_OCSP_CHECK_DELEGATED
%14 = load i32, i32* @OCSP_R_MISSING_OCSPSIGNING_USAGE
%15 = tail call i32 @OCSPerr(i32 %13, i32 %14)
br label %16
16: ; preds = %7, %12
%17 = phi i32 [ 0, %12 ], [ 1, %7 ]
ret i32 %17
}