#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 time_t;
struct tm {
  int dummy;
};
struct timeb {
  int /*<<< orphan*/ millitm;
};

/* Variables and functions */
int /*<<< orphan*/ error_show(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ ftime(struct timeb *);
struct tm *localtime(int *);
char *realloc(char *, scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
char *string_duplicate(char *);
scalar_t__ strlen(char *);
int time(int /*<<< orphan*/ *);
char *temporal_get_string_time() {
  time_t log_time;
  struct tm *log_tm;
  struct timeb tmili;
  char *str_time = string_duplicate("hh:mm:ss:mmmm");
  if ((log_time = time(NULL)) == -1) {
    error_show("Error getting date!");
    return 0;
  }
  log_tm = localtime(&log_time);
  if (ftime(&tmili)) {
    error_show("Error getting time!");
    return 0;
  }
  char *partial_time = string_duplicate("hh:mm:ss");
  strftime(partial_time, 127, "%H:%M:%S", log_tm);
  sprintf(str_time, "%s:%hu", partial_time, tmili.millitm);
  free(partial_time);
  str_time = realloc(str_time, strlen(str_time) + 1);
  return str_time;
}


x86 assembly (clang, -O0):
<temporal_get_string_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe51(%rip),%rdi
call   1070 <string_duplicate@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    11e6 <temporal_get_string_time+0x46>
lea    0xe3a(%rip),%rdi
call   1030 <error_show@plt>
movq   $0x0,-0x8(%rbp)
jmp    1295 <temporal_get_string_time+0xf5>
lea    -0xc(%rbp),%rdi
call   1050 <localtime@plt>
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   10c0 <ftime@plt>
cmp    $0x0,%rax
je     121f <temporal_get_string_time+0x7f>
lea    0xe15(%rip),%rdi
call   1030 <error_show@plt>
movq   $0x0,-0x8(%rbp)
jmp    1295 <temporal_get_string_time+0xf5>
lea    0xe10(%rip),%rdi
call   1070 <string_duplicate@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x7f,%esi
lea    0xdfc(%rip),%rdx
call   10a0 <strftime@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%ecx
lea    0xdee(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1090 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<temporal_get_string_time>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe50(%rip),%rdi
call   1070 <string_duplicate@plt>
mov    %rax,%r15
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     11ed <temporal_get_string_time+0x4d>
lea    0xc(%rsp),%rdi
call   1050 <localtime@plt>
mov    %rax,%r14
lea    0x8(%rsp),%rdi
call   10c0 <ftime@plt>
test   %rax,%rax
je     11fd <temporal_get_string_time+0x5d>
lea    0xe37(%rip),%rdi
jmp    11f4 <temporal_get_string_time+0x54>
lea    0xe1a(%rip),%rdi
call   1030 <error_show@plt>
xor    %eax,%eax
jmp    1255 <temporal_get_string_time+0xb5>
lea    0xe32(%rip),%rdi
call   1070 <string_duplicate@plt>
mov    %rax,%rbx
lea    0xe2c(%rip),%rdx
mov    %rax,%rdi
mov    $0x7f,%esi
mov    %r14,%rcx
call   10a0 <strftime@plt>
mov    0x8(%rsp),%ecx
lea    0xe1a(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r15,%rdi
call   1090 <realloc@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.timeb = type { i32 }
@.str = [14 x i8] c"hh:mm:ss:mmmm\00"
@.str.1 = [20 x i8] c"Error getting date!\00"
@.str.2 = [20 x i8] c"Error getting time!\00"
@.str.3 = [9 x i8] c"hh:mm:ss\00"
@.str.4 = [9 x i8] c"%H:%M:%S\00"
@.str.5 = [7 x i8] c"%s:%hu\00"
define i8* @temporal_get_string_time() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca %struct.timeb
%5 = alloca i8*
%6 = alloca i8*
%7 = call i8* @string_duplicate(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %5
%8 = call i32 @time(i32* null)
store i32 %8, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @error_show(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %1
br label %36
12: ; preds = %0
%13 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %13, %struct.tm** %3
%14 = call i64 @ftime(%struct.timeb* %4)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @error_show(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %1
br label %36
18: ; preds = %12
%19 = call i8* @string_duplicate(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = load %struct.tm*, %struct.tm** %3
%22 = call i32 @strftime(i8* %20, i32 127, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %struct.tm* %21)
%23 = load i8*, i8** %5
%24 = load i8*, i8** %6
%25 = getelementptr inbounds %struct.timeb, %struct.timeb* %4, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %24, i32 %26)
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
%30 = load i8*, i8** %5
%31 = load i8*, i8** %5
%32 = call i64 @strlen(i8* %31)
%33 = add nsw i64 %32, 1
%34 = call i8* @realloc(i8* %30, i64 %33)
store i8* %34, i8** %5
%35 = load i8*, i8** %5
store i8* %35, i8** %1
br label %36
36: ; preds = %18, %16, %10
%37 = load i8*, i8** %1
ret i8* %37
}

LLVM IR (-O2):
%struct.timeb = type { i32 }
%struct.tm = type { i32 }
@.str = [14 x i8] c"hh:mm:ss:mmmm\00"
@.str.1 = [20 x i8] c"Error getting date!\00"
@.str.2 = [20 x i8] c"Error getting time!\00"
@.str.3 = [9 x i8] c"hh:mm:ss\00"
@.str.4 = [9 x i8] c"%H:%M:%S\00"
@.str.5 = [7 x i8] c"%s:%hu\00"
define noalias i8* @temporal_get_string_time() {
%1 = alloca i32
%2 = alloca %struct.timeb
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.timeb* %2 to i8*
%5 = tail call i8* @string_duplicate(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %1
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @error_show(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %26
10: ; preds = %0
%11 = call %struct.tm* @localtime(i32* %1)
%12 = call i64 @ftime(%struct.timeb* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 @error_show(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %26
16: ; preds = %10
%17 = call i8* @string_duplicate(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @strftime(i8* %17, i32 127, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %struct.tm* %11)
%19 = getelementptr inbounds %struct.timeb, %struct.timeb* %2, i64 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %17, i32 %20)
%22 = call i32 @free(i8* %17)
%23 = call i64 @strlen(i8* dereferenceable(1) %5)
%24 = add nsw i64 %23, 1
%25 = call i8* @realloc(i8* %5, i64 %24)
br label %26
26: ; preds = %16, %14, %8
%27 = phi i8* [ null, %8 ], [ null, %14 ], [ %25, %16 ]
ret i8* %27
}