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

/* Variables and functions */
struct tm *gmtime(int /*<<< orphan*/ *);
uint16_t fat_from_unix_date(time_t seconds) {
  struct tm *time_str;
  uint16_t fatdate;
  time_str = gmtime(&seconds);
  fatdate = 0;
  fatdate += (time_str->tm_year - 80) << 9;
  fatdate += (time_str->tm_mon + 1) << 5;
  fatdate += time_str->tm_mday;
  return fatdate;
}


x86 assembly (clang, -O0):
<fat_from_unix_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1030 <gmtime@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x50,%eax
shl    $0x9,%eax
cltq
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x1,%eax
shl    $0x5,%eax
cltq
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fat_from_unix_date>:
push   %rax
mov    %edi,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <gmtime@plt>
mov    (%rax),%ecx
mov    0x4(%rax),%edx
shl    $0x9,%ecx
add    $0xffff6000,%ecx
movslq %ecx,%rcx
shl    $0x5,%edx
add    $0x20,%edx
movslq %edx,%rdx
add    0x8(%rax),%rcx
add    %rdx,%rcx
mov    %rcx,%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i64 }
define i64 @fat_from_unix_date(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca i64
store i32 %0, i32* %2
%5 = call %struct.tm* @gmtime(i32* %2)
store %struct.tm* %5, %struct.tm** %3
store i64 0, i64* %4
%6 = load %struct.tm*, %struct.tm** %3
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = sub nsw i32 %8, 80
%10 = shl i32 %9, 9
%11 = sext i32 %10 to i64
%12 = load i64, i64* %4
%13 = add nsw i64 %12, %11
store i64 %13, i64* %4
%14 = load %struct.tm*, %struct.tm** %3
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
%18 = shl i32 %17, 5
%19 = sext i32 %18 to i64
%20 = load i64, i64* %4
%21 = add nsw i64 %20, %19
store i64 %21, i64* %4
%22 = load %struct.tm*, %struct.tm** %3
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 2
%24 = load i64, i64* %23
%25 = load i64, i64* %4
%26 = add nsw i64 %25, %24
store i64 %26, i64* %4
%27 = load i64, i64* %4
ret i64 %27
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i64 }
define i64 @fat_from_unix_date(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call %struct.tm* @gmtime(i32* %2)
%4 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%5 = load i32, i32* %4
%6 = shl i32 %5, 9
%7 = add i32 %6, -40960
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%10 = load i32, i32* %9
%11 = shl i32 %10, 5
%12 = add i32 %11, 32
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%15 = load i64, i64* %14
%16 = add i64 %15, %8
%17 = add i64 %16, %13
ret i64 %17
}