#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 */
struct tm {
  int dummy;
};
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
size_t snprintf(char *, int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
const char *_log_datestamp(void) {
  struct timeval tv;
  struct tm *tm;
  static char buf[128];
  size_t c;
  if (gettimeofday(&tv, NULL) < 0) {
    return "-1";
  }
  tm = localtime(&(tv.tv_sec));
  c = snprintf(buf, sizeof(buf) - 1, "%lu.%06lu", tv.tv_sec, tv.tv_usec);
  strftime(&buf[c], (sizeof(buf) - c - 1), " %F %T", tm);
  buf[sizeof(buf) - 1] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<_log_datestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
jge    116f <_log_datestamp+0x2f>
lea    0xe9a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <_log_datestamp+0x9f>
lea    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0x2ec2(%rip),%rdi
mov    $0x7f,%esi
lea    0xe69(%rip),%rdx
call   1040 <snprintf@plt>
mov    %rax,-0x20(%rbp)
lea    0x2ea6(%rip),%rdi
add    -0x20(%rbp),%rdi
mov    $0x80,%eax
sub    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
lea    0xe45(%rip),%rdx
call   1060 <strftime@plt>
movb   $0x0,0x2efb(%rip)
lea    0x2e75(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_log_datestamp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %rax,%rax
js     11af <_log_datestamp+0x6f>
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%r14
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%ecx
lea    0x2eda(%rip),%rbx
lea    0xe86(%rip),%rdx
mov    $0x7f,%ebp
mov    %rbx,%rdi
mov    $0x7f,%esi
call   1040 <snprintf@plt>
lea    (%rbx,%rax,1),%rdi
sub    %eax,%ebp
lea    0xe71(%rip),%rdx
mov    %ebp,%esi
mov    %r14,%rcx
call   1060 <strftime@plt>
movb   $0x0,0x2f22(%rip)
jmp    11b6 <_log_datestamp+0x76>
lea    0xe4a(%rip),%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@_log_datestamp.buf = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"-1\00"
@.str.1 = [10 x i8] c"%lu.%06lu\00"
@.str.2 = [7 x i8] c" %F %T\00"
define i8* @_log_datestamp() {
%1 = alloca i8*
%2 = alloca %struct.timeval
%3 = alloca %struct.tm*
%4 = alloca i64
%5 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %1
br label %24
8: ; preds = %0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%10 = call %struct.tm* @localtime(i32* %9)
store %struct.tm* %10, %struct.tm** %3
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @_log_datestamp.buf, i64 0, i64 0), i32 127, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %14)
store i64 %15, i64* %4
%16 = load i64, i64* %4
%17 = getelementptr inbounds [128 x i8], [128 x i8]* @_log_datestamp.buf, i64 0, i64 %16
%18 = load i64, i64* %4
%19 = sub i64 128, %18
%20 = sub i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = load %struct.tm*, %struct.tm** %3
%23 = call i32 @strftime(i8* %17, i32 %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %22)
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @_log_datestamp.buf, i64 0, i64 127)
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @_log_datestamp.buf, i64 0, i64 0), i8** %1
br label %24
24: ; preds = %8, %7
%25 = load i8*, i8** %1
ret i8* %25
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@_log_datestamp.buf = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"-1\00"
@.str.1 = [10 x i8] c"%lu.%06lu\00"
@.str.2 = [7 x i8] c" %F %T\00"
define i8* @_log_datestamp() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp slt i64 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %0
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%7 = call %struct.tm* @localtime(i32* %6)
%8 = load i32, i32* %6
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = call i64 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @_log_datestamp.buf, i64 0, i64 0), i32 127, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %10)
%12 = getelementptr inbounds [128 x i8], [128 x i8]* @_log_datestamp.buf, i64 0, i64 %11
%13 = trunc i64 %11 to i32
%14 = sub i32 127, %13
%15 = call i32 @strftime(i8* %12, i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %7)
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @_log_datestamp.buf, i64 0, i64 127)
br label %16
16: ; preds = %0, %5
%17 = phi i8* [ getelementptr inbounds ([128 x i8], [128 x i8]* @_log_datestamp.buf, i64 0, i64 0), %5 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %0 ]
ret i8* %17
}