#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 timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, long, long);
int /*<<< orphan*/ timeval_subtract(struct timeval *, struct timeval *,
                                    struct timeval *);
const char *nslog_gettime(void) {
  static struct timeval start_tv;
  static char buff[32];
  struct timeval tv;
  struct timeval now_tv;
  gettimeofday(&start_tv, NULL);
  gettimeofday(&now_tv, NULL);
  timeval_subtract(&tv, &now_tv, &start_tv);
  snprintf(buff, sizeof(buff), "(%ld.%06ld)", (long)tv.tv_sec,
           (long)tv.tv_usec);
  return buff;
}


x86 assembly (clang, -O0):
<nslog_gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0x2f11(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    0x2eec(%rip),%rdx
call   1050 <timeval_subtract@plt>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0x2ee8(%rip),%rdi
mov    $0x20,%esi
lea    0xe7c(%rip),%rdx
call   1030 <snprintf@plt>
lea    0x2ed0(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nslog_gettime>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0x2f12(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <timeval_subtract@plt>
mov    0x8(%rsp),%r8
mov    0x10(%rsp),%rcx
lea    0x2ee8(%rip),%rbx
lea    0xe81(%rip),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@nslog_gettime.start_tv = internal global %struct.timeval zeroinitializer
@nslog_gettime.buff = internal global [32 x i8] zeroinitializer
@.str = [12 x i8] c"(%ld.%06ld)\00"
define i8* @nslog_gettime() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = call i32 @gettimeofday(%struct.timeval* @nslog_gettime.start_tv, i32* null)
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = call i32 @timeval_subtract(%struct.timeval* %1, %struct.timeval* %2, %struct.timeval* @nslog_gettime.start_tv)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%7 = load i64, i64* %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%9 = load i64, i64* %8
%10 = call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @nslog_gettime.buff, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %7, i64 %9)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @nslog_gettime.buff, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@nslog_gettime.start_tv = internal global %struct.timeval zeroinitializer
@nslog_gettime.buff = internal global [32 x i8] zeroinitializer
@.str = [12 x i8] c"(%ld.%06ld)\00"
define i8* @nslog_gettime() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = tail call i32 @gettimeofday(%struct.timeval* @nslog_gettime.start_tv, i32* null)
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%7 = call i32 @timeval_subtract(%struct.timeval* %1, %struct.timeval* %2, %struct.timeval* @nslog_gettime.start_tv)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load i64, i64* %10
%12 = call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @nslog_gettime.buff, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %9, i64 %11)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @nslog_gettime.buff, i64 0, i64 0)
}