#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 */

/* Variables and functions */
char *dupe_str(char const *);
char *dupe_str_n(char const *, int);
int /*<<< orphan*/ free(char *);
int safe_strlen(char const *);
char *strrchr(char const *, char);
char *get_datestring_from_filename(const char *filename) {
  char *ret = dupe_str(filename);
  if (filename == NULL) {
    return ret;
  }
  const char *dot = strrchr(filename, '.');
  size_t s;
  if (dot == NULL) {
    s = safe_strlen(filename);
  } else {
    if (safe_strlen(filename) - (dot - filename) <= 5) {
      s = dot - filename;
    } else {
      s = safe_strlen(filename);
    }
  }
  if (s <= 18 || s > 1024) {
    return ret;
  }
  free(ret);
  return dupe_str_n((const char *)(filename + s - 19), 19);
}


x86 assembly (clang, -O0):
<get_datestring_from_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <dupe_str@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1181 <get_datestring_from_filename+0x31>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1246 <get_datestring_from_filename+0xf6>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b2 <get_datestring_from_filename+0x62>
mov    -0x10(%rbp),%rdi
call   1060 <safe_strlen@plt>
cltq
mov    %rax,-0x28(%rbp)
jmp    11fd <get_datestring_from_filename+0xad>
mov    -0x10(%rbp),%rdi
call   1060 <safe_strlen@plt>
cltq
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
sub    %rcx,%rax
cmp    $0x5,%rax
jg     11e9 <get_datestring_from_filename+0x99>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    11f8 <get_datestring_from_filename+0xa8>
mov    -0x10(%rbp),%rdi
call   1060 <safe_strlen@plt>
cltq
mov    %rax,-0x28(%rbp)
jmp    11fd <get_datestring_from_filename+0xad>
cmpq   $0x12,-0x28(%rbp)
jbe    1216 <get_datestring_from_filename+0xc6>
cmpq   $0x400,-0x28(%rbp)
jbe    1223 <get_datestring_from_filename+0xd3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1246 <get_datestring_from_filename+0xf6>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0xffffffffffffffed,%rdi
mov    $0x13,%esi
call   1070 <dupe_str_n@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_datestring_from_filename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <dupe_str@plt>
mov    %rax,%r14
test   %r15,%r15
je     11b2 <get_datestring_from_filename+0x62>
mov    %r15,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1060 <safe_strlen@plt>
movslq %eax,%r12
test   %rbx,%rbx
je     11a2 <get_datestring_from_filename+0x52>
sub    %r15,%rbx
sub    %rbx,%r12
cmp    $0x6,%r12
mov    %rbx,%r12
jl     11a2 <get_datestring_from_filename+0x52>
mov    %r15,%rdi
call   1060 <safe_strlen@plt>
movslq %eax,%r12
lea    -0x401(%r12),%rax
ff
cmp    $0xfffffffffffffc12,%rax
jae    11c1 <get_datestring_from_filename+0x71>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
call   1030 <free@plt>
lea    (%r15,%r12,1),%rdi
add    $0xffffffffffffffed,%rdi
mov    $0x13,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <dupe_str_n@plt>

LLVM IR (-O0):
define i8* @get_datestring_from_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @dupe_str(i8* %7)
store i8* %8, i8** %4
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i8*, i8** %4
store i8* %12, i8** %2
br label %60
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i8* @strrchr(i8* %14, i8 signext 46)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i32 @safe_strlen(i8* %19)
%21 = sext i32 %20 to i64
store i64 %21, i64* %6
br label %44
22: ; preds = %13
%23 = load i8*, i8** %3
%24 = call i32 @safe_strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = load i8*, i8** %5
%27 = load i8*, i8** %3
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = sub nsw i64 %25, %30
%32 = icmp sle i64 %31, 5
br i1 %32, label %33, label %39
33: ; preds = %22
%34 = load i8*, i8** %5
%35 = load i8*, i8** %3
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
store i64 %38, i64* %6
br label %43
39: ; preds = %22
%40 = load i8*, i8** %3
%41 = call i32 @safe_strlen(i8* %40)
%42 = sext i32 %41 to i64
store i64 %42, i64* %6
br label %43
43: ; preds = %39, %33
br label %44
44: ; preds = %43, %18
%45 = load i64, i64* %6
%46 = icmp ule i64 %45, 18
br i1 %46, label %50, label %47
47: ; preds = %44
%48 = load i64, i64* %6
%49 = icmp ugt i64 %48, 1024
br i1 %49, label %50, label %52
50: ; preds = %47, %44
%51 = load i8*, i8** %4
store i8* %51, i8** %2
br label %60
52: ; preds = %47
%53 = load i8*, i8** %4
%54 = call i32 @free(i8* %53)
%55 = load i8*, i8** %3
%56 = load i64, i64* %6
%57 = getelementptr inbounds i8, i8* %55, i64 %56
%58 = getelementptr inbounds i8, i8* %57, i64 -19
%59 = call i8* @dupe_str_n(i8* %58, i32 19)
store i8* %59, i8** %2
br label %60
60: ; preds = %52, %50, %11
%61 = load i8*, i8** %2
ret i8* %61
}

LLVM IR (-O2):
define i8* @get_datestring_from_filename(i8* %0) {
%2 = tail call i8* @dupe_str(i8* %0)
%3 = icmp eq i8* %0, null
br i1 %3, label %27, label %4
4: ; preds = %1
%5 = tail call i8* @strrchr(i8* %0, i8 signext 46)
%6 = icmp eq i8* %5, null
%7 = tail call i32 @safe_strlen(i8* %0)
%8 = sext i32 %7 to i64
br i1 %6, label %18, label %9
9: ; preds = %4
%10 = ptrtoint i8* %5 to i64
%11 = ptrtoint i8* %0 to i64
%12 = sub i64 %10, %11
%13 = sub nsw i64 %8, %12
%14 = icmp slt i64 %13, 6
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = tail call i32 @safe_strlen(i8* %0)
%17 = sext i32 %16 to i64
br label %18
18: ; preds = %4, %9, %15
%19 = phi i64 [ %17, %15 ], [ %12, %9 ], [ %8, %4 ]
%20 = add i64 %19, -1025
%21 = icmp ult i64 %20, -1006
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = tail call i32 @free(i8* %2)
%24 = getelementptr inbounds i8, i8* %0, i64 %19
%25 = getelementptr inbounds i8, i8* %24, i64 -19
%26 = tail call i8* @dupe_str_n(i8* %25, i32 19)
br label %27
27: ; preds = %22, %18, %1
%28 = phi i8* [ %2, %1 ], [ %26, %22 ], [ %2, %18 ]
ret i8* %28
}