#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 */

/* Variables and functions */
double current_time();
int /*<<< orphan*/ sprintf(char *, char *, double);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int strlen(char *);
char *timestamp(void) {
  static char ts[16], *cp;
  sprintf(ts, "%.4g", current_time());
  cp = strchr(ts, '.');
  if (!cp)
    strcat(ts, ".0000");
  else if (strlen(cp) > 5)
    cp[5] = '\0';
  else
    while (strlen(cp) < 5)
      strcat(cp, "0");
  return ts;
}


x86 assembly (clang, -O0):
<timestamp>:
push   %rbp
mov    %rsp,%rbp
mov    $0x0,%al
call   1050 <current_time@plt>
lea    0x2efe(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <sprintf@plt>
lea    0x2eeb(%rip),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,0x2eea(%rip)
cmpq   $0x0,0x2ee2(%rip)
jne    11ac <timestamp+0x5c>
lea    0x2ec5(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1060 <strcat@plt>
jmp    120d <timestamp+0xbd>
mov    0x2ebd(%rip),%rdi
call   1030 <strlen@plt>
cmp    $0x5,%eax
jle    11d1 <timestamp+0x81>
mov    0x2ea8(%rip),%rax
movb   $0x0,0x5(%rax)
jmp    1208 <timestamp+0xb8>
jmp    11d6 <timestamp+0x86>
mov    0x2e93(%rip),%rdi
call   1030 <strlen@plt>
cmp    $0x5,%eax
jge    1203 <timestamp+0xb3>
mov    0x2e7e(%rip),%rdi
lea    0xe10(%rip),%rsi
call   1060 <strcat@plt>
jmp    11d6 <timestamp+0x86>
jmp    1208 <timestamp+0xb8>
jmp    120d <timestamp+0xbd>
lea    0x2e4c(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestamp>:
push   %rbx
xor    %eax,%eax
call   1050 <current_time@plt>
lea    0x2f01(%rip),%rbx
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,0x2eee(%rip)
test   %rax,%rax
je     11a1 <timestamp+0x51>
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    0x2eda(%rip),%rdi
cmp    $0x5,%eax
jle    11b6 <timestamp+0x66>
movb   $0x0,0x5(%rdi)
jmp    11f0 <timestamp+0xa0>
lea    0x2eb8(%rip),%rdi
lea    0xe56(%rip),%rsi
call   1060 <strcat@plt>
jmp    11f0 <timestamp+0xa0>
call   1030 <strlen@plt>
cmp    $0x4,%eax
jg     11f0 <timestamp+0xa0>
lea    0xe42(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    0x2e99(%rip),%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
mov    0x2e8a(%rip),%rdi
call   1030 <strlen@plt>
cmp    $0x5,%eax
jl     11d0 <timestamp+0x80>
lea    0x2e69(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@timestamp.ts = internal global [16 x i8] zeroinitializer
@timestamp.cp = internal global i8* null
@.str = [5 x i8] c"%.4g\00"
@.str.1 = [6 x i8] c".0000\00"
@.str.2 = [2 x i8] c"0\00"
define i8* @timestamp() {
%1 = call double (...) @current_time()
%2 = call i32 @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @timestamp.ts, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %1)
%3 = call i8* @strchr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @timestamp.ts, i64 0, i64 0), i8 signext 46)
store i8* %3, i8** @timestamp.cp
%4 = load i8*, i8** @timestamp.cp
%5 = icmp ne i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @strcat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @timestamp.ts, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %25
8: ; preds = %0
%9 = load i8*, i8** @timestamp.cp
%10 = call i32 @strlen(i8* %9)
%11 = icmp sgt i32 %10, 5
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i8*, i8** @timestamp.cp
%14 = getelementptr inbounds i8, i8* %13, i64 5
store i8 0, i8* %14
br label %24
15: ; preds = %8
br label %16
16: ; preds = %20, %15
%17 = load i8*, i8** @timestamp.cp
%18 = call i32 @strlen(i8* %17)
%19 = icmp slt i32 %18, 5
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8*, i8** @timestamp.cp
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %16
23: ; preds = %16
br label %24
24: ; preds = %23, %12
br label %25
25: ; preds = %24, %6
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @timestamp.ts, i64 0, i64 0)
}

LLVM IR (-O2):
@timestamp.ts = internal global [16 x i8] zeroinitializer
@timestamp.cp = internal unnamed_addr global i8* null
@.str = [5 x i8] c"%.4g\00"
@.str.1 = [6 x i8] c".0000\00"
@.str.2 = [2 x i8] c"0\00"
define i8* @timestamp() {
%1 = tail call double (...) @current_time()
%2 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @timestamp.ts, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %1)
%3 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @timestamp.ts, i64 0, i64 0), i8 signext 46)
store i8* %3, i8** @timestamp.cp
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @strcat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @timestamp.ts, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %22
7: ; preds = %0
%8 = tail call i32 @strlen(i8* %3)
%9 = icmp sgt i32 %8, 5
%10 = load i8*, i8** @timestamp.cp
br i1 %9, label %14, label %11
11: ; preds = %7
%12 = tail call i32 @strlen(i8* %10)
%13 = icmp slt i32 %12, 5
br i1 %13, label %16, label %22
14: ; preds = %7
%15 = getelementptr inbounds i8, i8* %10, i64 5
store i8 0, i8* %15
br label %22
16: ; preds = %11, %16
%17 = load i8*, i8** @timestamp.cp
%18 = tail call i32 @strcat(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** @timestamp.cp
%20 = tail call i32 @strlen(i8* %19)
%21 = icmp slt i32 %20, 5
br i1 %21, label %16, label %22
22: ; preds = %16, %11, %14, %5
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @timestamp.ts, i64 0, i64 0)
}