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

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, scalar_t__, scalar_t__,
                            int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
char *iso_time() {
  struct timeval tv;
  time_t now_t;
  int millis;
  struct tm now;
  char *timestring;
  gettimeofday(&tv, NULL);
  now_t = tv.tv_sec;
  millis = tv.tv_usec / 1000;
  now = *localtime(&now_t);
  asprintf(&timestring, "%4d-%02d-%02dT%02d:%02d:%02d.%03d+0200",
           now.tm_year + 1900, now.tm_mon + 1, now.tm_mday, now.tm_hour,
           now.tm_min, now.tm_sec, millis);
  return timestring;
}


x86 assembly (clang, -O0):
<iso_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rcx
mov    %rcx,-0x30(%rbp)
mov    0x8(%rax),%rcx
mov    %rcx,-0x28(%rbp)
mov    0x10(%rax),%rcx
mov    %rcx,-0x20(%rbp)
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdx
add    $0x76c,%rdx
mov    -0x20(%rbp),%rcx
add    $0x1,%rcx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
mov    -0x2c(%rbp),%r11d
mov    -0x30(%rbp),%r10d
mov    -0x10(%rbp),%eax
lea    -0x38(%rbp),%rdi
lea    0xe4e(%rip),%rsi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1050 <asprintf@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iso_time>:
push   %rbx
sub    $0x20,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x14(%rsp),%eax
mov    %eax,0xc(%rsp)
movslq 0x10(%rsp),%rax
imul   $0x10624dd3,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x26,%rbx
add    %eax,%ebx
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%r10d
mov    0x4(%rax),%r11d
mov    0x8(%rax),%r9d
mov    0xc(%rax),%r8d
mov    0x10(%rax),%rcx
mov    $0x76c,%edx
add    0x18(%rax),%rdx
add    $0x1,%rcx
sub    $0x8,%rsp
lea    0xe69(%rip),%rsi
lea    0x20(%rsp),%rdi
push   %rbx
push   %r10
push   %r11
call   1050 <asprintf@plt>
add    $0x20,%rsp
mov    0x18(%rsp),%rax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32, i32, i32, i32, i64, i64 }
@.str = [39 x i8] c"%4d-%02d-%02dT%02d:%02d:%02d.%03d+0200\00"
define i8* @iso_time() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.tm
%5 = alloca i8*
%6 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%8 = load i32, i32* %7
store i32 %8, i32* %2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%10 = load i32, i32* %9
%11 = sdiv i32 %10, 1000
store i32 %11, i32* %3
%12 = call %struct.tm* @localtime(i32* %2)
%13 = bitcast %struct.tm* %4 to i8*
%14 = bitcast %struct.tm* %12 to i8*
%15 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 5
%16 = load i64, i64* %15
%17 = add nsw i64 %16, 1900
%18 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 4
%19 = load i64, i64* %18
%20 = add nsw i64 %19, 1
%21 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 3
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i32, i32* %3
%30 = call i32 @asprintf(i8** %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %17, i64 %20, i32 %22, i32 %24, i32 %26, i32 %28, i32 %29)
%31 = load i8*, i8** %5
ret i8* %31
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32, i32, i32, i32, i64, i64 }
@.str = [39 x i8] c"%4d-%02d-%02dT%02d:%02d:%02d.%03d+0200\00"
define i8* @iso_time() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast %struct.timeval* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i8** %3 to i8*
%7 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%9 = load i32, i32* %8
store i32 %9, i32* %2
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = sdiv i32 %11, 1000
%13 = call %struct.tm* @localtime(i32* %2)
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 2
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 3
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 4
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %13, i64 0, i32 5
%25 = load i64, i64* %24
%26 = add nsw i64 %25, 1900
%27 = add nsw i64 %23, 1
%28 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i64 %26, i64 %27, i32 %21, i32 %19, i32 %17, i32 %15, i32 %12)
%29 = load i8*, i8** %3
ret i8* %29
}