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

/* Type definitions */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};
struct TYPE_6__ {
  int type;
  char *data;
  size_t length;
};
typedef TYPE_1__ ASN1_TIME;

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_ASN1_GENERALIZEDTIME_ADJ;
int /*<<< orphan*/ ASN1_R_ILLEGAL_TIME_VALUE;
int /*<<< orphan*/ ASN1_TIME_free(TYPE_1__ *);
TYPE_1__ *ASN1_TIME_new();
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ OPENSSL_gmtime_adj(struct tm *, int, long);
#define V_ASN1_GENERALIZEDTIME 129
#define V_ASN1_UTCTIME 128
int /*<<< orphan*/ free(char *);
char *gentime_string_from_tm(struct tm *);
int /*<<< orphan*/ *gmtime_r(int /*<<< orphan*/ *, struct tm *);
char *rfc5280_string_from_tm(struct tm *);
size_t strlen(char *);
char *utctime_string_from_tm(struct tm *);
ASN1_TIME *ASN1_TIME_adj_internal(ASN1_TIME *s, time_t t, int offset_day,
                                  long offset_sec, int mode) {
  int allocated = 0;
  struct tm tm;
  size_t len;
  char *p;
  if (gmtime_r(&t, &tm) == NULL)
    return (NULL);
  if (offset_day || offset_sec) {
    if (!OPENSSL_gmtime_adj(&tm, offset_day, offset_sec))
      return (NULL);
  }
  switch (mode) {
  case V_ASN1_UTCTIME:
    p = utctime_string_from_tm(&tm);
    break;
  case V_ASN1_GENERALIZEDTIME:
    p = gentime_string_from_tm(&tm);
    break;
  case 0:
    p = rfc5280_string_from_tm(&tm);
    break;
  default:
    return (NULL);
  }
  if (p == NULL) {
    ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, ASN1_R_ILLEGAL_TIME_VALUE);
    return (NULL);
  }
  if (s == NULL) {
    if ((s = ASN1_TIME_new()) == NULL)
      return (NULL);
    allocated = 1;
  }
  len = strlen(p);
  switch (len) {
  case 15:
    s->type = V_ASN1_GENERALIZEDTIME;
    break;
  case 13:
    s->type = V_ASN1_UTCTIME;
    break;
  default:
    if (allocated)
      ASN1_TIME_free(s);
    free(p);
    return (NULL);
  }
  free(s->data);
  s->data = p;
  s->length = len;
  return (s);
}


x86 assembly (clang, -O0):
<ASN1_TIME_adj_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <gmtime_r@plt>
cmp    $0x0,%rax
jne    11e5 <ASN1_TIME_adj_internal+0x45>
movq   $0x0,-0x8(%rbp)
jmp    13af <ASN1_TIME_adj_internal+0x20f>
cmpl   $0x0,-0x18(%rbp)
jne    11fa <ASN1_TIME_adj_internal+0x5a>
cmpq   $0x0,-0x20(%rbp)
je     1225 <ASN1_TIME_adj_internal+0x85>
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    -0x30(%rbp),%rdi
call   1080 <OPENSSL_gmtime_adj@plt>
cmp    $0x0,%eax
jne    1220 <ASN1_TIME_adj_internal+0x80>
movq   $0x0,-0x8(%rbp)
jmp    13af <ASN1_TIME_adj_internal+0x20f>
jmp    1225 <ASN1_TIME_adj_internal+0x85>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
test   %eax,%eax
je     1282 <ASN1_TIME_adj_internal+0xe2>
jmp    1238 <ASN1_TIME_adj_internal+0x98>
mov    -0x44(%rbp),%eax
sub    $0x80,%eax
je     125e <ASN1_TIME_adj_internal+0xbe>
jmp    124b <ASN1_TIME_adj_internal+0xab>
mov    -0x44(%rbp),%eax
sub    $0x81,%eax
je     1270 <ASN1_TIME_adj_internal+0xd0>
jmp    1294 <ASN1_TIME_adj_internal+0xf4>
lea    -0x30(%rbp),%rdi
call   10c0 <utctime_string_from_tm@plt>
mov    %rax,-0x40(%rbp)
jmp    12a1 <ASN1_TIME_adj_internal+0x101>
lea    -0x30(%rbp),%rdi
call   1090 <gentime_string_from_tm@plt>
mov    %rax,-0x40(%rbp)
jmp    12a1 <ASN1_TIME_adj_internal+0x101>
lea    -0x30(%rbp),%rdi
call   1070 <rfc5280_string_from_tm@plt>
mov    %rax,-0x40(%rbp)
jmp    12a1 <ASN1_TIME_adj_internal+0x101>
movq   $0x0,-0x8(%rbp)
jmp    13af <ASN1_TIME_adj_internal+0x20f>
cmpq   $0x0,-0x40(%rbp)
jne    12d0 <ASN1_TIME_adj_internal+0x130>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    0x2d1c(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movq   $0x0,-0x8(%rbp)
jmp    13af <ASN1_TIME_adj_internal+0x20f>
cmpq   $0x0,-0x10(%rbp)
jne    1304 <ASN1_TIME_adj_internal+0x164>
mov    $0x0,%al
call   10a0 <ASN1_TIME_new@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    12fd <ASN1_TIME_adj_internal+0x15d>
movq   $0x0,-0x8(%rbp)
jmp    13af <ASN1_TIME_adj_internal+0x20f>
movl   $0x1,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
sub    $0xd,%rax
je     134a <ASN1_TIME_adj_internal+0x1aa>
jmp    1328 <ASN1_TIME_adj_internal+0x188>
mov    -0x50(%rbp),%rax
sub    $0xf,%rax
jne    1359 <ASN1_TIME_adj_internal+0x1b9>
jmp    133b <ASN1_TIME_adj_internal+0x19b>
mov    -0x10(%rbp),%rax
movl   $0x81,(%rax)
jmp    1382 <ASN1_TIME_adj_internal+0x1e2>
mov    -0x10(%rbp),%rax
movl   $0x80,(%rax)
jmp    1382 <ASN1_TIME_adj_internal+0x1e2>
cmpl   $0x0,-0x28(%rbp)
je     136c <ASN1_TIME_adj_internal+0x1cc>
mov    -0x10(%rbp),%rdi
call   10b0 <ASN1_TIME_free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    13af <ASN1_TIME_adj_internal+0x20f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_TIME_adj_internal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rdi,%r14
mov    %esi,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
call   1060 <gmtime_r@plt>
test   %rax,%rax
je     12a6 <ASN1_TIME_adj_internal+0x106>
test   %ebp,%ebp
jne    11d5 <ASN1_TIME_adj_internal+0x35>
test   %rbx,%rbx
je     11ea <ASN1_TIME_adj_internal+0x4a>
mov    %rsp,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1080 <OPENSSL_gmtime_adj@plt>
test   %eax,%eax
je     12a6 <ASN1_TIME_adj_internal+0x106>
test   %r15d,%r15d
je     120f <ASN1_TIME_adj_internal+0x6f>
cmp    $0x81,%r15d
je     1219 <ASN1_TIME_adj_internal+0x79>
cmp    $0x80,%r15d
jne    12a6 <ASN1_TIME_adj_internal+0x106>
mov    %rsp,%rdi
call   10c0 <utctime_string_from_tm@plt>
jmp    1221 <ASN1_TIME_adj_internal+0x81>
mov    %rsp,%rdi
call   1070 <rfc5280_string_from_tm@plt>
jmp    1221 <ASN1_TIME_adj_internal+0x81>
mov    %rsp,%rdi
call   1090 <gentime_string_from_tm@plt>
mov    %rax,%r15
test   %rax,%rax
je     125e <ASN1_TIME_adj_internal+0xbe>
mov    %r14,%rbx
test   %r14,%r14
jne    1240 <ASN1_TIME_adj_internal+0xa0>
xor    %eax,%eax
call   10a0 <ASN1_TIME_new@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12a6 <ASN1_TIME_adj_internal+0x106>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
cmp    $0xf,%rax
je     1277 <ASN1_TIME_adj_internal+0xd7>
cmp    $0xd,%rbp
jne    1291 <ASN1_TIME_adj_internal+0xf1>
mov    $0x80,%eax
jmp    127c <ASN1_TIME_adj_internal+0xdc>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
jmp    12a6 <ASN1_TIME_adj_internal+0x106>
mov    $0x81,%eax
mov    %eax,(%rbx)
mov    0x8(%rbx),%rdi
call   1030 <free@plt>
mov    %r15,0x8(%rbx)
mov    %rbp,0x10(%rbx)
jmp    12a8 <ASN1_TIME_adj_internal+0x108>
test   %r14,%r14
jne    129e <ASN1_TIME_adj_internal+0xfe>
mov    %rbx,%rdi
call   10b0 <ASN1_TIME_free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32, i8*, i64 }
%struct.tm = type { i32 }
@ASN1_F_ASN1_GENERALIZEDTIME_ADJ = global i32 0
@ASN1_R_ILLEGAL_TIME_VALUE = global i32 0
define %struct.TYPE_6__* @ASN1_TIME_adj_internal(%struct.TYPE_6__* %0, i32 %1, i32 %2, i64 %3, i32 %4) {
%6 = alloca %struct.TYPE_6__*
%7 = alloca %struct.TYPE_6__*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.tm
%14 = alloca i64
%15 = alloca i8*
store %struct.TYPE_6__* %0, %struct.TYPE_6__** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i64 %3, i64* %10
store i32 %4, i32* %11
store i32 0, i32* %12
%16 = call i32* @gmtime_r(i32* %8, %struct.tm* %13)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %5
store %struct.TYPE_6__* null, %struct.TYPE_6__** %6
br label %87
19: ; preds = %5
%20 = load i32, i32* %9
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i64, i64* %10
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %22, %19
%26 = load i32, i32* %9
%27 = load i64, i64* %10
%28 = call i32 @OPENSSL_gmtime_adj(%struct.tm* %13, i32 %26, i64 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25
store %struct.TYPE_6__* null, %struct.TYPE_6__** %6
br label %87
31: ; preds = %25
br label %32
32: ; preds = %31, %22
%33 = load i32, i32* %11
switch i32 %33, label %40 [
i32 128, label %34
i32 129, label %36
i32 0, label %38
]
34: ; preds = %32
%35 = call i8* @utctime_string_from_tm(%struct.tm* %13)
store i8* %35, i8** %15
br label %41
36: ; preds = %32
%37 = call i8* @gentime_string_from_tm(%struct.tm* %13)
store i8* %37, i8** %15
br label %41
38: ; preds = %32
%39 = call i8* @rfc5280_string_from_tm(%struct.tm* %13)
store i8* %39, i8** %15
br label %41
40: ; preds = %32
store %struct.TYPE_6__* null, %struct.TYPE_6__** %6
br label %87
41: ; preds = %38, %36, %34
%42 = load i8*, i8** %15
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32, i32* @ASN1_F_ASN1_GENERALIZEDTIME_ADJ
%46 = load i32, i32* @ASN1_R_ILLEGAL_TIME_VALUE
%47 = call i32 @ASN1err(i32 %45, i32 %46)
store %struct.TYPE_6__* null, %struct.TYPE_6__** %6
br label %87
48: ; preds = %41
%49 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%50 = icmp eq %struct.TYPE_6__* %49, null
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = call %struct.TYPE_6__* (...) @ASN1_TIME_new()
store %struct.TYPE_6__* %52, %struct.TYPE_6__** %7
%53 = icmp eq %struct.TYPE_6__* %52, null
br i1 %53, label %54, label %55
54: ; preds = %51
store %struct.TYPE_6__* null, %struct.TYPE_6__** %6
br label %87
55: ; preds = %51
store i32 1, i32* %12
br label %56
56: ; preds = %55, %48
%57 = load i8*, i8** %15
%58 = call i64 @strlen(i8* %57)
store i64 %58, i64* %14
%59 = load i64, i64* %14
switch i64 %59, label %66 [
i64 15, label %60
i64 13, label %63
]
60: ; preds = %56
%61 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%62 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %61, i32 0, i32 0
store i32 129, i32* %62
br label %75
63: ; preds = %56
%64 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%65 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %64, i32 0, i32 0
store i32 128, i32* %65
br label %75
66: ; preds = %56
%67 = load i32, i32* %12
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%71 = call i32 @ASN1_TIME_free(%struct.TYPE_6__* %70)
br label %72
72: ; preds = %69, %66
%73 = load i8*, i8** %15
%74 = call i32 @free(i8* %73)
store %struct.TYPE_6__* null, %struct.TYPE_6__** %6
br label %87
75: ; preds = %63, %60
%76 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%77 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %76, i32 0, i32 1
%78 = load i8*, i8** %77
%79 = call i32 @free(i8* %78)
%80 = load i8*, i8** %15
%81 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%82 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %81, i32 0, i32 1
store i8* %80, i8** %82
%83 = load i64, i64* %14
%84 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%85 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %84, i32 0, i32 2
store i64 %83, i64* %85
%86 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
store %struct.TYPE_6__* %86, %struct.TYPE_6__** %6
br label %87
87: ; preds = %75, %72, %54, %44, %40, %30, %18
%88 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
ret %struct.TYPE_6__* %88
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32, i8*, i64 }
%struct.tm = type { i32 }
@ASN1_F_ASN1_GENERALIZEDTIME_ADJ = global i32 0
@ASN1_R_ILLEGAL_TIME_VALUE = global i32 0
define %struct.TYPE_6__* @ASN1_TIME_adj_internal(%struct.TYPE_6__* %0, i32 %1, i32 %2, i64 %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.tm
store i32 %1, i32* %6
%8 = bitcast %struct.tm* %7 to i8*
%9 = call i32* @gmtime_r(i32* %6, %struct.tm* %7)
%10 = icmp eq i32* %9, null
br i1 %10, label %53, label %11
11: ; preds = %5
%12 = icmp ne i32 %2, 0
%13 = icmp ne i64 %3, 0
%14 = or i1 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @OPENSSL_gmtime_adj(%struct.tm* %7, i32 %2, i64 %3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %53, label %18
18: ; preds = %15, %11
switch i32 %4, label %53 [
i32 128, label %19
i32 129, label %21
i32 0, label %23
]
19: ; preds = %18
%20 = call i8* @utctime_string_from_tm(%struct.tm* %7)
br label %25
21: ; preds = %18
%22 = call i8* @gentime_string_from_tm(%struct.tm* %7)
br label %25
23: ; preds = %18
%24 = call i8* @rfc5280_string_from_tm(%struct.tm* %7)
br label %25
25: ; preds = %23, %21, %19
%26 = phi i8* [ %24, %23 ], [ %22, %21 ], [ %20, %19 ]
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* @ASN1_F_ASN1_GENERALIZEDTIME_ADJ
%30 = load i32, i32* @ASN1_R_ILLEGAL_TIME_VALUE
%31 = call i32 @ASN1err(i32 %29, i32 %30)
br label %53
32: ; preds = %25
%33 = icmp eq %struct.TYPE_6__* %0, null
br i1 %33, label %34, label %37
34: ; preds = %32
%35 = call %struct.TYPE_6__* (...) @ASN1_TIME_new()
%36 = icmp eq %struct.TYPE_6__* %35, null
br i1 %36, label %53, label %37
37: ; preds = %34, %32
%38 = phi %struct.TYPE_6__* [ %0, %32 ], [ %35, %34 ]
%39 = call i64 @strlen(i8* %26)
switch i64 %39, label %41 [
i64 15, label %46
i64 13, label %40
]
40: ; preds = %37
br label %46
41: ; preds = %37
br i1 %33, label %42, label %44
42: ; preds = %41
%43 = call i32 @ASN1_TIME_free(%struct.TYPE_6__* %38)
br label %44
44: ; preds = %42, %41
%45 = call i32 @free(i8* %26)
br label %53
46: ; preds = %37, %40
%47 = phi i32 [ 128, %40 ], [ 129, %37 ]
%48 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %38, i64 0, i32 0
store i32 %47, i32* %48
%49 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %38, i64 0, i32 1
%50 = load i8*, i8** %49
%51 = call i32 @free(i8* %50)
store i8* %26, i8** %49
%52 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %38, i64 0, i32 2
store i64 %39, i64* %52
br label %53
53: ; preds = %34, %18, %15, %5, %46, %44, %28
%54 = phi %struct.TYPE_6__* [ null, %28 ], [ null, %44 ], [ %38, %46 ], [ null, %5 ], [ null, %15 ], [ null, %18 ], [ null, %34 ]
ret %struct.TYPE_6__* %54
}