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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ set_msec(char *, int);
size_t strftime(char *, int /*<<< orphan*/, char *, struct tm *);
int /*<<< orphan*/ strlen(char *);
void set_timestamp(char *timestamp) {
  struct tm tm;
  struct tm *tmp;
  struct timeval tv;
  struct timezone tz;
  gettimeofday(&tv, &tz);
  localtime_r(&tv.tv_sec, &tm);
  tmp = &tm;
  size_t size = strftime(timestamp, strlen(timestamp),
                         "%Y-%m-%dT%H:%M:%S.000"
                         "%z",
                         tmp);
  set_msec(timestamp, tv.tv_usec / 1000);
}


x86 assembly (clang, -O0):
<set_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <gettimeofday@plt>
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
lea    -0x10(%rbp),%rsi
call   1030 <localtime_r@plt>
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
lea    0xe5c(%rip),%rdx
call   1060 <strftime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
call   1070 <set_msec@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_timestamp>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1050 <gettimeofday@plt>
lea    0x4(%rsp),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1030 <localtime_r@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe78(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rcx
call   1060 <strftime@plt>
movslq (%rsp),%rax
imul   $0x10624dd3,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x26,%rsi
add    %eax,%esi
mov    %rbx,%rdi
call   1070 <set_msec@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
@.str = [24 x i8] c"%Y-%m-%dT%H:%M:%S.000%z\00"
define void @set_timestamp(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tm
%4 = alloca %struct.tm*
%5 = alloca %struct.timeval
%6 = alloca %struct.timezone
%7 = alloca i64
store i8* %0, i8** %2
%8 = call i32 @gettimeofday(%struct.timeval* %5, %struct.timezone* %6)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%10 = call i32 @localtime_r(i32* %9, %struct.tm* %3)
store %struct.tm* %3, %struct.tm** %4
%11 = load i8*, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
%14 = load %struct.tm*, %struct.tm** %4
%15 = call i64 @strftime(i8* %11, i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %struct.tm* %14)
store i64 %15, i64* %7
%16 = load i8*, i8** %2
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%18 = load i32, i32* %17
%19 = sdiv i32 %18, 1000
%20 = call i32 @set_msec(i8* %16, i32 %19)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
@.str = [24 x i8] c"%Y-%m-%dT%H:%M:%S.000%z\00"
define void @set_timestamp(i8* %0) {
%2 = alloca %struct.tm
%3 = alloca %struct.timeval
%4 = alloca %struct.timezone
%5 = bitcast %struct.tm* %2 to i8*
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timezone* %4 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* %4)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%10 = call i32 @localtime_r(i32* %9, %struct.tm* %2)
%11 = call i32 @strlen(i8* %0)
%12 = call i64 @strftime(i8* %0, i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %struct.tm* %2)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 1000
%16 = call i32 @set_msec(i8* %0, i32 %15)
ret void
}