#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 tm_year;
  int tm_mon;
  int /*<<< orphan*/ tm_mday;
};

/* Variables and functions */
struct tm *localtime(long *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int /*<<< orphan*/);
const char *FormatADate(long timestamp) {
  struct tm *ts;
  static char str[9];
  ts = localtime(&timestamp);
  sprintf(str, "%4d%02d%02d", ts->tm_year + 1900, ts->tm_mon + 1, ts->tm_mday);
  return str;
}


x86 assembly (clang, -O0):
<FormatADate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
add    $0x76c,%edx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8d
lea    0x2ed3(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1040 <sprintf@plt>
lea    0x2ec0(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FormatADate>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <localtime@plt>
mov    $0x76c,%edx
add    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
add    $0x1,%ecx
lea    0x2ee5(%rip),%rbx
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@FormatADate.str = internal global [9 x i8] zeroinitializer
@.str = [12 x i8] c"%4d%02d%02d\00"
define i8* @FormatADate(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.tm*
store i64 %0, i64* %2
%4 = call %struct.tm* @localtime(i64* %2)
store %struct.tm* %4, %struct.tm** %3
%5 = load %struct.tm*, %struct.tm** %3
%6 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = add nsw i32 %7, 1900
%9 = load %struct.tm*, %struct.tm** %3
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
%13 = load %struct.tm*, %struct.tm** %3
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 2
%15 = load i32, i32* %14
%16 = call i32 @sprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @FormatADate.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %12, i32 %15)
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @FormatADate.str, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@FormatADate.str = internal global [9 x i8] zeroinitializer
@.str = [12 x i8] c"%4d%02d%02d\00"
define i8* @FormatADate(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = call %struct.tm* @localtime(i64* %2)
%4 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%5 = load i32, i32* %4
%6 = add nsw i32 %5, 1900
%7 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%8 = load i32, i32* %7
%9 = add nsw i32 %8, 1
%10 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%11 = load i32, i32* %10
%12 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @FormatADate.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9, i32 %11)
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @FormatADate.str, i64 0, i64 0)
}