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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
char *gettimestamp(char *buffer) {
  struct timeval tv;
  struct tm *tm_info;
  char buf2[25];
  buffer = (char *)realloc(buffer, 25);
  gettimeofday(&tv, NULL);
  tm_info = localtime(&tv.tv_sec);
  strftime(buffer, 25, "%Y%m%d-%H:%M:%S", tm_info);
  sprintf(buf2, ".%03d", (int)tv.tv_usec / 1000);
  strcat(buffer, buf2);
  return (buffer);
}


x86 assembly (clang, -O0):
<gettimestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x19,%esi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x18(%rbp),%rdi
add    $0x8,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x19,%esi
lea    0xe50(%rip),%rdx
call   1060 <strftime@plt>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe42(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettimestamp>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    $0x19,%esi
call   1050 <realloc@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x8(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xe71(%rip),%rdx
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
movslq (%rsp),%rax
imul   $0x10624dd3,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x26,%rdx
add    %eax,%edx
lea    0xe52(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32 }
@.str = [16 x i8] c"%Y%m%d-%H:%M:%S\00"
@.str.1 = [6 x i8] c".%03d\00"
define i8* @gettimestamp(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.timeval
%4 = alloca %struct.tm*
%5 = alloca [25 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @realloc(i8* %6, i32 25)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %2
%9 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%11 = call %struct.tm* @localtime(i32* %10)
store %struct.tm* %11, %struct.tm** %4
%12 = load i8*, i8** %2
%13 = load %struct.tm*, %struct.tm** %4
%14 = call i32 @strftime(i8* %12, i32 25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %struct.tm* %13)
%15 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%17 = load i64, i64* %16
%18 = trunc i64 %17 to i32
%19 = sdiv i32 %18, 1000
%20 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i8*, i8** %2
%22 = getelementptr inbounds [25 x i8], [25 x i8]* %5, i64 0, i64 0
%23 = call i32 @strcat(i8* %21, i8* %22)
%24 = load i8*, i8** %2
ret i8* %24
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32 }
@.str = [16 x i8] c"%Y%m%d-%H:%M:%S\00"
@.str.1 = [6 x i8] c".%03d\00"
define i8* @gettimestamp(i8* %0) {
%2 = alloca %struct.timeval
%3 = alloca [25 x i8]
%4 = bitcast %struct.timeval* %2 to i8*
%5 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%6 = tail call i64 @realloc(i8* %0, i32 25)
%7 = inttoptr i64 %6 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%10 = call %struct.tm* @localtime(i32* %9)
%11 = call i32 @strftime(i8* %7, i32 25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = sdiv i32 %14, 1000
%16 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 @strcat(i8* %7, i8* %5)
ret i8* %7
}