#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 /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int strftime(char *, int, char *, struct tm *);
int time(int /*<<< orphan*/ *);
int mdbg_timestamp(char *out, int size) {
  time_t current_time;
  struct tm *bdtime;
  if (size < 24)
    return -1;
  if (time(&current_time) == -1)
    return -1;
  bdtime = localtime(&current_time);
  if (bdtime == NULL)
    return -1;
  if (strftime(out, size, "%Y-%m-%dT%H:%M:%S.000", bdtime) != 23)
    return -1;
  out[23] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<mdbg_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x18,-0x14(%rbp)
jge    1155 <mdbg_timestamp+0x25>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <mdbg_timestamp+0xa2>
lea    -0x18(%rbp),%rdi
call   1040 <time@plt>
cmp    $0xffffffff,%eax
jne    1173 <mdbg_timestamp+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <mdbg_timestamp+0xa2>
lea    -0x18(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1197 <mdbg_timestamp+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <mdbg_timestamp+0xa2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rcx
lea    0xe57(%rip),%rdx
call   1050 <strftime@plt>
cmp    $0x17,%eax
je     11c3 <mdbg_timestamp+0x93>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <mdbg_timestamp+0xa2>
mov    -0x10(%rbp),%rax
movb   $0x0,0x17(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mdbg_timestamp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%ebx
cmp    $0x18,%esi
jl     1185 <mdbg_timestamp+0x55>
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xc(%rsp),%rdi
call   1040 <time@plt>
cmp    $0xffffffff,%eax
je     1185 <mdbg_timestamp+0x55>
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1185 <mdbg_timestamp+0x55>
lea    0xe94(%rip),%rdx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rax,%rcx
call   1050 <strftime@plt>
cmp    $0x17,%eax
jne    1185 <mdbg_timestamp+0x55>
movb   $0x0,0x17(%r14)
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [22 x i8] c"%Y-%m-%dT%H:%M:%S.000\00"
define i32 @mdbg_timestamp(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tm*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 24
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %30
11: ; preds = %2
%12 = call i32 @time(i32* %6)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 -1, i32* %3
br label %30
15: ; preds = %11
%16 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %16, %struct.tm** %7
%17 = load %struct.tm*, %struct.tm** %7
%18 = icmp eq %struct.tm* %17, null
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %3
br label %30
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = load %struct.tm*, %struct.tm** %7
%24 = call i32 @strftime(i8* %21, i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %struct.tm* %23)
%25 = icmp ne i32 %24, 23
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 -1, i32* %3
br label %30
27: ; preds = %20
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 23
store i8 0, i8* %29
store i32 0, i32* %3
br label %30
30: ; preds = %27, %26, %19, %14, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [22 x i8] c"%Y-%m-%dT%H:%M:%S.000\00"
define i32 @mdbg_timestamp(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %1, 24
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = call i32 @time(i32* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = call %struct.tm* @localtime(i32* %3)
%11 = icmp eq %struct.tm* %10, null
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = call i32 @strftime(i8* %0, i32 %1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
%14 = icmp eq i32 %13, 23
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %0, i64 23
store i8 0, i8* %16
br label %17
17: ; preds = %12, %9, %6, %2, %15
%18 = phi i32 [ 0, %15 ], [ -1, %2 ], [ -1, %6 ], [ -1, %9 ], [ -1, %12 ]
ret i32 %18
}