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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int strftime(char *, int, char *, struct tm *);
void current_datetime(char *buf, int size, struct tm *tp) {
  int len;
  struct timeval tv;
  gettimeofday(&tv, NULL);
  localtime_r(&tv.tv_sec, tp);
  len = strftime(buf, size, "%F %T", tp);
  sprintf(buf + len, ".%06ld", tv.tv_usec);
}


x86 assembly (clang, -O0):
<current_datetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x28(%rbp),%rdi
add    $0x4,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xe7d(%rip),%rdx
call   1050 <strftime@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%edx
lea    0xe66(%rip),%rsi
call   1060 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<current_datetime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <localtime_r@plt>
lea    0xe8f(%rip),%rdx
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %rbx,%rcx
call   1050 <strftime@plt>
movslq %eax,%rdi
add    %rbp,%rdi
mov    0x8(%rsp),%edx
lea    0xe76(%rip),%rsi
call   1060 <sprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [6 x i8] c"%F %T\00"
@.str.1 = [7 x i8] c".%06ld\00"
define void @current_datetime(i8* %0, i32 %1, %struct.tm* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.tm*
%7 = alloca i32
%8 = alloca %struct.timeval
store i8* %0, i8** %4
store i32 %1, i32* %5
store %struct.tm* %2, %struct.tm** %6
%9 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%11 = load %struct.tm*, %struct.tm** %6
%12 = call i32 @localtime_r(i32* %10, %struct.tm* %11)
%13 = load i8*, i8** %4
%14 = load i32, i32* %5
%15 = load %struct.tm*, %struct.tm** %6
%16 = call i32 @strftime(i8* %13, i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %15)
store i32 %16, i32* %7
%17 = load i8*, i8** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %22)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [6 x i8] c"%F %T\00"
@.str.1 = [7 x i8] c".%06ld\00"
define void @current_datetime(i8* %0, i32 %1, %struct.tm* %2) {
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %4 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%8 = call i32 @localtime_r(i32* %7, %struct.tm* %2)
%9 = call i32 @strftime(i8* %0, i32 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %2)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %13)
ret void
}