#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) {
  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    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <X509_get_extension_flags@plt>
mov    0x2e7c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     117e <ocsp_check_delegated+0x4e>
mov    -0x10(%rbp),%rdi
call   1040 <X509_get_extended_key_usage@plt>
mov    0x2e79(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     117e <ocsp_check_delegated+0x4e>
movl   $0x1,-0x4(%rbp)
jmp    119c <ocsp_check_delegated+0x6c>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
call   1050 <OCSPerr@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%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) {
%2 = alloca i32
%3 = alloca i32*
store i32* %0, i32** %3
%4 = load i32*, i32** %3
%5 = call i32 @X509_get_extension_flags(i32* %4)
%6 = load i32, i32* @EXFLAG_XKUSAGE
%7 = and i32 %5, %6
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = call i32 @X509_get_extended_key_usage(i32* %10)
%12 = load i32, i32* @XKU_OCSP_SIGN
%13 = and i32 %11, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 1, i32* %2
br label %20
16: ; preds = %9, %1
%17 = load i32, i32* @OCSP_F_OCSP_CHECK_DELEGATED
%18 = load i32, i32* @OCSP_R_MISSING_OCSPSIGNING_USAGE
%19 = call i32 @OCSPerr(i32 %17, i32 %18)
store i32 0, i32* %2
br label %20
20: ; preds = %16, %15
%21 = load i32, i32* %2
ret i32 %21
}

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) {
%2 = tail call i32 @X509_get_extension_flags(i32* %0)
%3 = load i32, i32* @EXFLAG_XKUSAGE
%4 = and i32 %3, %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = tail call i32 @X509_get_extended_key_usage(i32* %0)
%8 = load i32, i32* @XKU_OCSP_SIGN
%9 = and i32 %8, %7
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %6, %1
%12 = load i32, i32* @OCSP_F_OCSP_CHECK_DELEGATED
%13 = load i32, i32* @OCSP_R_MISSING_OCSPSIGNING_USAGE
%14 = tail call i32 @OCSPerr(i32 %12, i32 %13)
br label %15
15: ; preds = %6, %11
%16 = phi i32 [ 0, %11 ], [ 1, %6 ]
ret i32 %16
}