#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*/ timerisset(struct timeval *);
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;
  if (!timerisset(&start_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    0x2f01(%rip),%rdi
call   1060 <timerisset@plt>
cmp    $0x0,%eax
jne    116d <nslog_gettime+0x2d>
lea    0x2eec(%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    0x2ec7(%rip),%rdx
call   1050 <timeval_subtract@plt>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0x2ec3(%rip),%rdi
mov    $0x20,%esi
lea    0xe57(%rip),%rdx
call   1030 <snprintf@plt>
lea    0x2eab(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nslog_gettime>:
push   %rbx
sub    $0x20,%rsp
lea    0x2f04(%rip),%rdi
call   1060 <timerisset@plt>
test   %eax,%eax
jne    1163 <nslog_gettime+0x23>
lea    0x2ef4(%rip),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x2ed7(%rip),%rdx
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <timeval_subtract@plt>
mov    (%rsp),%r8
mov    0x8(%rsp),%rcx
lea    0x2ecc(%rip),%rbx
lea    0xe65(%rip),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
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 @timerisset(%struct.timeval* @nslog_gettime.start_tv)
%4 = icmp ne i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @gettimeofday(%struct.timeval* @nslog_gettime.start_tv, i32* null)
br label %7
7: ; preds = %5, %0
%8 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%9 = call i32 @timeval_subtract(%struct.timeval* %1, %struct.timeval* %2, %struct.timeval* @nslog_gettime.start_tv)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%13 = load i64, i64* %12
%14 = 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 %11, i64 %13)
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 @timerisset(%struct.timeval* @nslog_gettime.start_tv)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @gettimeofday(%struct.timeval* @nslog_gettime.start_tv, i32* null)
br label %9
9: ; preds = %7, %0
%10 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%11 = call i32 @timeval_subtract(%struct.timeval* %1, %struct.timeval* %2, %struct.timeval* @nslog_gettime.start_tv)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%15 = load i64, i64* %14
%16 = 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 %13, i64 %15)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @nslog_gettime.buff, i64 0, i64 0)
}