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

/* Type definitions */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int /*<<< orphan*/ tm_sec;
  int /*<<< orphan*/ tm_min;
  int /*<<< orphan*/ tm_hour;
};
struct TYPE_4__ {
  unsigned char *data;
  int /*<<< orphan*/ type;
  scalar_t__ length;
};
typedef TYPE_1__ ASN1_GENERALIZEDTIME;

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_ASN1_GENERALIZEDTIME_ADJ;
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ OPENSSL_gmtime_adj(struct tm *, int, long);
int /*<<< orphan*/ V_ASN1_GENERALIZEDTIME;
int /*<<< orphan*/ free(unsigned char *);
struct tm *gmtime_r(int /*<<< orphan*/ *, struct tm *);
char *malloc(size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, int, int, int,
                            int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/);
scalar_t__ strlen(char *);
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj_internal(ASN1_GENERALIZEDTIME *s,
                                                        time_t t,
                                                        int offset_day,
                                                        long offset_sec) {
  char *p;
  struct tm *ts;
  struct tm data;
  size_t len = 20;
  ts = gmtime_r(&t, &data);
  if (ts == NULL)
    return (NULL);
  if (offset_day || offset_sec) {
    if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
      return NULL;
  }
  p = (char *)s->data;
  if ((p == NULL) || ((size_t)s->length < len)) {
    p = malloc(len);
    if (p == NULL) {
      ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, ERR_R_MALLOC_FAILURE);
      return (NULL);
    }
    free(s->data);
    s->data = (unsigned char *)p;
  }
  snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900,
           ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);
  s->length = strlen(p);
  s->type = V_ASN1_GENERALIZEDTIME;
  return (s);
}


x86 assembly (clang, -O0):
<ASN1_GENERALIZEDTIME_adj_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x14,-0x50(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1070 <gmtime_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b7 <ASN1_GENERALIZEDTIME_adj_internal+0x47>
movq   $0x0,-0x8(%rbp)
jmp    12f6 <ASN1_GENERALIZEDTIME_adj_internal+0x186>
cmpl   $0x0,-0x18(%rbp)
jne    11cc <ASN1_GENERALIZEDTIME_adj_internal+0x5c>
cmpq   $0x0,-0x20(%rbp)
je     11f7 <ASN1_GENERALIZEDTIME_adj_internal+0x87>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1080 <OPENSSL_gmtime_adj@plt>
cmp    $0x0,%eax
jne    11f2 <ASN1_GENERALIZEDTIME_adj_internal+0x82>
movq   $0x0,-0x8(%rbp)
jmp    12f6 <ASN1_GENERALIZEDTIME_adj_internal+0x186>
jmp    11f7 <ASN1_GENERALIZEDTIME_adj_internal+0x87>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     121f <ASN1_GENERALIZEDTIME_adj_internal+0xaf>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
cmp    -0x50(%rbp),%rax
jae    1272 <ASN1_GENERALIZEDTIME_adj_internal+0x102>
mov    -0x50(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    125b <ASN1_GENERALIZEDTIME_adj_internal+0xeb>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f6 <ASN1_GENERALIZEDTIME_adj_internal+0x186>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%r8d
add    $0x1,%r8d
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%r11d
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%eax
lea    0xd48(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1060 <snprintf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    0x2cf3(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_GENERALIZEDTIME_adj_internal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r15
mov    %edx,%ebp
mov    %rdi,%r14
mov    %esi,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1070 <gmtime_r@plt>
test   %rax,%rax
je     125b <ASN1_GENERALIZEDTIME_adj_internal+0xeb>
mov    %rax,%rbx
test   %ebp,%ebp
jne    11aa <ASN1_GENERALIZEDTIME_adj_internal+0x3a>
test   %r15,%r15
je     11bf <ASN1_GENERALIZEDTIME_adj_internal+0x4f>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1080 <OPENSSL_gmtime_adj@plt>
test   %eax,%eax
je     125b <ASN1_GENERALIZEDTIME_adj_internal+0xeb>
mov    (%r14),%r15
test   %r15,%r15
je     11ce <ASN1_GENERALIZEDTIME_adj_internal+0x5e>
cmpq   $0x13,0x10(%r14)
ja     11ee <ASN1_GENERALIZEDTIME_adj_internal+0x7e>
mov    $0x14,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1244 <ASN1_GENERALIZEDTIME_adj_internal+0xd4>
mov    %rax,%rbp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,(%r14)
mov    %rbp,%r15
mov    $0x76c,%ecx
add    (%rbx),%ecx
mov    0x4(%rbx),%r8d
mov    0x8(%rbx),%r9d
add    $0x1,%r8d
mov    0x14(%rbx),%eax
mov    0x10(%rbx),%ebp
mov    0xc(%rbx),%ebx
sub    $0x8,%rsp
lea    0xdeb(%rip),%rdx
mov    $0x14,%esi
mov    %r15,%rdi
push   %rbx
push   %rbp
push   %rax
call   1060 <snprintf@plt>
add    $0x20,%rsp
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,0x10(%r14)
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%r14)
jmp    125e <ASN1_GENERALIZEDTIME_adj_internal+0xee>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i8*, i32, i64 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@ASN1_F_ASN1_GENERALIZEDTIME_ADJ = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@.str = [26 x i8] c"%04d%02d%02d%02d%02d%02dZ\00"
@V_ASN1_GENERALIZEDTIME = global i32 0
define %struct.TYPE_4__* @ASN1_GENERALIZEDTIME_adj_internal(%struct.TYPE_4__* %0, i32 %1, i32 %2, i64 %3) {
%5 = alloca %struct.TYPE_4__*
%6 = alloca %struct.TYPE_4__*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca %struct.tm*
%12 = alloca %struct.tm
%13 = alloca i64
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i64 %3, i64* %9
store i64 20, i64* %13
%14 = call %struct.tm* @gmtime_r(i32* %7, %struct.tm* %12)
store %struct.tm* %14, %struct.tm** %11
%15 = load %struct.tm*, %struct.tm** %11
%16 = icmp eq %struct.tm* %15, null
br i1 %16, label %17, label %18
17: ; preds = %4
store %struct.TYPE_4__* null, %struct.TYPE_4__** %5
br label %93
18: ; preds = %4
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i64, i64* %9
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %21, %18
%25 = load %struct.tm*, %struct.tm** %11
%26 = load i32, i32* %8
%27 = load i64, i64* %9
%28 = call i32 @OPENSSL_gmtime_adj(%struct.tm* %25, i32 %26, i64 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %24
store %struct.TYPE_4__* null, %struct.TYPE_4__** %5
br label %93
31: ; preds = %24
br label %32
32: ; preds = %31, %21
%33 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %33, i32 0, i32 0
%35 = load i8*, i8** %34
store i8* %35, i8** %10
%36 = load i8*, i8** %10
%37 = icmp eq i8* %36, null
br i1 %37, label %44, label %38
38: ; preds = %32
%39 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%40 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %39, i32 0, i32 2
%41 = load i64, i64* %40
%42 = load i64, i64* %13
%43 = icmp ult i64 %41, %42
br i1 %43, label %44, label %61
44: ; preds = %38, %32
%45 = load i64, i64* %13
%46 = call i8* @malloc(i64 %45)
store i8* %46, i8** %10
%47 = load i8*, i8** %10
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i32, i32* @ASN1_F_ASN1_GENERALIZEDTIME_ADJ
%51 = load i32, i32* @ERR_R_MALLOC_FAILURE
%52 = call i32 @ASN1err(i32 %50, i32 %51)
store %struct.TYPE_4__* null, %struct.TYPE_4__** %5
br label %93
53: ; preds = %44
%54 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%55 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %54, i32 0, i32 0
%56 = load i8*, i8** %55
%57 = call i32 @free(i8* %56)
%58 = load i8*, i8** %10
%59 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%60 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %59, i32 0, i32 0
store i8* %58, i8** %60
br label %61
61: ; preds = %53, %38
%62 = load i8*, i8** %10
%63 = load i64, i64* %13
%64 = load %struct.tm*, %struct.tm** %11
%65 = getelementptr inbounds %struct.tm, %struct.tm* %64, i32 0, i32 0
%66 = load i32, i32* %65
%67 = add nsw i32 %66, 1900
%68 = load %struct.tm*, %struct.tm** %11
%69 = getelementptr inbounds %struct.tm, %struct.tm* %68, i32 0, i32 1
%70 = load i32, i32* %69
%71 = add nsw i32 %70, 1
%72 = load %struct.tm*, %struct.tm** %11
%73 = getelementptr inbounds %struct.tm, %struct.tm* %72, i32 0, i32 2
%74 = load i32, i32* %73
%75 = load %struct.tm*, %struct.tm** %11
%76 = getelementptr inbounds %struct.tm, %struct.tm* %75, i32 0, i32 5
%77 = load i32, i32* %76
%78 = load %struct.tm*, %struct.tm** %11
%79 = getelementptr inbounds %struct.tm, %struct.tm* %78, i32 0, i32 4
%80 = load i32, i32* %79
%81 = load %struct.tm*, %struct.tm** %11
%82 = getelementptr inbounds %struct.tm, %struct.tm* %81, i32 0, i32 3
%83 = load i32, i32* %82
%84 = call i32 @snprintf(i8* %62, i64 %63, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %67, i32 %71, i32 %74, i32 %77, i32 %80, i32 %83)
%85 = load i8*, i8** %10
%86 = call i64 @strlen(i8* %85)
%87 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%88 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %87, i32 0, i32 2
store i64 %86, i64* %88
%89 = load i32, i32* @V_ASN1_GENERALIZEDTIME
%90 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%91 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %90, i32 0, i32 1
store i32 %89, i32* %91
%92 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
store %struct.TYPE_4__* %92, %struct.TYPE_4__** %5
br label %93
93: ; preds = %61, %49, %30, %17
%94 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
ret %struct.TYPE_4__* %94
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i8*, i32, i64 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@ASN1_F_ASN1_GENERALIZEDTIME_ADJ = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@.str = [26 x i8] c"%04d%02d%02d%02d%02d%02dZ\00"
@V_ASN1_GENERALIZEDTIME = global i32 0
define %struct.TYPE_4__* @ASN1_GENERALIZEDTIME_adj_internal(%struct.TYPE_4__* %0, i32 %1, i32 %2, i64 %3) {
%5 = alloca i32
%6 = alloca %struct.tm
store i32 %1, i32* %5
%7 = bitcast %struct.tm* %6 to i8*
%8 = call %struct.tm* @gmtime_r(i32* %5, %struct.tm* %6)
%9 = icmp eq %struct.tm* %8, null
br i1 %9, label %55, label %10
10: ; preds = %4
%11 = icmp ne i32 %2, 0
%12 = icmp ne i64 %3, 0
%13 = or i1 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 @OPENSSL_gmtime_adj(%struct.tm* %8, i32 %2, i64 %3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %55, label %17
17: ; preds = %14, %10
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
%23 = load i64, i64* %22
%24 = icmp ult i64 %23, 20
br i1 %24, label %25, label %34
25: ; preds = %21, %17
%26 = call dereferenceable_or_null(20) i8* @malloc(i64 20)
%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* @ERR_R_MALLOC_FAILURE
%31 = call i32 @ASN1err(i32 %29, i32 %30)
br label %55
32: ; preds = %25
%33 = call i32 @free(i8* %19)
store i8* %26, i8** %18
br label %34
34: ; preds = %32, %21
%35 = phi i8* [ %26, %32 ], [ %19, %21 ]
%36 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 0
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1900
%39 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 1
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 1
%42 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 2
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 5
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 4
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 3
%49 = load i32, i32* %48
%50 = call i32 @snprintf(i8* %35, i64 20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %38, i32 %41, i32 %43, i32 %45, i32 %47, i32 %49)
%51 = call i64 @strlen(i8* %35)
%52 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
store i64 %51, i64* %52
%53 = load i32, i32* @V_ASN1_GENERALIZEDTIME
%54 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
store i32 %53, i32* %54
br label %55
55: ; preds = %14, %4, %34, %28
%56 = phi %struct.TYPE_4__* [ null, %28 ], [ %0, %34 ], [ null, %4 ], [ null, %14 ]
ret %struct.TYPE_4__* %56
}