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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
char *gf_time() {
  struct timeval tv;
  static char str[30];
  char *ptr;
  if (gettimeofday(&tv, NULL) < 0) {
    perror("gettimeofday");
    exit(EXIT_FAILURE);
  }
  ptr = ctime(&tv.tv_sec);
  strcpy(str, &ptr[11]);
  snprintf(str + 8, sizeof(str) - 8, ".%06ld", tv.tv_usec);
  return str;
}


x86 assembly (clang, -O0):
<gf_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
cmp    $0x0,%rax
jge    1199 <gf_time+0x39>
lea    0xe7a(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1040 <ctime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
add    $0xb,%rsi
lea    0x2ea7(%rip),%rdi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%ecx
lea    0x2e98(%rip),%rdi
add    $0x8,%rdi
mov    $0x16,%esi
lea    0xe35(%rip),%rdx
call   1050 <snprintf@plt>
lea    0x2e7c(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gf_time>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %rax,%rax
js     11b8 <gf_time+0x58>
lea    0xc(%rsp),%rdi
call   1040 <ctime@plt>
lea    0xb(%rax),%rsi
lea    0x2ed5(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    0x8(%rsp),%ecx
lea    0x2eca(%rip),%rdi
lea    0xe68(%rip),%rdx
mov    $0x16,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe41(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@gf_time.str = internal global [30 x i8] zeroinitializer
@.str = [13 x i8] c"gettimeofday\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c".%06ld\00"
define i8* @gf_time() {
%1 = alloca %struct.timeval
%2 = alloca i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%11 = call i8* @ctime(i32* %10)
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i64 11
%14 = call i32 @strcpy(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @gf_time.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @gf_time.str, i64 0, i64 8), i32 22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %16)
ret i8* getelementptr inbounds ([30 x i8], [30 x i8]* @gf_time.str, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@gf_time.str = internal global [30 x i8] zeroinitializer
@.str = [13 x i8] c"gettimeofday\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c".%06ld\00"
define i8* @gf_time() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%11 = call i8* @ctime(i32* %10)
%12 = getelementptr inbounds i8, i8* %11, i64 11
%13 = call i32 @strcpy(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @gf_time.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @gf_time.str, i64 0, i64 8), i32 22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %15)
ret i8* getelementptr inbounds ([30 x i8], [30 x i8]* @gf_time.str, i64 0, i64 0)
}