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

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int strftime(char *, int, char *, struct tm *);
const char *timeofday(void) {
  static char str[100];
  struct timeval tod;
  if (gettimeofday(&tod, NULL)) {
    str[0] = '\0';
  } else {
    struct tm *tm = localtime(&tod.tv_sec);
    char *p = str + strftime(str, 50, "%H:%M:%S.", tm);
    sprintf(p, "%06ld", tod.tv_usec);
  }
  return str;
}


x86 assembly (clang, -O0):
<timeofday>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
je     116b <timeofday+0x2b>
movb   $0x0,0x2eea(%rip)
jmp    11bc <timeofday+0x7c>
lea    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
lea    0x2ec9(%rip),%rdi
mov    $0x32,%esi
lea    0xe6d(%rip),%rdx
call   1050 <strftime@plt>
movslq %eax,%rcx
lea    0x2eae(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe53(%rip),%rsi
call   1060 <sprintf@plt>
lea    0x2e8d(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeofday>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
je     115f <timeofday+0x1f>
movb   $0x0,0x2ef3(%rip)
jmp    119d <timeofday+0x5d>
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0x2ee0(%rip),%rbx
lea    0xe89(%rip),%rdx
mov    %rbx,%rdi
mov    $0x32,%esi
mov    %rax,%rcx
call   1050 <strftime@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    0x8(%rsp),%edx
lea    0xe72(%rip),%rsi
call   1060 <sprintf@plt>
lea    0x2eac(%rip),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@timeofday.str = internal global [100 x i8] zeroinitializer
@.str = [10 x i8] c"%H:%M:%S.\00"
@.str.1 = [6 x i8] c"%06ld\00"
define i8* @timeofday() {
%1 = alloca %struct.timeval
%2 = alloca %struct.tm*
%3 = alloca i8*
%4 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i8 0, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timeofday.str, i64 0, i64 0)
br label %18
7: ; preds = %0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%9 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %9, %struct.tm** %2
%10 = load %struct.tm*, %struct.tm** %2
%11 = call i32 @strftime(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timeofday.str, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timeofday.str, i64 0, i64 0), i64 %12
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %7, %6
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timeofday.str, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@timeofday.str = internal global [100 x i8] zeroinitializer
@.str = [10 x i8] c"%H:%M:%S.\00"
@.str.1 = [6 x i8] c"%06ld\00"
define i8* @timeofday() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp eq i64 %3, 0
br i1 %4, label %6, label %5
5: ; preds = %0
store i8 0, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timeofday.str, i64 0, i64 0)
br label %15
6: ; preds = %0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%8 = call %struct.tm* @localtime(i32* %7)
%9 = call i32 @strftime(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timeofday.str, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.tm* %8)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* @timeofday.str, i64 0, i64 %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %6, %5
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timeofday.str, i64 0, i64 0)
}