#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_UTCTIME;

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_ASN1_UTCTIME_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_UTCTIME;
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_UTCTIME *ASN1_UTCTIME_adj_internal(ASN1_UTCTIME *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;
  }
  if ((ts->tm_year < 50) || (ts->tm_year >= 150))
    return NULL;
  p = (char *)s->data;
  if ((p == NULL) || ((size_t)s->length < len)) {
    p = malloc(len);
    if (p == NULL) {
      ASN1err(ASN1_F_ASN1_UTCTIME_ADJ, ERR_R_MALLOC_FAILURE);
      return (NULL);
    }
    free(s->data);
    s->data = (unsigned char *)p;
  }
  snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ", ts->tm_year % 100,
           ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);
  s->length = strlen(p);
  s->type = V_ASN1_UTCTIME;
  return (s);
}


x86 assembly (clang, -O0):
<ASN1_UTCTIME_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_UTCTIME_adj_internal+0x47>
movq   $0x0,-0x8(%rbp)
jmp    1324 <ASN1_UTCTIME_adj_internal+0x1b4>
cmpl   $0x0,-0x18(%rbp)
jne    11cc <ASN1_UTCTIME_adj_internal+0x5c>
cmpq   $0x0,-0x20(%rbp)
je     11f7 <ASN1_UTCTIME_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_UTCTIME_adj_internal+0x82>
movq   $0x0,-0x8(%rbp)
jmp    1324 <ASN1_UTCTIME_adj_internal+0x1b4>
jmp    11f7 <ASN1_UTCTIME_adj_internal+0x87>
mov    -0x30(%rbp),%rax
cmpl   $0x32,(%rax)
jl     1214 <ASN1_UTCTIME_adj_internal+0xa4>
mov    -0x30(%rbp),%rax
cmpl   $0x96,(%rax)
jl     1221 <ASN1_UTCTIME_adj_internal+0xb1>
movq   $0x0,-0x8(%rbp)
jmp    1324 <ASN1_UTCTIME_adj_internal+0x1b4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1249 <ASN1_UTCTIME_adj_internal+0xd9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
cmp    -0x50(%rbp),%rax
jae    129c <ASN1_UTCTIME_adj_internal+0x12c>
mov    -0x50(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1285 <ASN1_UTCTIME_adj_internal+0x115>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movq   $0x0,-0x8(%rbp)
jmp    1324 <ASN1_UTCTIME_adj_internal+0x1b4>
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),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,%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    0xd1a(%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    0x2cbd(%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_UTCTIME_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     1283 <ASN1_UTCTIME_adj_internal+0x113>
mov    %rax,%rbx
test   %ebp,%ebp
jne    11aa <ASN1_UTCTIME_adj_internal+0x3a>
test   %r15,%r15
je     11bf <ASN1_UTCTIME_adj_internal+0x4f>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1080 <OPENSSL_gmtime_adj@plt>
test   %eax,%eax
je     1283 <ASN1_UTCTIME_adj_internal+0x113>
mov    (%rbx),%eax
lea    -0x96(%rax),%ecx
cmp    $0xffffff9c,%ecx
jb     1283 <ASN1_UTCTIME_adj_internal+0x113>
mov    (%r14),%r15
test   %r15,%r15
je     11df <ASN1_UTCTIME_adj_internal+0x6f>
cmpq   $0x13,0x10(%r14)
ja     1201 <ASN1_UTCTIME_adj_internal+0x91>
mov    $0x14,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     126c <ASN1_UTCTIME_adj_internal+0xfc>
mov    %rax,%rbp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,(%r14)
mov    (%rbx),%eax
mov    %rbp,%r15
movslq %eax,%rcx
imul   $0x51eb851f,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rax
add    %edx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%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    0xdc3(%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    0x2d6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%r14)
jmp    1286 <ASN1_UTCTIME_adj_internal+0x116>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
mov    0x2d64(%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_UTCTIME_ADJ = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@.str = [26 x i8] c"%02d%02d%02d%02d%02d%02dZ\00"
@V_ASN1_UTCTIME = global i32 0
define %struct.TYPE_4__* @ASN1_UTCTIME_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 %104
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 %104
31: ; preds = %24
br label %32
32: ; preds = %31, %21
%33 = load %struct.tm*, %struct.tm** %11
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = icmp slt i32 %35, 50
br i1 %36, label %42, label %37
37: ; preds = %32
%38 = load %struct.tm*, %struct.tm** %11
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = icmp sge i32 %40, 150
br i1 %41, label %42, label %43
42: ; preds = %37, %32
store %struct.TYPE_4__* null, %struct.TYPE_4__** %5
br label %104
43: ; preds = %37
%44 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%45 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %44, i32 0, i32 0
%46 = load i8*, i8** %45
store i8* %46, i8** %10
%47 = load i8*, i8** %10
%48 = icmp eq i8* %47, null
br i1 %48, label %55, label %49
49: ; preds = %43
%50 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%51 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %50, i32 0, i32 2
%52 = load i64, i64* %51
%53 = load i64, i64* %13
%54 = icmp ult i64 %52, %53
br i1 %54, label %55, label %72
55: ; preds = %49, %43
%56 = load i64, i64* %13
%57 = call i8* @malloc(i64 %56)
store i8* %57, i8** %10
%58 = load i8*, i8** %10
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %64
60: ; preds = %55
%61 = load i32, i32* @ASN1_F_ASN1_UTCTIME_ADJ
%62 = load i32, i32* @ERR_R_MALLOC_FAILURE
%63 = call i32 @ASN1err(i32 %61, i32 %62)
store %struct.TYPE_4__* null, %struct.TYPE_4__** %5
br label %104
64: ; preds = %55
%65 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%66 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %65, i32 0, i32 0
%67 = load i8*, i8** %66
%68 = call i32 @free(i8* %67)
%69 = load i8*, i8** %10
%70 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%71 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %70, i32 0, i32 0
store i8* %69, i8** %71
br label %72
72: ; preds = %64, %49
%73 = load i8*, i8** %10
%74 = load i64, i64* %13
%75 = load %struct.tm*, %struct.tm** %11
%76 = getelementptr inbounds %struct.tm, %struct.tm* %75, i32 0, i32 0
%77 = load i32, i32* %76
%78 = srem i32 %77, 100
%79 = load %struct.tm*, %struct.tm** %11
%80 = getelementptr inbounds %struct.tm, %struct.tm* %79, i32 0, i32 1
%81 = load i32, i32* %80
%82 = add nsw i32 %81, 1
%83 = load %struct.tm*, %struct.tm** %11
%84 = getelementptr inbounds %struct.tm, %struct.tm* %83, i32 0, i32 2
%85 = load i32, i32* %84
%86 = load %struct.tm*, %struct.tm** %11
%87 = getelementptr inbounds %struct.tm, %struct.tm* %86, i32 0, i32 5
%88 = load i32, i32* %87
%89 = load %struct.tm*, %struct.tm** %11
%90 = getelementptr inbounds %struct.tm, %struct.tm* %89, i32 0, i32 4
%91 = load i32, i32* %90
%92 = load %struct.tm*, %struct.tm** %11
%93 = getelementptr inbounds %struct.tm, %struct.tm* %92, i32 0, i32 3
%94 = load i32, i32* %93
%95 = call i32 @snprintf(i8* %73, i64 %74, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %78, i32 %82, i32 %85, i32 %88, i32 %91, i32 %94)
%96 = load i8*, i8** %10
%97 = call i64 @strlen(i8* %96)
%98 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%99 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %98, i32 0, i32 2
store i64 %97, i64* %99
%100 = load i32, i32* @V_ASN1_UTCTIME
%101 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%102 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %101, i32 0, i32 1
store i32 %100, i32* %102
%103 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
store %struct.TYPE_4__* %103, %struct.TYPE_4__** %5
br label %104
104: ; preds = %72, %60, %42, %30, %17
%105 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
ret %struct.TYPE_4__* %105
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i8*, i32, i64 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@ASN1_F_ASN1_UTCTIME_ADJ = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@.str = [26 x i8] c"%02d%02d%02d%02d%02d%02dZ\00"
@V_ASN1_UTCTIME = global i32 0
define %struct.TYPE_4__* @ASN1_UTCTIME_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 %60, 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 %60, label %17
17: ; preds = %14, %10
%18 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 0
%19 = load i32, i32* %18
%20 = add i32 %19, -150
%21 = icmp ult i32 %20, -100
br i1 %21, label %60, label %22
22: ; preds = %17
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
%28 = load i64, i64* %27
%29 = icmp ult i64 %28, 20
br i1 %29, label %30, label %40
30: ; preds = %26, %22
%31 = call dereferenceable_or_null(20) i8* @malloc(i64 20)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* @ASN1_F_ASN1_UTCTIME_ADJ
%35 = load i32, i32* @ERR_R_MALLOC_FAILURE
%36 = call i32 @ASN1err(i32 %34, i32 %35)
br label %60
37: ; preds = %30
%38 = call i32 @free(i8* %24)
store i8* %31, i8** %23
%39 = load i32, i32* %18
br label %40
40: ; preds = %37, %26
%41 = phi i32 [ %39, %37 ], [ %19, %26 ]
%42 = phi i8* [ %31, %37 ], [ %24, %26 ]
%43 = srem i32 %41, 100
%44 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 1
%45 = load i32, i32* %44
%46 = add nsw i32 %45, 1
%47 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 2
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 5
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 4
%52 = load i32, i32* %51
%53 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 3
%54 = load i32, i32* %53
%55 = call i32 @snprintf(i8* %42, i64 20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %43, i32 %46, i32 %48, i32 %50, i32 %52, i32 %54)
%56 = call i64 @strlen(i8* %42)
%57 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 2
store i64 %56, i64* %57
%58 = load i32, i32* @V_ASN1_UTCTIME
%59 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
store i32 %58, i32* %59
br label %60
60: ; preds = %17, %14, %4, %40, %33
%61 = phi %struct.TYPE_4__* [ null, %33 ], [ %0, %40 ], [ null, %4 ], [ null, %14 ], [ null, %17 ]
ret %struct.TYPE_4__* %61
}