#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;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char **, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int genDate(unsigned char *dateData) {
  unsigned char year;
  unsigned char month;
  unsigned char day;
  time_t currTime = time(NULL);
  struct tm *localTime;
  localTime = localtime(&currTime);
  year = ((localTime->tm_year + 1900) & 0xff) + 0x30;
  month = localTime->tm_mon + 1;
  day = (localTime->tm_mday / 7) * 7;
  unsigned char combined[] = {year, month, day};
  memcpy(dateData, &combined, 4);
  return 1;
}


x86 assembly (clang, -O0):
<genDate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0x76c,%eax
and    $0xff,%eax
add    $0x30,%eax
mov    %al,-0x9(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x1,%eax
mov    %al,-0xa(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
imul   $0x7,%eax,%eax
mov    %al,-0xb(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x1b(%rbp)
mov    -0xa(%rbp),%al
mov    %al,-0x1a(%rbp)
mov    -0xb(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genDate>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%cl
mov    0x4(%rax),%dl
add    $0x9c,%cl
add    $0x1,%dl
movslq 0x8(%rax),%rax
imul   $0xffffffff92492493,%rax,%rsi
shr    $0x20,%rsi
add    %eax,%esi
mov    %esi,%eax
shr    $0x1f,%eax
shr    $0x2,%esi
add    %eax,%esi
lea    0x0(,%rsi,8),%eax
sub    %esi,%eax
mov    %cl,0x9(%rsp)
mov    %dl,0xa(%rsp)
mov    %al,0xb(%rsp)
lea    0x9(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
define i32 @genDate(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i32
%7 = alloca %struct.tm*
%8 = alloca [3 x i8]
store i8* %0, i8** %2
%9 = call i32 @time(i32* null)
store i32 %9, i32* %6
%10 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %10, %struct.tm** %7
%11 = load %struct.tm*, %struct.tm** %7
%12 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1900
%15 = and i32 %14, 255
%16 = add nsw i32 %15, 48
%17 = trunc i32 %16 to i8
store i8 %17, i8* %3
%18 = load %struct.tm*, %struct.tm** %7
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
%22 = trunc i32 %21 to i8
store i8 %22, i8* %4
%23 = load %struct.tm*, %struct.tm** %7
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 2
%25 = load i32, i32* %24
%26 = sdiv i32 %25, 7
%27 = mul nsw i32 %26, 7
%28 = trunc i32 %27 to i8
store i8 %28, i8* %5
%29 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%30 = load i8, i8* %3
store i8 %30, i8* %29
%31 = getelementptr inbounds i8, i8* %29, i64 1
%32 = load i8, i8* %4
store i8 %32, i8* %31
%33 = getelementptr inbounds i8, i8* %31, i64 1
%34 = load i8, i8* %5
store i8 %34, i8* %33
%35 = load i8*, i8** %2
%36 = bitcast [3 x i8]* %8 to i8**
%37 = call i32 @memcpy(i8* %35, i8** %36, i32 4)
ret i32 1
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
define i32 @genDate(i8* %0) {
%2 = alloca i32
%3 = alloca [3 x i8]
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %2
%6 = call %struct.tm* @localtime(i32* %2)
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%8 = load i32, i32* %7
%9 = trunc i32 %8 to i8
%10 = add i8 %9, -100
%11 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 1
%12 = load i32, i32* %11
%13 = trunc i32 %12 to i8
%14 = add i8 %13, 1
%15 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 2
%16 = load i32, i32* %15
%17 = srem i32 %16, 7
%18 = sub i32 %16, %17
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
store i8 %10, i8* %20
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
store i8 %14, i8* %21
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 %19, i8* %22
%23 = bitcast [3 x i8]* %3 to i8**
%24 = call i32 @memcpy(i8* %0, i8** %23, i32 4)
ret i32 1
}