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

/* Variables and functions */
scalar_t__ Ftest(char *);
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ tprintf(char *, char *);
char *Fdatetime(char *filename, int debug) {
  struct tm *ptr_ts;
  struct stat b;
  char *datetime;
  datetime = (char *)malloc(16 * sizeof(char));
  if (Ftest(filename) != 0) {
    datetime[0] = 0;
    if (debug)
      tprintf("File %s: does not exist\n", filename);
  } else if (!stat(filename, &b)) {
    ptr_ts = localtime(&b.st_mtime);
    sprintf(datetime, "%4d%02d%02d-%02d%02d%02d", ptr_ts->tm_year + 1900,
            ptr_ts->tm_mon + 1, ptr_ts->tm_mday, ptr_ts->tm_hour,
            ptr_ts->tm_min, ptr_ts->tm_sec);
    if (debug)
      printf("File %s: last modified at %s\n", filename, datetime);
  } else {
    datetime[0] = 0;
    if (debug)
      printf("File %s: cannot display the time\n", filename);
  }
  return (datetime);
}


x86 assembly (clang, -O0):
<Fdatetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x10,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <Ftest@plt>
cmp    $0x0,%rax
je     11c6 <Fdatetime+0x56>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0xc(%rbp)
je     11c1 <Fdatetime+0x51>
mov    -0x8(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1060 <tprintf@plt>
jmp    1288 <Fdatetime+0x118>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%eax
jne    125b <Fdatetime+0xeb>
lea    -0x20(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
add    $0x76c,%edx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%r10d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%eax
lea    0xdf0(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1090 <sprintf@plt>
cmpl   $0x0,-0xc(%rbp)
je     1256 <Fdatetime+0xe6>
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1283 <Fdatetime+0x113>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0xc(%rbp)
je     127e <Fdatetime+0x10e>
mov    -0x8(%rbp),%rsi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1283 <Fdatetime+0x113>
jmp    1288 <Fdatetime+0x118>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Fdatetime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x10,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <Ftest@plt>
test   %rax,%rax
je     11b7 <Fdatetime+0x47>
movb   $0x0,(%r14)
test   %ebp,%ebp
je     1237 <Fdatetime+0xc7>
lea    0xe56(%rip),%rdi
mov    %rbx,%rsi
call   1060 <tprintf@plt>
jmp    1237 <Fdatetime+0xc7>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <stat@plt>
test   %eax,%eax
je     11e3 <Fdatetime+0x73>
movb   $0x0,(%r14)
test   %ebp,%ebp
je     1237 <Fdatetime+0xc7>
lea    0xe79(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1237 <Fdatetime+0xc7>
lea    0x8(%rsp),%rdi
call   1030 <localtime@plt>
mov    $0x76c,%edx
add    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
add    $0x1,%ecx
mov    0xc(%rax),%r9d
mov    0x14(%rax),%r10d
mov    0x10(%rax),%eax
lea    0xe09(%rip),%rsi
mov    %r14,%rdi
push   %rax
push   %r10
call   1090 <sprintf@plt>
add    $0x10,%rsp
test   %ebp,%ebp
je     1237 <Fdatetime+0xc7>
lea    0xe08(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
%struct.stat = type { i32 }
@.str = [25 x i8] c"File %s: does not exist\0A\00"
@.str.1 = [25 x i8] c"%4d%02d%02d-%02d%02d%02d\00"
@.str.2 = [30 x i8] c"File %s: last modified at %s\0A\00"
@.str.3 = [34 x i8] c"File %s: cannot display the time\0A\00"
define i8* @Fdatetime(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.tm*
%6 = alloca %struct.stat
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call i64 @malloc(i32 16)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %7
%10 = load i8*, i8** %3
%11 = call i64 @Ftest(i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load i8*, i8** %7
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 0, i8* %15
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i32 @tprintf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %13
br label %68
22: ; preds = %2
%23 = load i8*, i8** %3
%24 = call i32 @stat(i8* %23, %struct.stat* %6)
%25 = icmp ne i32 %24, 0
br i1 %25, label %58, label %26
26: ; preds = %22
%27 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%28 = call %struct.tm* @localtime(i32* %27)
store %struct.tm* %28, %struct.tm** %5
%29 = load i8*, i8** %7
%30 = load %struct.tm*, %struct.tm** %5
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = add nsw i32 %32, 1900
%34 = load %struct.tm*, %struct.tm** %5
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 1
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
%38 = load %struct.tm*, %struct.tm** %5
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 2
%40 = load i32, i32* %39
%41 = load %struct.tm*, %struct.tm** %5
%42 = getelementptr inbounds %struct.tm, %struct.tm* %41, i32 0, i32 3
%43 = load i32, i32* %42
%44 = load %struct.tm*, %struct.tm** %5
%45 = getelementptr inbounds %struct.tm, %struct.tm* %44, i32 0, i32 5
%46 = load i32, i32* %45
%47 = load %struct.tm*, %struct.tm** %5
%48 = getelementptr inbounds %struct.tm, %struct.tm* %47, i32 0, i32 4
%49 = load i32, i32* %48
%50 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %37, i32 %40, i32 %43, i32 %46, i32 %49)
%51 = load i32, i32* %4
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %26
%54 = load i8*, i8** %3
%55 = load i8*, i8** %7
%56 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %54, i8* %55)
br label %57
57: ; preds = %53, %26
br label %67
58: ; preds = %22
%59 = load i8*, i8** %7
%60 = getelementptr inbounds i8, i8* %59, i64 0
store i8 0, i8* %60
%61 = load i32, i32* %4
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = load i8*, i8** %3
%65 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %64)
br label %66
66: ; preds = %63, %58
br label %67
67: ; preds = %66, %57
br label %68
68: ; preds = %67, %21
%69 = load i8*, i8** %7
ret i8* %69
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [25 x i8] c"File %s: does not exist\0A\00"
@.str.1 = [25 x i8] c"%4d%02d%02d-%02d%02d%02d\00"
@.str.2 = [30 x i8] c"File %s: last modified at %s\0A\00"
@.str.3 = [34 x i8] c"File %s: cannot display the time\0A\00"
define i8* @Fdatetime(i8* %0, i32 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i64 @malloc(i32 16)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i64 @Ftest(i8* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
store i8 0, i8* %6
%10 = icmp eq i32 %1, 0
br i1 %10, label %41, label %11
11: ; preds = %9
%12 = tail call i32 @tprintf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %41
13: ; preds = %2
%14 = call i32 @stat(i8* %0, %struct.stat* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %37
16: ; preds = %13
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%18 = call %struct.tm* @localtime(i32* %17)
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 0
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1900
%22 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 1
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1
%25 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 2
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 3
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 5
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.tm, %struct.tm* %18, i64 0, i32 4
%32 = load i32, i32* %31
%33 = call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %24, i32 %26, i32 %28, i32 %30, i32 %32)
%34 = icmp eq i32 %1, 0
br i1 %34, label %41, label %35
35: ; preds = %16
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %6)
br label %41
37: ; preds = %13
store i8 0, i8* %6
%38 = icmp eq i32 %1, 0
br i1 %38, label %41, label %39
39: ; preds = %37
%40 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %41
41: ; preds = %35, %16, %39, %37, %9, %11
ret i8* %6
}