#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_hour;
  int tm_min;
  int tm_sec;
  int tm_isdst;
  scalar_t__ tm_mday;
  scalar_t__ tm_mon;
  scalar_t__ tm_year;
};

/* Variables and functions */
int /*<<< orphan*/ mktime(struct tm *);
time_t fat_to_unix_time(uint16_t time) {
  struct tm time_str;
  time_str.tm_year = 0;
  time_str.tm_mon = 0;
  time_str.tm_mday = 0;
  time_str.tm_hour = ((time & 0xF800) >> 11);
  time_str.tm_min = ((time & 0x03E0) >> 5);
  time_str.tm_sec = (time & 0x001F) << 1;
  time_str.tm_isdst = -1;
  return mktime(&time_str);
}


x86 assembly (clang, -O0):
<fat_to_unix_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf800,%eax
sar    $0xb,%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
and    $0x3e0,%eax
sar    $0x5,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1f,%eax
shl    $0x1,%eax
mov    %eax,-0x28(%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_time>:
sub    $0x28,%rsp
mov    %edi,%eax
shr    $0xb,%eax
and    $0x1f,%eax
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
mov    %eax,(%rsp)
mov    %edi,%eax
shr    $0x5,%eax
and    $0x1f,%eax
mov    %eax,0x4(%rsp)
add    %edi,%edi
and    $0x3e,%edi
mov    %edi,0x8(%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_time(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.tm
store i32 %0, i32* %2
%4 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 6
store i64 0, i64* %4
%5 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 5
store i64 0, i64* %5
%6 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 4
store i64 0, i64* %6
%7 = load i32, i32* %2
%8 = and i32 %7, 63488
%9 = ashr i32 %8, 11
%10 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* %2
%12 = and i32 %11, 992
%13 = ashr i32 %12, 5
%14 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* %2
%16 = and i32 %15, 31
%17 = shl i32 %16, 1
%18 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 2
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 3
store i32 -1, i32* %19
%20 = call i32 @mktime(%struct.tm* %3)
ret i32 %20
}

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