#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 */

/* Type definitions */
typedef int uint64_t;
typedef int /*<<< orphan*/ time_t;
typedef int /*<<< orphan*/ genstr;
typedef int /*<<< orphan*/ BIO;
typedef int /*<<< orphan*/ ASN1_GENERALIZEDTIME;

/* Variables and functions */
int /*<<< orphan*/ ASN1_GENERALIZEDTIME_adj(int /*<<< orphan*/ *,
                                            int /*<<< orphan*/, int, int);
int /*<<< orphan*/ ASN1_GENERALIZEDTIME_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *ASN1_GENERALIZEDTIME_new();
int /*<<< orphan*/ ASN1_GENERALIZEDTIME_print(int /*<<< orphan*/ *,
                                              int /*<<< orphan*/ *);
scalar_t__ ASN1_GENERALIZEDTIME_set_string(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ ASN1_STRING_get0_data(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_snprintf(char *, int, char *, int /*<<< orphan*/,
                                unsigned int);
void timestamp_print(uint64_t timestamp, BIO *out) {
  ASN1_GENERALIZEDTIME *gen = ASN1_GENERALIZEDTIME_new();
  char genstr[20];
  if (gen == NULL)
    return;
  ASN1_GENERALIZEDTIME_adj(gen, (time_t)0, (int)(timestamp / 86400000),
                           (timestamp % 86400000) / 1000);
  BIO_snprintf(genstr, sizeof(genstr), "%.14s.%03dZ",
               ASN1_STRING_get0_data(gen), (unsigned int)(timestamp % 1000));
  if (ASN1_GENERALIZEDTIME_set_string(gen, genstr))
    ASN1_GENERALIZEDTIME_print(out, gen);
  ASN1_GENERALIZEDTIME_free(gen);
}


x86 assembly (clang, -O0):
<timestamp_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <ASN1_GENERALIZEDTIME_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119a <timestamp_print+0x2a>
jmp    1230 <timestamp_print+0xc0>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0x5265c00,%ecx
cltd
idiv   %ecx
mov    %eax,-0x3c(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x5265c00,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x3c(%rbp),%edx
mov    %eax,%ecx
xor    %esi,%esi
call   1030 <ASN1_GENERALIZEDTIME_adj@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <ASN1_STRING_get0_data@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%ecx
mov    -0x4(%rbp),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
mov    %edx,%r8d
mov    $0x14,%esi
lea    0xe02(%rip),%rdx
call   1070 <BIO_snprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <ASN1_GENERALIZEDTIME_set_string@plt>
cmp    $0x0,%rax
je     1227 <timestamp_print+0xb7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <ASN1_GENERALIZEDTIME_print@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ASN1_GENERALIZEDTIME_free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestamp_print>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %eax,%eax
call   1090 <ASN1_GENERALIZEDTIME_new@plt>
test   %rax,%rax
je     1238 <timestamp_print+0xc8>
mov    %rax,%r15
movslq %ebx,%rbx
imul   $0x31b5d43b,%rbx,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x38,%rdx
add    %eax,%edx
imul   $0x5265c00,%edx,%eax
mov    %ebx,%ecx
sub    %eax,%ecx
movslq %ecx,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x26,%rcx
add    %eax,%ecx
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <ASN1_GENERALIZEDTIME_adj@plt>
mov    %r15,%rdi
call   1080 <ASN1_STRING_get0_data@plt>
imul   $0x10624dd3,%rbx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%ebx
lea    0xe00(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x14,%esi
mov    %eax,%ecx
mov    %ebx,%r8d
call   1070 <BIO_snprintf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <ASN1_GENERALIZEDTIME_set_string@plt>
test   %rax,%rax
je     1230 <timestamp_print+0xc0>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <ASN1_GENERALIZEDTIME_print@plt>
mov    %r15,%rdi
call   1050 <ASN1_GENERALIZEDTIME_free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%.14s.%03dZ\00"
define void @timestamp_print(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [20 x i8]
store i32 %0, i32* %3
store i32* %1, i32** %4
%7 = call i32* (...) @ASN1_GENERALIZEDTIME_new()
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
br label %36
11: ; preds = %2
%12 = load i32*, i32** %5
%13 = load i32, i32* %3
%14 = sdiv i32 %13, 86400000
%15 = load i32, i32* %3
%16 = srem i32 %15, 86400000
%17 = sdiv i32 %16, 1000
%18 = call i32 @ASN1_GENERALIZEDTIME_adj(i32* %12, i32 0, i32 %14, i32 %17)
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i32 @ASN1_STRING_get0_data(i32* %20)
%22 = load i32, i32* %3
%23 = srem i32 %22, 1000
%24 = call i32 @BIO_snprintf(i8* %19, i32 20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %23)
%25 = load i32*, i32** %5
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%27 = call i64 @ASN1_GENERALIZEDTIME_set_string(i32* %25, i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %11
%30 = load i32*, i32** %4
%31 = load i32*, i32** %5
%32 = call i32 @ASN1_GENERALIZEDTIME_print(i32* %30, i32* %31)
br label %33
33: ; preds = %29, %11
%34 = load i32*, i32** %5
%35 = call i32 @ASN1_GENERALIZEDTIME_free(i32* %34)
br label %36
36: ; preds = %33, %10
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%.14s.%03dZ\00"
define void @timestamp_print(i32 %0, i32* %1) {
%3 = alloca [20 x i8]
%4 = tail call i32* (...) @ASN1_GENERALIZEDTIME_new()
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%6 = icmp eq i32* %4, null
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = sdiv i32 %0, 86400000
%9 = srem i32 %0, 86400000
%10 = sdiv i32 %9, 1000
%11 = tail call i32 @ASN1_GENERALIZEDTIME_adj(i32* %4, i32 0, i32 %8, i32 %10)
%12 = tail call i32 @ASN1_STRING_get0_data(i32* %4)
%13 = srem i32 %0, 1000
%14 = call i32 @BIO_snprintf(i8* %5, i32 20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%15 = call i64 @ASN1_GENERALIZEDTIME_set_string(i32* %4, i8* %5)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %7
%18 = call i32 @ASN1_GENERALIZEDTIME_print(i32* %1, i32* %4)
br label %19
19: ; preds = %17, %7
%20 = call i32 @ASN1_GENERALIZEDTIME_free(i32* %4)
br label %21
21: ; preds = %2, %19
ret void
}