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

/* Variables and functions */
int /*<<< orphan*/ mktime(struct tm *);
time_t fat_to_unix_date(uint16_t date) {
  struct tm time_str;
  time_str.tm_year = (((date & 0xFE00) >> 9) + 80);
  time_str.tm_mon = (((date & 0x01E0) >> 5) - 1);
  time_str.tm_mday = (date & 0x001F);
  time_str.tm_hour = 0;
  time_str.tm_min = 0;
  time_str.tm_sec = 0;
  time_str.tm_isdst = -1;
  return mktime(&time_str);
}


x86 assembly (clang, -O0):
<fat_to_unix_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xfe00,%eax
sar    $0x9,%eax
add    $0x50,%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1e0,%eax
sar    $0x5,%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1f,%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <mktime@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fat_to_unix_date>:
sub    $0x28,%rsp
mov    %edi,%eax
shr    $0x9,%eax
and    $0x7f,%eax
add    $0x50,%eax
mov    %eax,(%rsp)
mov    %edi,%eax
shr    $0x5,%eax
and    $0xf,%eax
add    $0xffffffff,%eax
mov    %eax,0x4(%rsp)
and    $0x1f,%edi
mov    %edi,0x8(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
mov    %rsp,%rdi
call   1030 <mktime@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i64, i64, i64 }
define i32 @fat_to_unix_date(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.tm
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = and i32 %4, 65024
%6 = ashr i32 %5, 9
%7 = add nsw i32 %6, 80
%8 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 0
store i32 %7, i32* %8
%9 = load i32, i32* %2
%10 = and i32 %9, 480
%11 = ashr i32 %10, 5
%12 = sub nsw i32 %11, 1
%13 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* %2
%15 = and i32 %14, 31
%16 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 2
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 6
store i64 0, i64* %17
%18 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 5
store i64 0, i64* %18
%19 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 4
store i64 0, i64* %19
%20 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 3
store i32 -1, i32* %20
%21 = call i32 @mktime(%struct.tm* %3)
ret i32 %21
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i64, i64, i64 }
define i32 @fat_to_unix_date(i32 %0) {
%2 = alloca %struct.tm
%3 = bitcast %struct.tm* %2 to i8*
%4 = lshr i32 %0, 9
%5 = and i32 %4, 127
%6 = add nuw nsw i32 %5, 80
%7 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
store i32 %6, i32* %7
%8 = lshr i32 %0, 5
%9 = and i32 %8, 15
%10 = add nsw i32 %9, -1
%11 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
store i32 %10, i32* %11
%12 = and i32 %0, 31
%13 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 4
%15 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
%16 = bitcast i64* %14 to i8*
store i32 -1, i32* %15
%17 = call i32 @mktime(%struct.tm* %2)
ret i32 %17
}