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

/* Variables and functions */
char *asctime(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *,
                           int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct timeval *, int /*<<< orphan*/, int);
int strlen(char *);
int print_timestamp(FILE *fp) {
  struct timeval tv;
  char *tstr;
  memset(&tv, 0, sizeof(tv));
  gettimeofday(&tv, NULL);
  tstr = asctime(localtime(&tv.tv_sec));
  tstr[strlen(tstr) - 1] = 0;
  fprintf(fp, "Timestamp: %s %lu usec\n", tstr, tv.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<print_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
lea    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1050 <asctime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xe2c(%rip),%rsi
call   1080 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_timestamp>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
call   1050 <asctime@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    (%rsp),%ecx
lea    0xe50(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1080 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [24 x i8] c"Timestamp: %s %lu usec\0A\00"
define i32 @print_timestamp(i32* %0) {
%2 = alloca i32*
%3 = alloca %struct.timeval
%4 = alloca i8*
store i32* %0, i32** %2
%5 = call i32 @memset(%struct.timeval* %3, i32 0, i32 8)
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%8 = call i32 @localtime(i32* %7)
%9 = call i8* @asctime(i32 %8)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
store i8 0, i8* %15
%16 = load i32*, i32** %2
%17 = load i8*, i8** %4
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %19)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [24 x i8] c"Timestamp: %s %lu usec\0A\00"
define i32 @print_timestamp(i32* nocapture %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @memset(%struct.timeval* %2, i32 0, i32 8)
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%7 = call i32 @localtime(i32* %6)
%8 = call i8* @asctime(i32 %7)
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
store i8 0, i8* %12
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %14)
ret i32 0
}