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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, long);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
char *getTimeStr() {
  struct timeval tv;
  struct tm *ptm;
  long milliseconds;
  char *time_string = (char *)malloc(sizeof(char) * 15);
  char *ms = (char *)malloc(sizeof(char) * 5);
  gettimeofday(&tv, NULL);
  ptm = localtime(&tv.tv_sec);
  strftime(time_string, 15, "%H:%M:%S", ptm);
  milliseconds = tv.tv_usec / 1000;
  snprintf(ms, 5, ".%03ld\n", milliseconds);
  strcat(time_string, ms);
  free(ms);
  return time_string;
}


x86 assembly (clang, -O0):
<getTimeStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0xf,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x5,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
lea    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1040 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xf,%esi
lea    0xe3a(%rip),%rdx
call   1080 <strftime@plt>
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x5,%esi
lea    0xe19(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTimeStr>:
push   %r14
push   %rbx
push   %rax
mov    $0xf,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x5,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
lea    0x4(%rsp),%rdi
call   1040 <localtime@plt>
lea    0xe57(%rip),%rdx
mov    %r14,%rdi
mov    $0xf,%esi
mov    %rax,%rcx
call   1080 <strftime@plt>
movslq (%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
movslq %eax,%rcx
lea    0xe2e(%rip),%rdx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1050 <snprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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