#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 {
  scalar_t__ tm_isdst;
};

/* Variables and functions */
char *equalize_date_string(char *);
int /*<<< orphan*/ error_printf(char *, char const *);
int /*<<< orphan*/ free(char *);
char *get_datestring_from_filename(char const *);
scalar_t__ mktime(struct tm *);
int /*<<< orphan*/ *strptime(char *, char *, struct tm *);
int get_unix_timestamp_from_filename(const char *filename) {
  if (filename == NULL) {
    return 0;
  }
  char *datestring = get_datestring_from_filename(filename);
  if (datestring == NULL) {
    return 0;
  }
  char *datestring2 = equalize_date_string(datestring);
  free(datestring);
  if (datestring2 == NULL) {
    return 0;
  }
  struct tm tm;
  time_t epoch;
  tm.tm_isdst = 0;
  if (strptime(datestring2, "%Y %m %d %H %M %S", &tm) != NULL) {
    tm.tm_isdst = 0;
    epoch = mktime(&tm);
  } else {
    epoch = 0;
    error_printf("Error: Can not parse date and time from filename: %s\n",
                 filename);
  }
  free(datestring2);
  return (int)epoch;
}


x86 assembly (clang, -O0):
<get_unix_timestamp_from_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <get_unix_timestamp_from_filename+0x23>
movl   $0x0,-0x4(%rbp)
jmp    123c <get_unix_timestamp_from_filename+0xdc>
mov    -0x10(%rbp),%rdi
call   1070 <get_datestring_from_filename@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a7 <get_unix_timestamp_from_filename+0x47>
movl   $0x0,-0x4(%rbp)
jmp    123c <get_unix_timestamp_from_filename+0xdc>
mov    -0x18(%rbp),%rdi
call   1050 <equalize_date_string@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11d4 <get_unix_timestamp_from_filename+0x74>
movl   $0x0,-0x4(%rbp)
jmp    123c <get_unix_timestamp_from_filename+0xdc>
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe19(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1080 <strptime@plt>
cmp    $0x0,%rax
je     1214 <get_unix_timestamp_from_filename+0xb4>
movq   $0x0,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
call   1060 <mktime@plt>
mov    %rax,-0x30(%rbp)
jmp    122c <get_unix_timestamp_from_filename+0xcc>
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xdeb(%rip),%rdi
call   1040 <error_printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_unix_timestamp_from_filename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %r15d,%r15d
test   %rdi,%rdi
je     11e6 <get_unix_timestamp_from_filename+0x86>
mov    %rdi,%r12
call   1070 <get_datestring_from_filename@plt>
test   %rax,%rax
je     11e6 <get_unix_timestamp_from_filename+0x86>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <equalize_date_string@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     11e6 <get_unix_timestamp_from_filename+0x86>
movq   $0x0,(%rsp)
lea    0xe59(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
call   1080 <strptime@plt>
test   %rax,%rax
je     11cc <get_unix_timestamp_from_filename+0x6c>
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   1060 <mktime@plt>
mov    %rax,%r15
jmp    11de <get_unix_timestamp_from_filename+0x7e>
lea    0xe3f(%rip),%rdi
mov    %r12,%rsi
call   1040 <error_printf@plt>
xor    %r15d,%r15d
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i64 }
@.str = [18 x i8] c"%Y %m %d %H %M %S\00"
@.str.1 = [54 x i8] c"Error: Can not parse date and time from filename: %s\0A\00"
define i32 @get_unix_timestamp_from_filename(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.tm
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %41
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i8* @get_datestring_from_filename(i8* %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 0, i32* %2
br label %41
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = call i8* @equalize_date_string(i8* %18)
store i8* %19, i8** %5
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
%22 = load i8*, i8** %5
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 0, i32* %2
br label %41
25: ; preds = %17
%26 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
store i64 0, i64* %26
%27 = load i8*, i8** %5
%28 = call i32* @strptime(i8* %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %6)
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
store i64 0, i64* %31
%32 = call i64 @mktime(%struct.tm* %6)
store i64 %32, i64* %7
br label %36
33: ; preds = %25
store i64 0, i64* %7
%34 = load i8*, i8** %3
%35 = call i32 @error_printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %33, %30
%37 = load i8*, i8** %5
%38 = call i32 @free(i8* %37)
%39 = load i64, i64* %7
%40 = trunc i64 %39 to i32
store i32 %40, i32* %2
br label %41
41: ; preds = %36, %24, %16, %10
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
%struct.tm = type { i64 }
@.str = [18 x i8] c"%Y %m %d %H %M %S\00"
@.str.1 = [54 x i8] c"Error: Can not parse date and time from filename: %s\0A\00"
define i32 @get_unix_timestamp_from_filename(i8* %0) {
%2 = alloca %struct.tm
%3 = icmp eq i8* %0, null
br i1 %3, label %24, label %4
4: ; preds = %1
%5 = tail call i8* @get_datestring_from_filename(i8* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %24, label %7
7: ; preds = %4
%8 = tail call i8* @equalize_date_string(i8* %5)
%9 = tail call i32 @free(i8* %5)
%10 = icmp eq i8* %8, null
br i1 %10, label %24, label %11
11: ; preds = %7
%12 = bitcast %struct.tm* %2 to i8*
%13 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
store i64 0, i64* %13
%14 = call i32* @strptime(i8* %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %2)
%15 = icmp eq i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %11
store i64 0, i64* %13
%17 = call i64 @mktime(%struct.tm* %2)
%18 = trunc i64 %17 to i32
br label %21
19: ; preds = %11
%20 = call i32 @error_printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %21
21: ; preds = %19, %16
%22 = phi i32 [ %18, %16 ], [ 0, %19 ]
%23 = call i32 @free(i8* %8)
br label %24
24: ; preds = %4, %7, %21, %1
%25 = phi i32 [ 0, %1 ], [ 0, %4 ], [ %22, %21 ], [ 0, %7 ]
ret i32 %25
}