#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 tm_hour;
  int tm_min;
  int tm_sec;
};
struct timeval {
  scalar_t__ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
char *timestamp(void) {
  struct timeval tv;
  static char time[50];
  struct tm *tmp;
  gettimeofday(&tv, 0);
  tmp = gmtime(&tv.tv_sec);
  sprintf(time, "%02d:%02d:%02d.%02d", tmp->tm_hour, tmp->tm_min, tmp->tm_sec,
          (int)tv.tv_usec / 10000);
  return time;
}


x86 assembly (clang, -O0):
<timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1040 <gmtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x10(%rbp),%rax
mov    $0x2710,%esi
cltd
idiv   %esi
mov    -0x1c(%rbp),%edx
mov    %eax,%r9d
lea    0x2ecb(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1050 <sprintf@plt>
lea    0x2eb8(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestamp>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0x8(%rsp),%rdi
call   1040 <gmtime@plt>
mov    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
movslq (%rsp),%rax
imul   $0x68db8bad,%rax,%r9
mov    %r9,%rax
shr    $0x3f,%rax
sar    $0x2c,%r9
add    %eax,%r9d
lea    0x2ede(%rip),%rbx
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32, i32, i32 }
@timestamp.time = internal global [50 x i8] zeroinitializer
@.str = [20 x i8] c"%02d:%02d:%02d.%02d\00"
define i8* @timestamp() {
%1 = alloca %struct.timeval
%2 = alloca %struct.tm*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%5 = call %struct.tm* @gmtime(i32* %4)
store %struct.tm* %5, %struct.tm** %2
%6 = load %struct.tm*, %struct.tm** %2
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = load %struct.tm*, %struct.tm** %2
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
%11 = load i32, i32* %10
%12 = load %struct.tm*, %struct.tm** %2
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 2
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = sdiv i32 %17, 10000
%19 = call i32 @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @timestamp.time, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11, i32 %14, i32 %18)
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @timestamp.time, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32, i32, i32 }
@timestamp.time = internal global [50 x i8] zeroinitializer
@.str = [20 x i8] c"%02d:%02d:%02d.%02d\00"
define i8* @timestamp() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%5 = call %struct.tm* @gmtime(i32* %4)
%6 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = sdiv i32 %14, 10000
%16 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @timestamp.time, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %9, i32 %11, i32 %15)
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @timestamp.time, i64 0, i64 0)
}