#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 timespec {
  int /*<<< orphan*/ tv_nsec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int strlen(char *);
char *format_time_8601plus(struct timespec *timestamp) {
  struct tm *ltime = localtime(&timestamp->tv_sec);
  static char buf[32];
  strftime(buf, 20, "%F %T", ltime);
  snprintf(buf + strlen(buf), 11, ".%09li", timestamp->tv_nsec);
  return buf;
}


x86 assembly (clang, -O0):
<format_time_8601plus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
lea    0x2ee8(%rip),%rdi
mov    $0x14,%esi
lea    0xe8c(%rip),%rdx
call   1060 <strftime@plt>
lea    0x2ed0(%rip),%rdi
call   1040 <strlen@plt>
cltq
lea    0x2ec2(%rip),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    $0xb,%esi
lea    0xe63(%rip),%rdx
call   1050 <snprintf@plt>
lea    0x2ea1(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_time_8601plus>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
add    $0x4,%rdi
call   1030 <localtime@plt>
lea    0x2ef9(%rip),%r14
lea    0xea2(%rip),%rdx
mov    %r14,%rdi
mov    $0x14,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
add    %r14,%rdi
mov    (%rbx),%ecx
lea    0xe81(%rip),%rdx
mov    $0xb,%esi
call   1050 <snprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.tm = type { i32 }
@format_time_8601plus.buf = internal global [32 x i8] zeroinitializer
@.str = [6 x i8] c"%F %T\00"
@.str.1 = [7 x i8] c".%09li\00"
define i8* @format_time_8601plus(%struct.timespec* %0) {
%2 = alloca %struct.timespec*
%3 = alloca %struct.tm*
store %struct.timespec* %0, %struct.timespec** %2
%4 = load %struct.timespec*, %struct.timespec** %2
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%6 = call %struct.tm* @localtime(i32* %5)
store %struct.tm* %6, %struct.tm** %3
%7 = load %struct.tm*, %struct.tm** %3
%8 = call i32 @strftime(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @format_time_8601plus.buf, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %7)
%9 = call i32 @strlen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @format_time_8601plus.buf, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @format_time_8601plus.buf, i64 0, i64 0), i64 %10
%12 = load %struct.timespec*, %struct.timespec** %2
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @snprintf(i8* %11, i32 11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %14)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @format_time_8601plus.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
%struct.tm = type { i32 }
@format_time_8601plus.buf = internal global [32 x i8] zeroinitializer
@.str = [6 x i8] c"%F %T\00"
@.str.1 = [7 x i8] c".%09li\00"
define i8* @format_time_8601plus(%struct.timespec* %0) {
%2 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%3 = tail call %struct.tm* @localtime(i32* %2)
%4 = tail call i32 @strftime(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @format_time_8601plus.buf, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %3)
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @format_time_8601plus.buf, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [32 x i8], [32 x i8]* @format_time_8601plus.buf, i64 0, i64 %6
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @snprintf(i8* %7, i32 11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %9)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @format_time_8601plus.buf, i64 0, i64 0)
}