#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 scalar_t__ time_t;
struct tm {
  scalar_t__ tm_year;
  scalar_t__ tm_mon;
  scalar_t__ tm_mday;
  scalar_t__ tm_hour;
  scalar_t__ tm_min;
  scalar_t__ tm_sec;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ check_ptr_or_quit(char *);
struct tm *gmtime(scalar_t__ *);
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
scalar_t__ time(int /*<<< orphan*/ *);
char *new_timestamp(void) {
  char *timestamp;
  time_t t;
  struct tm *ti;
  static struct tm last_time = {0};
  static int fake_micro = 0;
  timestamp = malloc(64);
  check_ptr_or_quit(timestamp);
  t = time(NULL);
  if (t != (time_t)-1) {
    ti = gmtime(&t);
  } else {
    ti = NULL;
  }
  if (ti) {
    if (last_time.tm_year == ti->tm_year && last_time.tm_mon == ti->tm_mon &&
        last_time.tm_mday == ti->tm_mday && last_time.tm_hour == ti->tm_hour &&
        last_time.tm_min == ti->tm_min && last_time.tm_sec == ti->tm_sec) {
      fake_micro += 1;
    } else {
      fake_micro = 0;
      last_time = *ti;
    }
    snprintf(timestamp, 64, "%d-%02d-%02dT%02d:%02d:%02d.%06dZ",
             ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour,
             ti->tm_min, ti->tm_sec, fake_micro);
  } else {
    snprintf(timestamp, 64, "Unknown");
  }
  return timestamp;
}


x86 assembly (clang, -O0):
<new_timestamp>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x38,%rsp
mov    $0x40,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <check_ptr_or_quit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
je     11aa <new_timestamp+0x4a>
lea    -0x18(%rbp),%rdi
call   1080 <gmtime@plt>
mov    %rax,-0x20(%rbp)
jmp    11b2 <new_timestamp+0x52>
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12db <new_timestamp+0x17b>
mov    0x2e94(%rip),%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
jne    124e <new_timestamp+0xee>
mov    0x2e88(%rip),%rax
mov    -0x20(%rbp),%rcx
cmp    0x8(%rcx),%rax
jne    124e <new_timestamp+0xee>
mov    0x2e7b(%rip),%rax
mov    -0x20(%rbp),%rcx
cmp    0x10(%rcx),%rax
jne    124e <new_timestamp+0xee>
mov    0x2e6e(%rip),%rax
mov    -0x20(%rbp),%rcx
cmp    0x18(%rcx),%rax
jne    124e <new_timestamp+0xee>
mov    0x2e61(%rip),%rax
mov    -0x20(%rbp),%rcx
cmp    0x20(%rcx),%rax
jne    124e <new_timestamp+0xee>
mov    0x2e54(%rip),%rax
mov    -0x20(%rbp),%rcx
cmp    0x28(%rcx),%rax
jne    124e <new_timestamp+0xee>
mov    0x2e50(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e47(%rip)
jmp    126d <new_timestamp+0x10d>
movl   $0x0,0x2e38(%rip)
mov    -0x20(%rbp),%rsi
lea    0x2df5(%rip),%rdi
mov    $0x38,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x76c,%rcx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8
add    $0x1,%r8
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%r9
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rbx
mov    -0x20(%rbp),%rax
mov    0x20(%rax),%r11
mov    -0x20(%rbp),%rax
mov    0x28(%rax),%r10
mov    0x2ddf(%rip),%eax
mov    $0x40,%esi
lea    0xd43(%rip),%rdx
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %eax,0x18(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12f2 <new_timestamp+0x192>
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
lea    0xd37(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_timestamp>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <check_ptr_or_quit@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,0x8(%rsp)
cmp    $0xffffffffffffffff,%rax
je     11f0 <new_timestamp+0xa0>
lea    0x8(%rsp),%rdi
call   1070 <gmtime@plt>
test   %rax,%rax
je     11f0 <new_timestamp+0xa0>
mov    0x2eba(%rip),%rcx
cmp    (%rax),%rcx
jne    1208 <new_timestamp+0xb8>
mov    0x2eb6(%rip),%r8
cmp    0x8(%rax),%r8
jne    1208 <new_timestamp+0xb8>
mov    0x2eb1(%rip),%r9
cmp    0x10(%rax),%r9
jne    1208 <new_timestamp+0xb8>
mov    0x2eac(%rip),%r10
cmp    0x18(%rax),%r10
jne    1208 <new_timestamp+0xb8>
mov    0x2ea7(%rip),%r11
cmp    0x20(%rax),%r11
jne    1208 <new_timestamp+0xb8>
mov    0x2ea2(%rip),%r14
cmp    0x28(%rax),%r14
jne    1208 <new_timestamp+0xb8>
mov    0x2ea5(%rip),%r15d
add    $0x1,%r15d
mov    %r15d,0x2e9a(%rip)
jmp    1257 <new_timestamp+0x107>
lea    0xe2b(%rip),%rdx
mov    %rbx,%rdi
mov    $0x40,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    1284 <new_timestamp+0x134>
movl   $0x0,0x2e76(%rip)
mov    0x30(%rax),%rcx
mov    %rcx,0x2e63(%rip)
movups (%rax),%xmm0
movups 0x10(%rax),%xmm1
movups 0x20(%rax),%xmm2
movups %xmm2,0x2e41(%rip)
movups %xmm1,0x2e2a(%rip)
movups %xmm0,0x2e13(%rip)
mov    (%rax),%rcx
mov    0x8(%rax),%r8
mov    0x10(%rax),%r9
mov    0x18(%rax),%r10
mov    0x20(%rax),%r11
mov    0x28(%rax),%r14
xor    %r15d,%r15d
add    $0x76c,%rcx
add    $0x1,%r8
lea    0xd97(%rip),%rdx
mov    %rbx,%rdi
mov    $0x40,%esi
xor    %eax,%eax
push   %r15
push   %r14
push   %r11
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.tm = type { i64, i64, i64, i64, i64, i64, i32 }
@new_timestamp.last_time = internal unnamed_addr global %struct.tm zeroinitializer
@new_timestamp.fake_micro = internal unnamed_addr global i32 0
@.str = [34 x i8] c"%d-%02d-%02dT%02d:%02d:%02d.%06dZ\00"
@.str.1 = [8 x i8] c"Unknown\00"
define i8* @new_timestamp() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
%4 = tail call i32 @check_ptr_or_quit(i8* %3)
%5 = tail call i64 @time(i32* null)
store i64 %5, i64* %1
%6 = icmp eq i64 %5, -1
br i1 %6, label %67, label %7
7: ; preds = %0
%8 = call %struct.tm* @gmtime(i64* %1)
%9 = icmp eq %struct.tm* %8, null
br i1 %9, label %67, label %10
10: ; preds = %7
%11 = load i64, i64* getelementptr inbounds (%struct.tm, %struct.tm* @new_timestamp.last_time, i64 0, i32 0)
%12 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 0
%13 = load i64, i64* %12
%14 = icmp eq i64 %11, %13
br i1 %14, label %15, label %43
15: ; preds = %10
%16 = load i64, i64* getelementptr inbounds (%struct.tm, %struct.tm* @new_timestamp.last_time, i64 0, i32 1)
%17 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 1
%18 = load i64, i64* %17
%19 = icmp eq i64 %16, %18
br i1 %19, label %20, label %43
20: ; preds = %15
%21 = load i64, i64* getelementptr inbounds (%struct.tm, %struct.tm* @new_timestamp.last_time, i64 0, i32 2)
%22 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 2
%23 = load i64, i64* %22
%24 = icmp eq i64 %21, %23
br i1 %24, label %25, label %43
25: ; preds = %20
%26 = load i64, i64* getelementptr inbounds (%struct.tm, %struct.tm* @new_timestamp.last_time, i64 0, i32 3)
%27 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 3
%28 = load i64, i64* %27
%29 = icmp eq i64 %26, %28
br i1 %29, label %30, label %43
30: ; preds = %25
%31 = load i64, i64* getelementptr inbounds (%struct.tm, %struct.tm* @new_timestamp.last_time, i64 0, i32 4)
%32 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 4
%33 = load i64, i64* %32
%34 = icmp eq i64 %31, %33
br i1 %34, label %35, label %43
35: ; preds = %30
%36 = load i64, i64* getelementptr inbounds (%struct.tm, %struct.tm* @new_timestamp.last_time, i64 0, i32 5)
%37 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 5
%38 = load i64, i64* %37
%39 = icmp eq i64 %36, %38
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* @new_timestamp.fake_micro
%42 = add nsw i32 %41, 1
store i32 %42, i32* @new_timestamp.fake_micro
br label %56
43: ; preds = %35, %30, %25, %20, %15, %10
store i32 0, i32* @new_timestamp.fake_micro
%44 = bitcast %struct.tm* %8 to i8*
%45 = load i64, i64* %12
%46 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 1
%47 = load i64, i64* %46
%48 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 2
%49 = load i64, i64* %48
%50 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 3
%51 = load i64, i64* %50
%52 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 4
%53 = load i64, i64* %52
%54 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 5
%55 = load i64, i64* %54
br label %56
56: ; preds = %43, %40
%57 = phi i32 [ 0, %43 ], [ %42, %40 ]
%58 = phi i64 [ %55, %43 ], [ %36, %40 ]
%59 = phi i64 [ %53, %43 ], [ %31, %40 ]
%60 = phi i64 [ %51, %43 ], [ %26, %40 ]
%61 = phi i64 [ %49, %43 ], [ %21, %40 ]
%62 = phi i64 [ %47, %43 ], [ %16, %40 ]
%63 = phi i64 [ %45, %43 ], [ %11, %40 ]
%64 = add nsw i64 %63, 1900
%65 = add nsw i64 %62, 1
%66 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %64, i64 %65, i64 %61, i64 %60, i64 %59, i64 %58, i32 %57)
br label %69
67: ; preds = %0, %7
%68 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %69
69: ; preds = %67, %56
ret i8* %3
}