#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 time_t;
struct tm {
  scalar_t__ tm_year;
  scalar_t__ tm_mon;
};
struct stat {
  int st_mtime;
};

/* Variables and functions */
int /*<<< orphan*/ *localtime_r(int *, struct tm *);
char *strdup(char *);
size_t strftime(char *, int, char *, struct tm *);
int time(int /*<<< orphan*/ *);
size_t myls_get_mtime(struct stat *filename_stat, char **mtime_str) {
  char str[100];
  struct tm mtime_lt;
  struct tm now_lt;
  time_t mtime_raw;
  time_t now_raw;
  size_t res;
  mtime_raw = filename_stat->st_mtime;
  if ((now_raw = time(NULL)) == -1)
    return -1;
  if (localtime_r(&now_raw, &now_lt) == NULL)
    return -1;
  if (localtime_r(&mtime_raw, &mtime_lt) == NULL)
    return -1;
  if (now_lt.tm_year == mtime_lt.tm_year && now_lt.tm_mon == mtime_lt.tm_mon) {
    if ((res = strftime(str, 100, "%b %d %H:%M", &mtime_lt)) < 0)
      return -1;
    if ((*mtime_str = strdup(str)) == NULL)
      return -1;
    return res;
  } else {
    if ((res = strftime(str, 100, "%b %d  %Y", &mtime_lt)) < 0)
      return -1;
    if ((*mtime_str = strdup(str)) == NULL)
      return -1;
    return res;
  }
}


x86 assembly (clang, -O0):
<myls_get_mtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0xa8(%rbp)
cmp    $0xffffffff,%eax
jne    1184 <myls_get_mtime+0x44>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12dd <myls_get_mtime+0x19d>
lea    -0xa8(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
jne    11ae <myls_get_mtime+0x6e>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12dd <myls_get_mtime+0x19d>
lea    -0xa4(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
jne    11d8 <myls_get_mtime+0x98>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12dd <myls_get_mtime+0x19d>
mov    -0xa0(%rbp),%rax
cmp    -0x90(%rbp),%rax
jne    1271 <myls_get_mtime+0x131>
mov    -0x98(%rbp),%rax
cmp    -0x88(%rbp),%rax
jne    1271 <myls_get_mtime+0x131>
lea    -0x80(%rbp),%rdi
mov    $0x64,%esi
lea    0xdf0(%rip),%rdx
lea    -0x90(%rbp),%rcx
call   1050 <strftime@plt>
mov    %rax,-0xb0(%rbp)
cmp    $0x0,%rax
jae    123a <myls_get_mtime+0xfa>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12dd <myls_get_mtime+0x19d>
lea    -0x80(%rbp),%rdi
call   1060 <strdup@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    1261 <myls_get_mtime+0x121>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12dd <myls_get_mtime+0x19d>
mov    -0xb0(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12dd <myls_get_mtime+0x19d>
lea    -0x80(%rbp),%rdi
mov    $0x64,%esi
lea    0xd8b(%rip),%rdx
lea    -0x90(%rbp),%rcx
call   1050 <strftime@plt>
mov    %rax,-0xb0(%rbp)
cmp    $0x0,%rax
jae    12ab <myls_get_mtime+0x16b>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12dd <myls_get_mtime+0x19d>
lea    -0x80(%rbp),%rdi
call   1060 <strdup@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    12d2 <myls_get_mtime+0x192>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12dd <myls_get_mtime+0x19d>
mov    -0xb0(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myls_get_mtime>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    %rsi,%r14
mov    (%rdi),%eax
mov    %eax,0xc(%rsp)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x8(%rsp)
mov    $0xffffffffffffffff,%rbx
cmp    $0xffffffff,%eax
je     11eb <myls_get_mtime+0xab>
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
je     11eb <myls_get_mtime+0xab>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
je     11eb <myls_get_mtime+0xab>
mov    0x20(%rsp),%rax
cmp    0x10(%rsp),%rax
jne    11b5 <myls_get_mtime+0x75>
mov    0x28(%rsp),%rax
cmp    0x18(%rsp),%rax
jne    11b5 <myls_get_mtime+0x75>
lea    0xe4d(%rip),%rdx
jmp    11bc <myls_get_mtime+0x7c>
lea    0xe50(%rip),%rdx
lea    0x30(%rsp),%rbx
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <strftime@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1060 <strdup@plt>
mov    %rax,(%r14)
cmp    $0x1,%rax
sbb    %rbx,%rbx
or     %r15,%rbx
mov    %rbx,%rax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.tm = type { i64, i64 }
@.str = [12 x i8] c"%b %d %H:%M\00"
@.str.1 = [10 x i8] c"%b %d %Y\00"
define i64 @myls_get_mtime(%struct.stat* %0, i8** %1) {
%3 = alloca i64
%4 = alloca %struct.stat*
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca %struct.tm
%8 = alloca %struct.tm
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store %struct.stat* %0, %struct.stat** %4
store i8** %1, i8*** %5
%12 = load %struct.stat*, %struct.stat** %4
%13 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%14 = load i32, i32* %13
store i32 %14, i32* %9
%15 = call i32 @time(i32* null)
store i32 %15, i32* %10
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %2
store i64 -1, i64* %3
br label %64
18: ; preds = %2
%19 = call i32* @localtime_r(i32* %10, %struct.tm* %8)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %18
store i64 -1, i64* %3
br label %64
22: ; preds = %18
%23 = call i32* @localtime_r(i32* %9, %struct.tm* %7)
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %26
25: ; preds = %22
store i64 -1, i64* %3
br label %64
26: ; preds = %22
%27 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 0
%28 = load i64, i64* %27
%29 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%30 = load i64, i64* %29
%31 = icmp eq i64 %28, %30
br i1 %31, label %32, label %51
32: ; preds = %26
%33 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 1
%34 = load i64, i64* %33
%35 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 1
%36 = load i64, i64* %35
%37 = icmp eq i64 %34, %36
br i1 %37, label %38, label %51
38: ; preds = %32
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%40 = call i64 @strftime(i8* %39, i32 100, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %struct.tm* %7)
store i64 %40, i64* %11
%41 = icmp ult i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %38
store i64 -1, i64* %3
br label %64
43: ; preds = %38
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%45 = call i8* @strdup(i8* %44)
%46 = load i8**, i8*** %5
store i8* %45, i8** %46
%47 = icmp eq i8* %45, null
br i1 %47, label %48, label %49
48: ; preds = %43
store i64 -1, i64* %3
br label %64
49: ; preds = %43
%50 = load i64, i64* %11
store i64 %50, i64* %3
br label %64
51: ; preds = %32, %26
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%53 = call i64 @strftime(i8* %52, i32 100, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %7)
store i64 %53, i64* %11
%54 = icmp ult i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %51
store i64 -1, i64* %3
br label %64
56: ; preds = %51
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%58 = call i8* @strdup(i8* %57)
%59 = load i8**, i8*** %5
store i8* %58, i8** %59
%60 = icmp eq i8* %58, null
br i1 %60, label %61, label %62
61: ; preds = %56
store i64 -1, i64* %3
br label %64
62: ; preds = %56
%63 = load i64, i64* %11
store i64 %63, i64* %3
br label %64
64: ; preds = %62, %61, %55, %49, %48, %42, %25, %21, %17
%65 = load i64, i64* %3
ret i64 %65
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.tm = type { i64, i64 }
@.str = [12 x i8] c"%b %d %H:%M\00"
@.str.1 = [10 x i8] c"%b %d %Y\00"
define i64 @myls_get_mtime(%struct.stat* nocapture %0, i8** nocapture writeonly %1) {
%3 = alloca [100 x i8]
%4 = alloca %struct.tm
%5 = alloca %struct.tm
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%9 = bitcast %struct.tm* %4 to i8*
%10 = bitcast %struct.tm* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%14 = load i32, i32* %13
store i32 %14, i32* %6
%15 = tail call i32 @time(i32* null)
store i32 %15, i32* %7
%16 = icmp eq i32 %15, -1
br i1 %16, label %42, label %17
17: ; preds = %2
%18 = call i32* @localtime_r(i32* %7, %struct.tm* %5)
%19 = icmp eq i32* %18, null
br i1 %19, label %42, label %20
20: ; preds = %17
%21 = call i32* @localtime_r(i32* %6, %struct.tm* %4)
%22 = icmp eq i32* %21, null
br i1 %22, label %42, label %23
23: ; preds = %20
%24 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%25 = load i64, i64* %24
%26 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%27 = load i64, i64* %26
%28 = icmp eq i64 %25, %27
br i1 %28, label %29, label %35
29: ; preds = %23
%30 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%31 = load i64, i64* %30
%32 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%33 = load i64, i64* %32
%34 = icmp eq i64 %31, %33
br i1 %34, label %36, label %35
35: ; preds = %29, %23
br label %36
36: ; preds = %29, %35
%37 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %35 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %29 ]
%38 = call i64 @strftime(i8* %8, i32 100, i8* %37, %struct.tm* %4)
%39 = call i8* @strdup(i8* %8)
store i8* %39, i8** %1
%40 = icmp eq i8* %39, null
%41 = select i1 %40, i64 -1, i64 %38
br label %42
42: ; preds = %36, %20, %17, %2
%43 = phi i64 [ -1, %2 ], [ -1, %17 ], [ -1, %20 ], [ %41, %36 ]
ret i64 %43
}