#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__ time_t;
struct tm {
  int tm_isdst;
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
struct tm *localtime(scalar_t__ *);
scalar_t__ mktime(struct tm *);
scalar_t__ time(int /*<<< orphan*/ *);
time_t dos_to_unix_time(unsigned long dosdatetime) {
  time_t m_time;
  struct tm *tm;
  time_t now = time(NULL);
  tm = localtime(&now);
  tm->tm_isdst = -1;
  tm->tm_year = ((int)(dosdatetime >> 25) & 0x7f) + (1980 - 1900);
  tm->tm_mon = ((int)(dosdatetime >> 21) & 0x0f) - 1;
  tm->tm_mday = ((int)(dosdatetime >> 16) & 0x1f);
  tm->tm_hour = (int)((unsigned)dosdatetime >> 11) & 0x1f;
  tm->tm_min = (int)((unsigned)dosdatetime >> 5) & 0x3f;
  tm->tm_sec = (int)((unsigned)dosdatetime << 1) & 0x3e;
  m_time = mktime(tm);
  if ((dosdatetime >= ((unsigned long)0x74320000L)) &&
      (m_time < (time_t)0x70000000L))
    m_time = ((time_t)(unsigned long)0xffffffffL);
  if (m_time < (time_t)0L)
    m_time = ((time_t)(unsigned long)0x7fffffffL);
  return m_time;
}


x86 assembly (clang, -O0):
<dos_to_unix_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x8(%rbp),%rax
shr    $0x19,%rax
mov    %eax,%ecx
and    $0x7f,%ecx
add    $0x50,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
shr    $0x15,%rax
mov    %eax,%ecx
and    $0xf,%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rax
shr    $0x10,%rax
mov    %eax,%ecx
and    $0x1f,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x8(%rbp),%rax
mov    %eax,%ecx
shr    $0xb,%ecx
and    $0x1f,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x8(%rbp),%rax
mov    %eax,%ecx
shr    $0x5,%ecx
and    $0x3f,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x8(%rbp),%rax
mov    %eax,%ecx
shl    $0x1,%ecx
and    $0x3e,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <mktime@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x74320000,-0x8(%rbp)
74
jb     120d <dos_to_unix_time+0xdd>
cmpq   $0x70000000,-0x10(%rbp)
70
jge    120d <dos_to_unix_time+0xdd>
mov    $0xffffffff,%eax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1220 <dos_to_unix_time+0xf0>
movq   $0x7fffffff,-0x10(%rbp)
7f
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dos_to_unix_time>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <localtime@plt>
movl   $0xffffffff,(%rax)
mov    %ebx,%ecx
shr    $0x19,%ecx
add    $0x50,%ecx
mov    %ecx,0x4(%rax)
mov    %ebx,%ecx
shr    $0x15,%ecx
and    $0xf,%ecx
add    $0xffffffff,%ecx
mov    %ecx,0x8(%rax)
mov    %ebx,%ecx
shr    $0x10,%ecx
and    $0x1f,%ecx
mov    %ecx,0xc(%rax)
mov    %ebx,%ecx
shr    $0xb,%ecx
and    $0x1f,%ecx
mov    %ecx,0x10(%rax)
mov    %ebx,%ecx
shr    $0x5,%ecx
and    $0x3f,%ecx
mov    %ecx,0x14(%rax)
lea    (%rbx,%rbx,1),%ecx
and    $0x3e,%ecx
mov    %ecx,0x18(%rax)
mov    %rax,%rdi
call   1050 <mktime@plt>
cmp    $0x70000000,%rax
mov    $0xffffffff,%ecx
cmovge %rax,%rcx
cmp    $0x74320000,%rbx
cmovae %rcx,%rax
test   %rax,%rax
mov    $0x7fffffff,%ecx
cmovs  %rcx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
define i64 @dos_to_unix_time(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca %struct.tm*
%5 = alloca i64
store i64 %0, i64* %2
%6 = call i64 @time(i32* null)
store i64 %6, i64* %5
%7 = call %struct.tm* @localtime(i64* %5)
store %struct.tm* %7, %struct.tm** %4
%8 = load %struct.tm*, %struct.tm** %4
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 0
store i32 -1, i32* %9
%10 = load i64, i64* %2
%11 = lshr i64 %10, 25
%12 = trunc i64 %11 to i32
%13 = and i32 %12, 127
%14 = add nsw i32 %13, 80
%15 = load %struct.tm*, %struct.tm** %4
%16 = getelementptr inbounds %struct.tm, %struct.tm* %15, i32 0, i32 1
store i32 %14, i32* %16
%17 = load i64, i64* %2
%18 = lshr i64 %17, 21
%19 = trunc i64 %18 to i32
%20 = and i32 %19, 15
%21 = sub nsw i32 %20, 1
%22 = load %struct.tm*, %struct.tm** %4
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 2
store i32 %21, i32* %23
%24 = load i64, i64* %2
%25 = lshr i64 %24, 16
%26 = trunc i64 %25 to i32
%27 = and i32 %26, 31
%28 = load %struct.tm*, %struct.tm** %4
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 3
store i32 %27, i32* %29
%30 = load i64, i64* %2
%31 = trunc i64 %30 to i32
%32 = lshr i32 %31, 11
%33 = and i32 %32, 31
%34 = load %struct.tm*, %struct.tm** %4
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 4
store i32 %33, i32* %35
%36 = load i64, i64* %2
%37 = trunc i64 %36 to i32
%38 = lshr i32 %37, 5
%39 = and i32 %38, 63
%40 = load %struct.tm*, %struct.tm** %4
%41 = getelementptr inbounds %struct.tm, %struct.tm* %40, i32 0, i32 5
store i32 %39, i32* %41
%42 = load i64, i64* %2
%43 = trunc i64 %42 to i32
%44 = shl i32 %43, 1
%45 = and i32 %44, 62
%46 = load %struct.tm*, %struct.tm** %4
%47 = getelementptr inbounds %struct.tm, %struct.tm* %46, i32 0, i32 6
store i32 %45, i32* %47
%48 = load %struct.tm*, %struct.tm** %4
%49 = call i64 @mktime(%struct.tm* %48)
store i64 %49, i64* %3
%50 = load i64, i64* %2
%51 = icmp uge i64 %50, 1949433856
br i1 %51, label %52, label %56
52: ; preds = %1
%53 = load i64, i64* %3
%54 = icmp slt i64 %53, 1879048192
br i1 %54, label %55, label %56
55: ; preds = %52
store i64 4294967295, i64* %3
br label %56
56: ; preds = %55, %52, %1
%57 = load i64, i64* %3
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %56
store i64 2147483647, i64* %3
br label %60
60: ; preds = %59, %56
%61 = load i64, i64* %3
ret i64 %61
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32 }
define i64 @dos_to_unix_time(i64 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = tail call i64 @time(i32* null)
store i64 %4, i64* %2
%5 = call %struct.tm* @localtime(i64* %2)
%6 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
store i32 -1, i32* %6
%7 = trunc i64 %0 to i32
%8 = lshr i32 %7, 25
%9 = add nuw nsw i32 %8, 80
%10 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
store i32 %9, i32* %10
%11 = lshr i32 %7, 21
%12 = and i32 %11, 15
%13 = add nsw i32 %12, -1
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
store i32 %13, i32* %14
%15 = lshr i32 %7, 16
%16 = and i32 %15, 31
%17 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 3
store i32 %16, i32* %17
%18 = lshr i32 %7, 11
%19 = and i32 %18, 31
%20 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 4
store i32 %19, i32* %20
%21 = lshr i32 %7, 5
%22 = and i32 %21, 63
%23 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 5
store i32 %22, i32* %23
%24 = shl i32 %7, 1
%25 = and i32 %24, 62
%26 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 6
store i32 %25, i32* %26
%27 = call i64 @mktime(%struct.tm* %5)
%28 = icmp ugt i64 %0, 1949433855
%29 = icmp slt i64 %27, 1879048192
%30 = and i1 %28, %29
%31 = select i1 %30, i64 4294967295, i64 %27
%32 = icmp slt i64 %31, 0
%33 = select i1 %32, i64 2147483647, i64 %31
ret i64 %33
}