#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*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
};
struct timeval {
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, int, int, int);
char *time_today_string(char *date_str, size_t date_size) {
  struct tm tm_now;
  struct timeval tv;
  gettimeofday(&tv, NULL);
  time_t now = tv.tv_sec;
  localtime_r(&now, &tm_now);
  snprintf(date_str, date_size, "%04d-%02d-%02d", tm_now.tm_year + 1900,
           tm_now.tm_mon + 1, tm_now.tm_mday);
  return date_str;
}


x86 assembly (clang, -O0):
<time_today_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x2c(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x1c(%rbp),%r8d
add    $0x1,%r8d
mov    -0x18(%rbp),%r9d
lea    0xe7c(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_today_string>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    (%rsp),%eax
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
mov    $0x76c,%ecx
add    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x10(%rsp),%r9d
add    $0x1,%r8d
lea    0xe85(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
%struct.timeval = type { i32 }
@.str = [15 x i8] c"%04d-%02d-%02d\00"
define i8* @time_today_string(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.tm
%6 = alloca %struct.timeval
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%10 = load i32, i32* %9
store i32 %10, i32* %7
%11 = call i32 @localtime_r(i32* %7, %struct.tm* %5)
%12 = load i8*, i8** %3
%13 = load i64, i64* %4
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1900
%17 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
%20 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
%21 = load i32, i32* %20
%22 = call i32 @snprintf(i8* %12, i64 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %19, i32 %21)
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
%struct.timeval = type { i32 }
@.str = [15 x i8] c"%04d-%02d-%02d\00"
define i8* @time_today_string(i8* returned %0, i64 %1) {
%3 = alloca %struct.tm
%4 = alloca %struct.timeval
%5 = alloca i32
%6 = bitcast %struct.tm* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%11 = load i32, i32* %10
store i32 %11, i32* %5
%12 = call i32 @localtime_r(i32* %5, %struct.tm* %3)
%13 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1900
%16 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%17 = load i32, i32* %16
%18 = add nsw i32 %17, 1
%19 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%20 = load i32, i32* %19
%21 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %18, i32 %20)
ret i8* %0
}