#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 timeb {
  int /*<<< orphan*/ millitm;
  scalar_t__ time;
};

/* Variables and functions */
double atof(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ ftime(struct timeb *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
double current_time_millis() {
  char *buffer = malloc(sizeof(char));
  struct timeb t;
  double time;
  ftime(&t);
  sprintf(buffer, "%ld.", (long)t.time);
  sprintf(buffer, "%s%d", buffer, t.millitm);
  time = atof(buffer);
  free(buffer);
  return time;
}


x86 assembly (clang, -O0):
<current_time_millis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <ftime@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<current_time_millis>:
push   %rbx
sub    $0x20,%rsp
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
call   1070 <ftime@plt>
mov    0x18(%rsp),%rdx
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    0x10(%rsp),%ecx
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <atof@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeb = type { i32, i64 }
@.str = [5 x i8] c"%ld.\00"
@.str.1 = [5 x i8] c"%s%d\00"
define double @current_time_millis() {
%1 = alloca i8*
%2 = alloca %struct.timeb
%3 = alloca double
%4 = call i8* @malloc(i32 1)
store i8* %4, i8** %1
%5 = call i32 @ftime(%struct.timeb* %2)
%6 = load i8*, i8** %1
%7 = getelementptr inbounds %struct.timeb, %struct.timeb* %2, i32 0, i32 1
%8 = load i64, i64* %7
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %8)
%10 = load i8*, i8** %1
%11 = load i8*, i8** %1
%12 = getelementptr inbounds %struct.timeb, %struct.timeb* %2, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %13)
%15 = load i8*, i8** %1
%16 = call double @atof(i8* %15)
store double %16, double* %3
%17 = load i8*, i8** %1
%18 = call i32 @free(i8* %17)
%19 = load double, double* %3
ret double %19
}

LLVM IR (-O2):
%struct.timeb = type { i32, i64 }
@.str = [5 x i8] c"%ld.\00"
@.str.1 = [5 x i8] c"%s%d\00"
define double @current_time_millis() {
%1 = alloca %struct.timeb
%2 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%3 = bitcast %struct.timeb* %1 to i8*
%4 = call i32 @ftime(%struct.timeb* %1)
%5 = getelementptr inbounds %struct.timeb, %struct.timeb* %1, i64 0, i32 1
%6 = load i64, i64* %5
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %6)
%8 = getelementptr inbounds %struct.timeb, %struct.timeb* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %9)
%11 = call double @atof(i8* %2)
%12 = call i32 @free(i8* %2)
ret double %11
}