#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_R_ILLEGAL_TIME_VALUE;
int /*<<< orphan*/ ASN1_TIME_free(TYPE_1__ *);
TYPE_1__ *ASN1_TIME_new();
int /*<<< orphan*/ ASN1error(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) {
    ASN1error(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   1050 <gmtime_r@plt>
cmp    $0x0,%rax
jne    11e5 <ASN1_TIME_adj_internal+0x45>
movq   $0x0,-0x8(%rbp)
jmp    13a6 <ASN1_TIME_adj_internal+0x206>
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   1070 <OPENSSL_gmtime_adj@plt>
cmp    $0x0,%eax
jne    1220 <ASN1_TIME_adj_internal+0x80>
movq   $0x0,-0x8(%rbp)
jmp    13a6 <ASN1_TIME_adj_internal+0x206>
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   10b0 <utctime_string_from_tm@plt>
mov    %rax,-0x40(%rbp)
jmp    12a1 <ASN1_TIME_adj_internal+0x101>
lea    -0x30(%rbp),%rdi
call   1080 <gentime_string_from_tm@plt>
mov    %rax,-0x40(%rbp)
jmp    12a1 <ASN1_TIME_adj_internal+0x101>
lea    -0x30(%rbp),%rdi
call   1060 <rfc5280_string_from_tm@plt>
mov    %rax,-0x40(%rbp)
jmp    12a1 <ASN1_TIME_adj_internal+0x101>
movq   $0x0,-0x8(%rbp)
jmp    13a6 <ASN1_TIME_adj_internal+0x206>
cmpq   $0x0,-0x40(%rbp)
jne    12c7 <ASN1_TIME_adj_internal+0x127>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
call   10c0 <ASN1error@plt>
movq   $0x0,-0x8(%rbp)
jmp    13a6 <ASN1_TIME_adj_internal+0x206>
cmpq   $0x0,-0x10(%rbp)
jne    12fb <ASN1_TIME_adj_internal+0x15b>
mov    $0x0,%al
call   1090 <ASN1_TIME_new@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    12f4 <ASN1_TIME_adj_internal+0x154>
movq   $0x0,-0x8(%rbp)
jmp    13a6 <ASN1_TIME_adj_internal+0x206>
movl   $0x1,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
sub    $0xd,%rax
je     1341 <ASN1_TIME_adj_internal+0x1a1>
jmp    131f <ASN1_TIME_adj_internal+0x17f>
mov    -0x50(%rbp),%rax
sub    $0xf,%rax
jne    1350 <ASN1_TIME_adj_internal+0x1b0>
jmp    1332 <ASN1_TIME_adj_internal+0x192>
mov    -0x10(%rbp),%rax
movl   $0x81,(%rax)
jmp    1379 <ASN1_TIME_adj_internal+0x1d9>
mov    -0x10(%rbp),%rax
movl   $0x80,(%rax)
jmp    1379 <ASN1_TIME_adj_internal+0x1d9>
cmpl   $0x0,-0x28(%rbp)
je     1363 <ASN1_TIME_adj_internal+0x1c3>
mov    -0x10(%rbp),%rdi
call   10a0 <ASN1_TIME_free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    13a6 <ASN1_TIME_adj_internal+0x206>
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   1050 <gmtime_r@plt>
test   %rax,%rax
je     129d <ASN1_TIME_adj_internal+0xfd>
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   1070 <OPENSSL_gmtime_adj@plt>
test   %eax,%eax
je     129d <ASN1_TIME_adj_internal+0xfd>
test   %r15d,%r15d
je     120f <ASN1_TIME_adj_internal+0x6f>
cmp    $0x81,%r15d
je     1219 <ASN1_TIME_adj_internal+0x79>
cmp    $0x80,%r15d
jne    129d <ASN1_TIME_adj_internal+0xfd>
mov    %rsp,%rdi
call   10b0 <utctime_string_from_tm@plt>
jmp    1221 <ASN1_TIME_adj_internal+0x81>
mov    %rsp,%rdi
call   1060 <rfc5280_string_from_tm@plt>
jmp    1221 <ASN1_TIME_adj_internal+0x81>
mov    %rsp,%rdi
call   1080 <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   1090 <ASN1_TIME_new@plt>
mov    %rax,%rbx
test   %rax,%rax
je     129d <ASN1_TIME_adj_internal+0xfd>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
cmp    $0xf,%rax
je     126e <ASN1_TIME_adj_internal+0xce>
cmp    $0xd,%rbp
jne    1288 <ASN1_TIME_adj_internal+0xe8>
mov    $0x80,%eax
jmp    1273 <ASN1_TIME_adj_internal+0xd3>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10c0 <ASN1error@plt>
jmp    129d <ASN1_TIME_adj_internal+0xfd>
mov    $0x81,%eax
mov    %eax,(%rbx)
mov    0x8(%rbx),%rdi
call   1030 <free@plt>
mov    %r15,0x8(%rbx)
mov    %rbp,0x10(%rbx)
jmp    129f <ASN1_TIME_adj_internal+0xff>
test   %r14,%r14
jne    1295 <ASN1_TIME_adj_internal+0xf5>
mov    %rbx,%rdi
call   10a0 <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_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 %86
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 %86
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 %86
41: ; preds = %38, %36, %34
%42 = load i8*, i8** %15
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* @ASN1_R_ILLEGAL_TIME_VALUE
%46 = call i32 @ASN1error(i32 %45)
store %struct.TYPE_6__* null, %struct.TYPE_6__** %6
br label %86
47: ; preds = %41
%48 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%49 = icmp eq %struct.TYPE_6__* %48, null
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = call %struct.TYPE_6__* (...) @ASN1_TIME_new()
store %struct.TYPE_6__* %51, %struct.TYPE_6__** %7
%52 = icmp eq %struct.TYPE_6__* %51, null
br i1 %52, label %53, label %54
53: ; preds = %50
store %struct.TYPE_6__* null, %struct.TYPE_6__** %6
br label %86
54: ; preds = %50
store i32 1, i32* %12
br label %55
55: ; preds = %54, %47
%56 = load i8*, i8** %15
%57 = call i64 @strlen(i8* %56)
store i64 %57, i64* %14
%58 = load i64, i64* %14
switch i64 %58, label %65 [
i64 15, label %59
i64 13, label %62
]
59: ; preds = %55
%60 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%61 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %60, i32 0, i32 0
store i32 129, i32* %61
br label %74
62: ; preds = %55
%63 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%64 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %63, i32 0, i32 0
store i32 128, i32* %64
br label %74
65: ; preds = %55
%66 = load i32, i32* %12
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%70 = call i32 @ASN1_TIME_free(%struct.TYPE_6__* %69)
br label %71
71: ; preds = %68, %65
%72 = load i8*, i8** %15
%73 = call i32 @free(i8* %72)
store %struct.TYPE_6__* null, %struct.TYPE_6__** %6
br label %86
74: ; preds = %62, %59
%75 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%76 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %75, i32 0, i32 1
%77 = load i8*, i8** %76
%78 = call i32 @free(i8* %77)
%79 = load i8*, i8** %15
%80 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%81 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %80, i32 0, i32 1
store i8* %79, i8** %81
%82 = load i64, i64* %14
%83 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
%84 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %83, i32 0, i32 2
store i64 %82, i64* %84
%85 = load %struct.TYPE_6__*, %struct.TYPE_6__** %7
store %struct.TYPE_6__* %85, %struct.TYPE_6__** %6
br label %86
86: ; preds = %74, %71, %53, %44, %40, %30, %18
%87 = load %struct.TYPE_6__*, %struct.TYPE_6__** %6
ret %struct.TYPE_6__* %87
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32, i8*, i64 }
%struct.tm = type { i32 }
@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 %52, 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 %52, label %18
18: ; preds = %15, %11
switch i32 %4, label %52 [
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 %31
28: ; preds = %25
%29 = load i32, i32* @ASN1_R_ILLEGAL_TIME_VALUE
%30 = call i32 @ASN1error(i32 %29)
br label %52
31: ; preds = %25
%32 = icmp eq %struct.TYPE_6__* %0, null
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = call %struct.TYPE_6__* (...) @ASN1_TIME_new()
%35 = icmp eq %struct.TYPE_6__* %34, null
br i1 %35, label %52, label %36
36: ; preds = %33, %31
%37 = phi %struct.TYPE_6__* [ %0, %31 ], [ %34, %33 ]
%38 = call i64 @strlen(i8* %26)
switch i64 %38, label %40 [
i64 15, label %45
i64 13, label %39
]
39: ; preds = %36
br label %45
40: ; preds = %36
br i1 %32, label %41, label %43
41: ; preds = %40
%42 = call i32 @ASN1_TIME_free(%struct.TYPE_6__* %37)
br label %43
43: ; preds = %41, %40
%44 = call i32 @free(i8* %26)
br label %52
45: ; preds = %36, %39
%46 = phi i32 [ 128, %39 ], [ 129, %36 ]
%47 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %37, i64 0, i32 0
store i32 %46, i32* %47
%48 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %37, i64 0, i32 1
%49 = load i8*, i8** %48
%50 = call i32 @free(i8* %49)
store i8* %26, i8** %48
%51 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %37, i64 0, i32 2
store i64 %38, i64* %51
br label %52
52: ; preds = %33, %18, %15, %5, %45, %43, %28
%53 = phi %struct.TYPE_6__* [ null, %28 ], [ null, %43 ], [ %37, %45 ], [ null, %5 ], [ null, %15 ], [ null, %18 ], [ null, %33 ]
ret %struct.TYPE_6__* %53
}