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

/* Type definitions */
typedef int /*<<< orphan*/ tm1;
typedef int time_t;
struct tm {
  int tm_year;
};
struct TYPE_3__ {
  int /*<<< orphan*/ length;
  int /*<<< orphan*/ data;
};
typedef TYPE_1__ ASN1_TIME;

/* Variables and functions */
int V_ASN1_GENERALIZEDTIME;
int V_ASN1_UTCTIME;
int asn1_time_parse(int /*<<< orphan*/, int /*<<< orphan*/, struct tm *,
                    int /*<<< orphan*/);
int asn1_tm_cmp(struct tm *, struct tm *);
int /*<<< orphan*/ *gmtime_r(int *, struct tm *);
int /*<<< orphan*/ memset(struct tm *, int /*<<< orphan*/, int);
int time(int /*<<< orphan*/ *);
int timegm(struct tm *);
int X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time) {
  time_t time1, time2;
  struct tm tm1, tm2;
  int ret = 0;
  int type;
  if (cmp_time == NULL)
    time2 = time(NULL);
  else
    time2 = *cmp_time;
  memset(&tm1, 0, sizeof(tm1));
  if ((type = asn1_time_parse(ctm->data, ctm->length, &tm1, 0)) == -1)
    goto out;
  if (tm1.tm_year < 150 && type != V_ASN1_UTCTIME)
    goto out;
  if (tm1.tm_year >= 150 && type != V_ASN1_GENERALIZEDTIME)
    goto out;
  if ((time1 = timegm(&tm1)) == -1)
    goto out;
  if (gmtime_r(&time2, &tm2) == NULL)
    goto out;
  ret = asn1_tm_cmp(&tm1, &tm2);
  if (ret == 0)
    ret = -1;
out:
  return (ret);
}


x86 assembly (clang, -O0):
<X509_cmp_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1193 <X509_cmp_time+0x33>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x18(%rbp)
jmp    119c <X509_cmp_time+0x3c>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
xor    %ecx,%ecx
call   1080 <asn1_time_parse@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    11d5 <X509_cmp_time+0x75>
jmp    1279 <X509_cmp_time+0x119>
cmpl   $0x96,-0x20(%rbp)
jge    11f9 <X509_cmp_time+0x99>
mov    -0x30(%rbp),%eax
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%eax
je     11f9 <X509_cmp_time+0x99>
jmp    1279 <X509_cmp_time+0x119>
cmpl   $0x96,-0x20(%rbp)
jl     121d <X509_cmp_time+0xbd>
mov    -0x30(%rbp),%eax
mov    0x2dd8(%rip),%rcx
cmp    (%rcx),%eax
je     121d <X509_cmp_time+0xbd>
jmp    1279 <X509_cmp_time+0x119>
lea    -0x20(%rbp),%rdi
call   1060 <timegm@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1237 <X509_cmp_time+0xd7>
jmp    1279 <X509_cmp_time+0x119>
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <gmtime_r@plt>
cmp    $0x0,%rax
jne    1253 <X509_cmp_time+0xf3>
jmp    1279 <X509_cmp_time+0x119>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <asn1_tm_cmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1274 <X509_cmp_time+0x114>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1279 <X509_cmp_time+0x119>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<X509_cmp_time>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
test   %rsi,%rsi
je     1174 <X509_cmp_time+0x14>
mov    (%rsi),%eax
jmp    117b <X509_cmp_time+0x1b>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
mov    %rsp,%rbp
xor    %r14d,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    (%rbx),%esi
mov    0x4(%rbx),%edi
mov    %rbp,%rdx
xor    %ecx,%ecx
call   1080 <asn1_time_parse@plt>
cmp    $0xffffffff,%eax
je     1208 <X509_cmp_time+0xa8>
mov    (%rsp),%ecx
cmp    $0x95,%ecx
jg     11be <X509_cmp_time+0x5e>
mov    0x2e1e(%rip),%rdx
cmp    (%rdx),%eax
jne    1208 <X509_cmp_time+0xa8>
cmp    $0x96,%ecx
jl     11d1 <X509_cmp_time+0x71>
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%eax
jne    1208 <X509_cmp_time+0xa8>
mov    %rsp,%rdi
call   1060 <timegm@plt>
cmp    $0xffffffff,%eax
je     1208 <X509_cmp_time+0xa8>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <gmtime_r@plt>
test   %rax,%rax
je     1208 <X509_cmp_time+0xa8>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1070 <asn1_tm_cmp@plt>
cmp    $0x1,%eax
sbb    %r14d,%r14d
or     %eax,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
%struct.tm = type { i32 }
@V_ASN1_UTCTIME = global i32 0
@V_ASN1_GENERALIZEDTIME = global i32 0
define i32 @X509_cmp_time(%struct.TYPE_3__* %0, i32* %1) {
%3 = alloca %struct.TYPE_3__*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tm
%8 = alloca %struct.tm
%9 = alloca i32
%10 = alloca i32
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %3
store i32* %1, i32** %4
store i32 0, i32* %9
%11 = load i32*, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @time(i32* null)
store i32 %14, i32* %6
br label %18
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = load i32, i32* %16
store i32 %17, i32* %6
br label %18
18: ; preds = %15, %13
%19 = call i32 @memset(%struct.tm* %7, i32 0, i32 4)
%20 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @asn1_time_parse(i32 %22, i32 %25, %struct.tm* %7, i32 0)
store i32 %26, i32* %10
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %18
br label %61
29: ; preds = %18
%30 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%31 = load i32, i32* %30
%32 = icmp slt i32 %31, 150
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = load i32, i32* %10
%35 = load i32, i32* @V_ASN1_UTCTIME
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %33
br label %61
38: ; preds = %33, %29
%39 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%40 = load i32, i32* %39
%41 = icmp sge i32 %40, 150
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = load i32, i32* %10
%44 = load i32, i32* @V_ASN1_GENERALIZEDTIME
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %42
br label %61
47: ; preds = %42, %38
%48 = call i32 @timegm(%struct.tm* %7)
store i32 %48, i32* %5
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %51
50: ; preds = %47
br label %61
51: ; preds = %47
%52 = call i32* @gmtime_r(i32* %6, %struct.tm* %8)
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %55
54: ; preds = %51
br label %61
55: ; preds = %51
%56 = call i32 @asn1_tm_cmp(%struct.tm* %7, %struct.tm* %8)
store i32 %56, i32* %9
%57 = load i32, i32* %9
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %55
store i32 -1, i32* %9
br label %60
60: ; preds = %59, %55
br label %61
61: ; preds = %60, %54, %50, %46, %37, %28
%62 = load i32, i32* %9
ret i32 %62
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
%struct.tm = type { i32 }
@V_ASN1_UTCTIME = global i32 0
@V_ASN1_GENERALIZEDTIME = global i32 0
define i32 @X509_cmp_time(%struct.TYPE_3__* nocapture %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.tm
%5 = alloca %struct.tm
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.tm* %4 to i8*
%8 = bitcast %struct.tm* %5 to i8*
%9 = icmp eq i32* %1, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @time(i32* null)
br label %14
12: ; preds = %2
%13 = load i32, i32* %1
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ %13, %12 ], [ %11, %10 ]
store i32 %15, i32* %3
%16 = call i32 @memset(%struct.tm* %4, i32 0, i32 4)
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @asn1_time_parse(i32 %18, i32 %20, %struct.tm* %4, i32 0)
%22 = icmp eq i32 %21, -1
br i1 %22, label %45, label %23
23: ; preds = %14
%24 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%25 = load i32, i32* %24
%26 = icmp sgt i32 %25, 149
%27 = load i32, i32* @V_ASN1_UTCTIME
%28 = icmp eq i32 %21, %27
%29 = select i1 %26, i1 true, i1 %28
br i1 %29, label %30, label %45
30: ; preds = %23
%31 = icmp slt i32 %25, 150
%32 = load i32, i32* @V_ASN1_GENERALIZEDTIME
%33 = icmp eq i32 %21, %32
%34 = select i1 %31, i1 true, i1 %33
br i1 %34, label %35, label %45
35: ; preds = %30
%36 = call i32 @timegm(%struct.tm* %4)
%37 = icmp eq i32 %36, -1
br i1 %37, label %45, label %38
38: ; preds = %35
%39 = call i32* @gmtime_r(i32* %3, %struct.tm* %5)
%40 = icmp eq i32* %39, null
br i1 %40, label %45, label %41
41: ; preds = %38
%42 = call i32 @asn1_tm_cmp(%struct.tm* %4, %struct.tm* %5)
%43 = icmp eq i32 %42, 0
%44 = select i1 %43, i32 -1, i32 %42
br label %45
45: ; preds = %30, %23, %38, %35, %14, %41
%46 = phi i32 [ 0, %14 ], [ 0, %35 ], [ 0, %38 ], [ %44, %41 ], [ 0, %23 ], [ 0, %30 ]
ret i32 %46
}