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

/* Variables and functions */
double fb_DateSerial(scalar_t__, scalar_t__, int /*<<< orphan*/);
double fb_TimeSerial(int /*<<< orphan*/, int /*<<< orphan*/,
                     int /*<<< orphan*/);
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ stat(char const *, struct stat *);
double fb_FileDateTime(const char *filename) {
  struct stat buf;
  if (stat(filename, &buf) != 0)
    return 0.0;
  struct tm *tm = localtime(&buf.st_mtime);
  if (tm == 0)
    return 0.0;
  return fb_DateSerial(1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday) +
         fb_TimeSerial(tm->tm_hour, tm->tm_min, tm->tm_sec);
}


x86 assembly (clang, -O0):
<fb_FileDateTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
je     1170 <fb_FileDateTime+0x30>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11eb <fb_FileDateTime+0xab>
lea    -0x18(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1195 <fb_FileDateTime+0x55>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11eb <fb_FileDateTime+0xab>
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rdi
add    $0x76c,%rdi
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rsi
add    $0x1,%rsi
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%edx
call   1040 <fb_DateSerial@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1060 <fb_TimeSerial@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_FileDateTime>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rsi
call   1050 <stat@plt>
xorpd  %xmm0,%xmm0
test   %rax,%rax
jne    119c <fb_FileDateTime+0x5c>
mov    %rsp,%rdi
call   1030 <localtime@plt>
xorpd  %xmm0,%xmm0
test   %rax,%rax
je     119c <fb_FileDateTime+0x5c>
mov    %rax,%rbx
mov    $0x76c,%edi
add    0x18(%rax),%rdi
mov    0x10(%rax),%rsi
add    $0x1,%rsi
mov    0xc(%rax),%edx
call   1040 <fb_DateSerial@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x8(%rbx),%edi
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
call   1060 <fb_TimeSerial@plt>
addsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i64, i64 }
define double @fb_FileDateTime(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca %struct.tm*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @stat(i8* %6, %struct.stat* %4)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store double 0.000000e+00, double* %2
br label %40
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%12 = call %struct.tm* @localtime(i32* %11)
store %struct.tm* %12, %struct.tm** %5
%13 = load %struct.tm*, %struct.tm** %5
%14 = icmp eq %struct.tm* %13, null
br i1 %14, label %15, label %16
15: ; preds = %10
store double 0.000000e+00, double* %2
br label %40
16: ; preds = %10
%17 = load %struct.tm*, %struct.tm** %5
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 5
%19 = load i64, i64* %18
%20 = add nsw i64 1900, %19
%21 = load %struct.tm*, %struct.tm** %5
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i32 0, i32 4
%23 = load i64, i64* %22
%24 = add nsw i64 1, %23
%25 = load %struct.tm*, %struct.tm** %5
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 3
%27 = load i32, i32* %26
%28 = call double @fb_DateSerial(i64 %20, i64 %24, i32 %27)
%29 = load %struct.tm*, %struct.tm** %5
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 2
%31 = load i32, i32* %30
%32 = load %struct.tm*, %struct.tm** %5
%33 = getelementptr inbounds %struct.tm, %struct.tm* %32, i32 0, i32 1
%34 = load i32, i32* %33
%35 = load %struct.tm*, %struct.tm** %5
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call double @fb_TimeSerial(i32 %31, i32 %34, i32 %37)
%39 = fadd double %28, %38
store double %39, double* %2
br label %40
40: ; preds = %16, %15, %9
%41 = load double, double* %2
ret double %41
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i64, i64 }
define double @fb_FileDateTime(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %28
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = call %struct.tm* @localtime(i32* %7)
%9 = icmp eq %struct.tm* %8, null
br i1 %9, label %28, label %10
10: ; preds = %6
%11 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 5
%12 = load i64, i64* %11
%13 = add nsw i64 %12, 1900
%14 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 4
%15 = load i64, i64* %14
%16 = add nsw i64 %15, 1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 3
%18 = load i32, i32* %17
%19 = call double @fb_DateSerial(i64 %13, i64 %16, i32 %18)
%20 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 2
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call double @fb_TimeSerial(i32 %21, i32 %23, i32 %25)
%27 = fadd double %19, %26
br label %28
28: ; preds = %10, %6, %1
%29 = phi double [ 0.000000e+00, %1 ], [ %27, %10 ], [ 0.000000e+00, %6 ]
ret double %29
}