#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 scalar_t__ time_t;
typedef int /*<<< orphan*/ ASN1_GENERALIZEDTIME;

/* Variables and functions */
int /*<<< orphan*/ ASN1_GENERALIZEDTIME_check(int /*<<< orphan*/ *);
scalar_t__ ASN1_STRING_cmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ OCSP_F_OCSP_CHECK_VALIDITY;
int /*<<< orphan*/ OCSP_R_ERROR_IN_NEXTUPDATE_FIELD;
int /*<<< orphan*/ OCSP_R_ERROR_IN_THISUPDATE_FIELD;
int /*<<< orphan*/ OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE;
int /*<<< orphan*/ OCSP_R_STATUS_EXPIRED;
int /*<<< orphan*/ OCSP_R_STATUS_NOT_YET_VALID;
int /*<<< orphan*/ OCSP_R_STATUS_TOO_OLD;
int /*<<< orphan*/ OCSPerr(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ X509_cmp_time(int /*<<< orphan*/ *, scalar_t__ *);
int /*<<< orphan*/ time(scalar_t__ *);
int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
                        ASN1_GENERALIZEDTIME *nextupd, long nsec, long maxsec) {
  int ret = 1;
  time_t t_now, t_tmp;
  time(&t_now);
  if (!ASN1_GENERALIZEDTIME_check(thisupd)) {
    OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_THISUPDATE_FIELD);
    ret = 0;
  } else {
    t_tmp = t_now + nsec;
    if (X509_cmp_time(thisupd, &t_tmp) > 0) {
      OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_NOT_YET_VALID);
      ret = 0;
    }
    if (maxsec >= 0) {
      t_tmp = t_now - maxsec;
      if (X509_cmp_time(thisupd, &t_tmp) < 0) {
        OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_TOO_OLD);
        ret = 0;
      }
    }
  }
  if (!nextupd)
    return ret;
  if (!ASN1_GENERALIZEDTIME_check(nextupd)) {
    OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_NEXTUPDATE_FIELD);
    ret = 0;
  } else {
    t_tmp = t_now - nsec;
    if (X509_cmp_time(nextupd, &t_tmp) < 0) {
      OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_EXPIRED);
      ret = 0;
    }
  }
  if (ASN1_STRING_cmp(nextupd, thisupd) < 0) {
    OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE);
    ret = 0;
  }
  return ret;
}


x86 assembly (clang, -O0):
<OCSP_check_validity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
lea    -0x38(%rbp),%rdi
call   1060 <time@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ASN1_GENERALIZEDTIME_check@plt>
cmp    $0x0,%eax
jne    11ad <OCSP_check_validity+0x5d>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
call   1070 <OCSPerr@plt>
movl   $0x0,-0x2c(%rbp)
jmp    1244 <OCSP_check_validity+0xf4>
mov    -0x38(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <X509_cmp_time@plt>
cmp    $0x0,%rax
jle    11ee <OCSP_check_validity+0x9e>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
call   1070 <OCSPerr@plt>
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jl     123f <OCSP_check_validity+0xef>
mov    -0x38(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <X509_cmp_time@plt>
cmp    $0x0,%rax
jge    123a <OCSP_check_validity+0xea>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
call   1070 <OCSPerr@plt>
movl   $0x0,-0x2c(%rbp)
jmp    123f <OCSP_check_validity+0xef>
jmp    1244 <OCSP_check_validity+0xf4>
cmpq   $0x0,-0x18(%rbp)
jne    125a <OCSP_check_validity+0x10a>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1310 <OCSP_check_validity+0x1c0>
mov    -0x18(%rbp),%rdi
call   1050 <ASN1_GENERALIZEDTIME_check@plt>
cmp    $0x0,%eax
jne    128f <OCSP_check_validity+0x13f>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
call   1070 <OCSPerr@plt>
movl   $0x0,-0x2c(%rbp)
jmp    12d5 <OCSP_check_validity+0x185>
mov    -0x38(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <X509_cmp_time@plt>
cmp    $0x0,%rax
jge    12d0 <OCSP_check_validity+0x180>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
mov    0x2cf6(%rip),%rax
mov    (%rax),%esi
call   1070 <OCSPerr@plt>
movl   $0x0,-0x2c(%rbp)
jmp    12d5 <OCSP_check_validity+0x185>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <ASN1_STRING_cmp@plt>
cmp    $0x0,%rax
jge    130a <OCSP_check_validity+0x1ba>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
mov    0x2ccc(%rip),%rax
mov    (%rax),%esi
call   1070 <OCSPerr@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OCSP_check_validity>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
lea    0x8(%rsp),%rdi
call   1060 <time@plt>
mov    %r12,%rdi
call   1050 <ASN1_GENERALIZEDTIME_check@plt>
test   %eax,%eax
je     11ba <OCSP_check_validity+0x6a>
mov    0x8(%rsp),%rax
add    %r15,%rax
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    %r12,%rdi
call   1030 <X509_cmp_time@plt>
test   %rax,%rax
jle    11c3 <OCSP_check_validity+0x73>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1070 <OCSPerr@plt>
xor    %ebp,%ebp
test   %rbx,%rbx
jns    11cd <OCSP_check_validity+0x7d>
jmp    1202 <OCSP_check_validity+0xb2>
mov    0x2dff(%rip),%rax
jmp    11f0 <OCSP_check_validity+0xa0>
mov    $0x1,%ebp
test   %rbx,%rbx
js     1202 <OCSP_check_validity+0xb2>
mov    0x8(%rsp),%rax
sub    %rbx,%rax
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    %r12,%rdi
call   1030 <X509_cmp_time@plt>
test   %rax,%rax
jns    1202 <OCSP_check_validity+0xb2>
mov    0x2dc0(%rip),%rax
mov    0x2de1(%rip),%rcx
mov    (%rcx),%edi
mov    (%rax),%esi
call   1070 <OCSPerr@plt>
xor    %ebp,%ebp
test   %r14,%r14
je     127a <OCSP_check_validity+0x12a>
mov    %r14,%rdi
call   1050 <ASN1_GENERALIZEDTIME_check@plt>
test   %eax,%eax
je     1238 <OCSP_check_validity+0xe8>
mov    0x8(%rsp),%rax
sub    %r15,%rax
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <X509_cmp_time@plt>
test   %rax,%rax
jns    1251 <OCSP_check_validity+0x101>
mov    0x2d82(%rip),%rax
jmp    123f <OCSP_check_validity+0xef>
mov    0x2da1(%rip),%rax
mov    0x2d92(%rip),%rcx
mov    (%rcx),%edi
mov    (%rax),%esi
call   1070 <OCSPerr@plt>
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <ASN1_STRING_cmp@plt>
test   %rax,%rax
jns    127a <OCSP_check_validity+0x12a>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
call   1070 <OCSPerr@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@OCSP_F_OCSP_CHECK_VALIDITY = global i32 0
@OCSP_R_ERROR_IN_THISUPDATE_FIELD = global i32 0
@OCSP_R_STATUS_NOT_YET_VALID = global i32 0
@OCSP_R_STATUS_TOO_OLD = global i32 0
@OCSP_R_ERROR_IN_NEXTUPDATE_FIELD = global i32 0
@OCSP_R_STATUS_EXPIRED = global i32 0
@OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE = global i32 0
define i32 @OCSP_check_validity(i32* %0, i32* %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
store i32* %0, i32** %6
store i32* %1, i32** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i32 1, i32* %10
%13 = call i32 @time(i64* %11)
%14 = load i32*, i32** %6
%15 = call i32 @ASN1_GENERALIZEDTIME_check(i32* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %4
%18 = load i32, i32* @OCSP_F_OCSP_CHECK_VALIDITY
%19 = load i32, i32* @OCSP_R_ERROR_IN_THISUPDATE_FIELD
%20 = call i32 @OCSPerr(i32 %18, i32 %19)
store i32 0, i32* %10
br label %48
21: ; preds = %4
%22 = load i64, i64* %11
%23 = load i64, i64* %8
%24 = add nsw i64 %22, %23
store i64 %24, i64* %12
%25 = load i32*, i32** %6
%26 = call i64 @X509_cmp_time(i32* %25, i64* %12)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %21
%29 = load i32, i32* @OCSP_F_OCSP_CHECK_VALIDITY
%30 = load i32, i32* @OCSP_R_STATUS_NOT_YET_VALID
%31 = call i32 @OCSPerr(i32 %29, i32 %30)
store i32 0, i32* %10
br label %32
32: ; preds = %28, %21
%33 = load i64, i64* %9
%34 = icmp sge i64 %33, 0
br i1 %34, label %35, label %47
35: ; preds = %32
%36 = load i64, i64* %11
%37 = load i64, i64* %9
%38 = sub nsw i64 %36, %37
store i64 %38, i64* %12
%39 = load i32*, i32** %6
%40 = call i64 @X509_cmp_time(i32* %39, i64* %12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load i32, i32* @OCSP_F_OCSP_CHECK_VALIDITY
%44 = load i32, i32* @OCSP_R_STATUS_TOO_OLD
%45 = call i32 @OCSPerr(i32 %43, i32 %44)
store i32 0, i32* %10
br label %46
46: ; preds = %42, %35
br label %47
47: ; preds = %46, %32
br label %48
48: ; preds = %47, %17
%49 = load i32*, i32** %7
%50 = icmp ne i32* %49, null
br i1 %50, label %53, label %51
51: ; preds = %48
%52 = load i32, i32* %10
store i32 %52, i32* %5
br label %84
53: ; preds = %48
%54 = load i32*, i32** %7
%55 = call i32 @ASN1_GENERALIZEDTIME_check(i32* %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %61, label %57
57: ; preds = %53
%58 = load i32, i32* @OCSP_F_OCSP_CHECK_VALIDITY
%59 = load i32, i32* @OCSP_R_ERROR_IN_NEXTUPDATE_FIELD
%60 = call i32 @OCSPerr(i32 %58, i32 %59)
store i32 0, i32* %10
br label %73
61: ; preds = %53
%62 = load i64, i64* %11
%63 = load i64, i64* %8
%64 = sub nsw i64 %62, %63
store i64 %64, i64* %12
%65 = load i32*, i32** %7
%66 = call i64 @X509_cmp_time(i32* %65, i64* %12)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %61
%69 = load i32, i32* @OCSP_F_OCSP_CHECK_VALIDITY
%70 = load i32, i32* @OCSP_R_STATUS_EXPIRED
%71 = call i32 @OCSPerr(i32 %69, i32 %70)
store i32 0, i32* %10
br label %72
72: ; preds = %68, %61
br label %73
73: ; preds = %72, %57
%74 = load i32*, i32** %7
%75 = load i32*, i32** %6
%76 = call i64 @ASN1_STRING_cmp(i32* %74, i32* %75)
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %73
%79 = load i32, i32* @OCSP_F_OCSP_CHECK_VALIDITY
%80 = load i32, i32* @OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE
%81 = call i32 @OCSPerr(i32 %79, i32 %80)
store i32 0, i32* %10
br label %82
82: ; preds = %78, %73
%83 = load i32, i32* %10
store i32 %83, i32* %5
br label %84
84: ; preds = %82, %51
%85 = load i32, i32* %5
ret i32 %85
}

LLVM IR (-O2):
@OCSP_F_OCSP_CHECK_VALIDITY = global i32 0
@OCSP_R_ERROR_IN_THISUPDATE_FIELD = global i32 0
@OCSP_R_STATUS_NOT_YET_VALID = global i32 0
@OCSP_R_STATUS_TOO_OLD = global i32 0
@OCSP_R_ERROR_IN_NEXTUPDATE_FIELD = global i32 0
@OCSP_R_STATUS_EXPIRED = global i32 0
@OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE = global i32 0
define i32 @OCSP_check_validity(i32* %0, i32* %1, i64 %2, i64 %3) {
%5 = alloca i64
%6 = alloca i64
%7 = bitcast i64* %5 to i8*
%8 = bitcast i64* %6 to i8*
%9 = call i32 @time(i64* %5)
%10 = call i32 @ASN1_GENERALIZEDTIME_check(i32* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %29, label %12
12: ; preds = %4
%13 = load i64, i64* %5
%14 = add nsw i64 %13, %2
store i64 %14, i64* %6
%15 = call i64 @X509_cmp_time(i32* %0, i64* %6)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @OCSP_F_OCSP_CHECK_VALIDITY
%19 = load i32, i32* @OCSP_R_STATUS_NOT_YET_VALID
%20 = call i32 @OCSPerr(i32 %18, i32 %19)
br label %21
21: ; preds = %17, %12
%22 = phi i32 [ 0, %17 ], [ 1, %12 ]
%23 = icmp sgt i64 %3, -1
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load i64, i64* %5
%26 = sub nsw i64 %25, %3
store i64 %26, i64* %6
%27 = call i64 @X509_cmp_time(i32* %0, i64* %6)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24, %4
%30 = phi i32* [ @OCSP_R_ERROR_IN_THISUPDATE_FIELD, %4 ], [ @OCSP_R_STATUS_TOO_OLD, %24 ]
%31 = load i32, i32* @OCSP_F_OCSP_CHECK_VALIDITY
%32 = load i32, i32* %30
%33 = call i32 @OCSPerr(i32 %31, i32 %32)
br label %34
34: ; preds = %29, %21, %24
%35 = phi i32 [ %22, %24 ], [ %22, %21 ], [ 0, %29 ]
%36 = icmp eq i32* %1, null
br i1 %36, label %58, label %37
37: ; preds = %34
%38 = call i32 @ASN1_GENERALIZEDTIME_check(i32* %1)
%39 = icmp eq i32 %38, 0
br i1 %39, label %45, label %40
40: ; preds = %37
%41 = load i64, i64* %5
%42 = sub nsw i64 %41, %2
store i64 %42, i64* %6
%43 = call i64 @X509_cmp_time(i32* %1, i64* %6)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %40, %37
%46 = phi i32* [ @OCSP_R_ERROR_IN_NEXTUPDATE_FIELD, %37 ], [ @OCSP_R_STATUS_EXPIRED, %40 ]
%47 = load i32, i32* @OCSP_F_OCSP_CHECK_VALIDITY
%48 = load i32, i32* %46
%49 = call i32 @OCSPerr(i32 %47, i32 %48)
br label %50
50: ; preds = %45, %40
%51 = phi i32 [ %35, %40 ], [ 0, %45 ]
%52 = call i64 @ASN1_STRING_cmp(i32* %1, i32* %0)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i32, i32* @OCSP_F_OCSP_CHECK_VALIDITY
%56 = load i32, i32* @OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE
%57 = call i32 @OCSPerr(i32 %55, i32 %56)
br label %58
58: ; preds = %50, %54, %34
%59 = phi i32 [ %35, %34 ], [ 0, %54 ], [ %51, %50 ]
ret i32 %59
}