#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*/ type;
  int /*<<< orphan*/ length;
  int /*<<< orphan*/ data;
};
typedef TYPE_1__ ASN1_TIME;

/* Variables and functions */
int ASN1_time_parse(int /*<<< orphan*/, int /*<<< orphan*/, struct tm *,
                    int /*<<< orphan*/);
int /*<<< orphan*/ ASN1_time_tm_clamp_notafter(struct tm *);
int ASN1_time_tm_cmp(struct tm *, struct tm *);
int V_ASN1_GENERALIZEDTIME;
int V_ASN1_UTCTIME;
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_internal(const ASN1_TIME *ctm, time_t *cmp_time,
                           int clamp_notafter) {
  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));
  type = ASN1_time_parse(ctm->data, ctm->length, &tm1, ctm->type);
  if (type == -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 (clamp_notafter) {
    if (!ASN1_time_tm_clamp_notafter(&tm1))
      goto out;
  }
  if ((time1 = timegm(&tm1)) == -1)
    goto out;
  if (gmtime_r(&time2, &tm2) == NULL)
    goto out;
  ret = ASN1_time_tm_cmp(&tm1, &tm2);
  if (ret == 0)
    ret = -1;
out:
  return (ret);
}


x86 assembly (clang, -O0):
<X509_cmp_time_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a6 <X509_cmp_time_internal+0x36>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x1c(%rbp)
jmp    11af <X509_cmp_time_internal+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%rdx
call   1060 <ASN1_time_parse@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    11ee <X509_cmp_time_internal+0x7e>
jmp    12b8 <X509_cmp_time_internal+0x148>
cmpl   $0x96,-0x20(%rbp)
jge    1212 <X509_cmp_time_internal+0xa2>
mov    -0x30(%rbp),%eax
mov    0x2dd3(%rip),%rcx
cmp    (%rcx),%eax
je     1212 <X509_cmp_time_internal+0xa2>
jmp    12b8 <X509_cmp_time_internal+0x148>
cmpl   $0x96,-0x20(%rbp)
jl     1236 <X509_cmp_time_internal+0xc6>
mov    -0x30(%rbp),%eax
mov    0x2dbf(%rip),%rcx
cmp    (%rcx),%eax
je     1236 <X509_cmp_time_internal+0xc6>
jmp    12b8 <X509_cmp_time_internal+0x148>
cmpl   $0x0,-0x14(%rbp)
je     125c <X509_cmp_time_internal+0xec>
lea    -0x20(%rbp),%rdi
call   1090 <ASN1_time_tm_clamp_notafter@plt>
cmp    $0x0,%eax
jne    1257 <X509_cmp_time_internal+0xe7>
jmp    12b8 <X509_cmp_time_internal+0x148>
jmp    125c <X509_cmp_time_internal+0xec>
lea    -0x20(%rbp),%rdi
call   1080 <timegm@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1276 <X509_cmp_time_internal+0x106>
jmp    12b8 <X509_cmp_time_internal+0x148>
lea    -0x1c(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <gmtime_r@plt>
cmp    $0x0,%rax
jne    1292 <X509_cmp_time_internal+0x122>
jmp    12b8 <X509_cmp_time_internal+0x148>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <ASN1_time_tm_cmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    12b3 <X509_cmp_time_internal+0x143>
movl   $0xffffffff,-0x2c(%rbp)
jmp    12b8 <X509_cmp_time_internal+0x148>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<X509_cmp_time_internal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rdi,%rbp
test   %rsi,%rsi
je     1189 <X509_cmp_time_internal+0x19>
mov    (%rsi),%eax
jmp    1190 <X509_cmp_time_internal+0x20>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0x14(%rsp)
lea    0x8(%rsp),%rbx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x8(%rbp),%edi
mov    0x0(%rbp),%ecx
mov    0x4(%rbp),%esi
mov    %rbx,%rdx
call   1060 <ASN1_time_parse@plt>
cmp    $0xffffffff,%eax
je     1239 <X509_cmp_time_internal+0xc9>
mov    0x8(%rsp),%ecx
cmp    $0x95,%ecx
jg     11d8 <X509_cmp_time_internal+0x68>
mov    0x2e04(%rip),%rdx
cmp    (%rdx),%eax
jne    1239 <X509_cmp_time_internal+0xc9>
cmp    $0x96,%ecx
jl     11eb <X509_cmp_time_internal+0x7b>
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%eax
jne    1239 <X509_cmp_time_internal+0xc9>
test   %r14d,%r14d
je     11fe <X509_cmp_time_internal+0x8e>
lea    0x8(%rsp),%rdi
call   1090 <ASN1_time_tm_clamp_notafter@plt>
test   %eax,%eax
je     1239 <X509_cmp_time_internal+0xc9>
lea    0x8(%rsp),%rdi
call   1080 <timegm@plt>
cmp    $0xffffffff,%eax
je     1239 <X509_cmp_time_internal+0xc9>
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <gmtime_r@plt>
test   %rax,%rax
je     1239 <X509_cmp_time_internal+0xc9>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <ASN1_time_tm_cmp@plt>
cmp    $0x1,%eax
sbb    %r15d,%r15d
or     %eax,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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