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

/* Variables and functions */
int gettimeofday(struct timeval *, struct timezone *);
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
void gettimeofday_test() {
  int r;
  char *buf;
  struct tm *tp;
  struct timeval tv;
  struct timezone tz;
  r = gettimeofday(&tv, &tz);
  tp = localtime(&tv.tv_sec);
  buf = (char *)malloc(64);
  strftime(buf, 64, "%Y-%m-%d %H:%M:%S", tp);
  printf("gettimeofday() => %s.%ld(%ld.%ld)", buf, tv.tv_usec, tv.tv_sec,
         tv.tv_usec);
}


x86 assembly (clang, -O0):
<gettimeofday_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <gettimeofday@plt>
mov    %eax,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x40,%esi
lea    0xe65(%rip),%rdx
call   1070 <strftime@plt>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettimeofday_test>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <gettimeofday@plt>
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%r14
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe79(%rip),%rdx
mov    %rax,%rdi
mov    $0x40,%esi
mov    %r14,%rcx
call   1070 <strftime@plt>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xe6c(%rip),%rdi
mov    %rbx,%rsi
mov    %edx,%r8d
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [34 x i8] c"gettimeofday() => %s.%ld(%ld.%ld)\00"
define void @gettimeofday_test() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.tm*
%4 = alloca %struct.timeval
%5 = alloca %struct.timezone
%6 = call i32 @gettimeofday(%struct.timeval* %4, %struct.timezone* %5)
store i32 %6, i32* %1
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%8 = call %struct.tm* @localtime(i32* %7)
store %struct.tm* %8, %struct.tm** %3
%9 = call i64 @malloc(i32 64)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = load %struct.tm*, %struct.tm** %3
%13 = call i32 @strftime(i8* %11, i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %12)
%14 = load i8*, i8** %2
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %16, i32 %18, i32 %20)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
@.str.1 = [34 x i8] c"gettimeofday() => %s.%ld(%ld.%ld)\00"
define void @gettimeofday_test() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timezone
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timezone* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %1, %struct.timezone* %2)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%7 = call %struct.tm* @localtime(i32* %6)
%8 = call i64 @malloc(i32 64)
%9 = inttoptr i64 %8 to i8*
%10 = call i32 @strftime(i8* %9, i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %7)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* %6
%14 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %12, i32 %13, i32 %12)
ret void
}