#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 */
int atoi(char *);
char *calculateFileName(int /*<<< orphan*/ *, int, int, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *getFilename(char *date) {
  char *current;
  char next[10];
  int year = 0;
  int month = 0;
  int day = 0;
  if (date && (strlen(date) == 8)) {
    current = date;
    strncpy(next, current, 4);
    next[4] = '\0';
    year = atoi(next);
    if ((year < 2010) || (year > 3010))
      return NULL;
    current = current + 4;
    strncpy(next, current, 2);
    next[2] = '\0';
    month = atoi(next);
    if ((month < 1) || (month > 12))
      return NULL;
    current = current + 2;
    strncpy(next, current, 2);
    next[2] = '\0';
    day = atoi(next);
    if ((day < 1) || (day > 31))
      return NULL;
    return calculateFileName(NULL, year, month, day);
  } else
    return NULL;
}


x86 assembly (clang, -O0):
<getFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1288 <getFilename+0x148>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x8,%eax
jne    1288 <getFilename+0x148>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x1e(%rbp)
lea    -0x22(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x7da,-0x28(%rbp)
jl     11c2 <getFilename+0x82>
cmpl   $0xbc2,-0x28(%rbp)
jle    11cf <getFilename+0x8f>
movq   $0x0,-0x8(%rbp)
jmp    1290 <getFilename+0x150>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x20(%rbp)
lea    -0x22(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jl     1211 <getFilename+0xd1>
cmpl   $0xc,-0x2c(%rbp)
jle    121e <getFilename+0xde>
movq   $0x0,-0x8(%rbp)
jmp    1290 <getFilename+0x150>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x20(%rbp)
lea    -0x22(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x1,-0x30(%rbp)
jl     1260 <getFilename+0x120>
cmpl   $0x1f,-0x30(%rbp)
jle    126d <getFilename+0x12d>
movq   $0x0,-0x8(%rbp)
jmp    1290 <getFilename+0x150>
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
call   1050 <calculateFileName@plt>
mov    %rax,-0x8(%rbp)
jmp    1290 <getFilename+0x150>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFilename>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     11f5 <getFilename+0xb5>
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x8,%eax
jne    11f5 <getFilename+0xb5>
lea    0xe(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x12(%rsp)
mov    %r14,%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
lea    -0xbc3(%r14),%eax
cmp    $0xfffffc17,%eax
jb     11f5 <getFilename+0xb5>
lea    0x4(%rbx),%rsi
lea    0xe(%rsp),%r15
mov    %r15,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x10(%rsp)
mov    %r15,%rdi
call   1060 <atoi@plt>
mov    %eax,%r15d
lea    -0xd(%r15),%eax
cmp    $0xfffffff4,%eax
jb     11f5 <getFilename+0xb5>
add    $0x6,%rbx
lea    0xe(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x10(%rsp)
mov    %r12,%rdi
call   1060 <atoi@plt>
lea    -0x20(%rax),%ecx
cmp    $0xffffffe1,%ecx
jae    1203 <getFilename+0xc3>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %edi,%edi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %eax,%ecx
call   1050 <calculateFileName@plt>
jmp    11f7 <getFilename+0xb7>

LLVM IR (-O0):
define i8* @getFilename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [10 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %64
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = icmp eq i32 %13, 8
br i1 %14, label %15, label %64
15: ; preds = %11
%16 = load i8*, i8** %3
store i8* %16, i8** %4
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = call i32 @strncpy(i8* %17, i8* %18, i32 4)
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 4
store i8 0, i8* %20
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 2010
br i1 %24, label %28, label %25
25: ; preds = %15
%26 = load i32, i32* %6
%27 = icmp sgt i32 %26, 3010
br i1 %27, label %28, label %29
28: ; preds = %25, %15
store i8* null, i8** %2
br label %65
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 4
store i8* %31, i8** %4
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%33 = load i8*, i8** %4
%34 = call i32 @strncpy(i8* %32, i8* %33, i32 2)
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 2
store i8 0, i8* %35
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 1
br i1 %39, label %43, label %40
40: ; preds = %29
%41 = load i32, i32* %7
%42 = icmp sgt i32 %41, 12
br i1 %42, label %43, label %44
43: ; preds = %40, %29
store i8* null, i8** %2
br label %65
44: ; preds = %40
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i64 2
store i8* %46, i8** %4
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%48 = load i8*, i8** %4
%49 = call i32 @strncpy(i8* %47, i8* %48, i32 2)
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 2
store i8 0, i8* %50
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%52 = call i32 @atoi(i8* %51)
store i32 %52, i32* %8
%53 = load i32, i32* %8
%54 = icmp slt i32 %53, 1
br i1 %54, label %58, label %55
55: ; preds = %44
%56 = load i32, i32* %8
%57 = icmp sgt i32 %56, 31
br i1 %57, label %58, label %59
58: ; preds = %55, %44
store i8* null, i8** %2
br label %65
59: ; preds = %55
%60 = load i32, i32* %6
%61 = load i32, i32* %7
%62 = load i32, i32* %8
%63 = call i8* @calculateFileName(i32* null, i32 %60, i32 %61, i32 %62)
store i8* %63, i8** %2
br label %65
64: ; preds = %11, %1
store i8* null, i8** %2
br label %65
65: ; preds = %64, %59, %58, %43, %28
%66 = load i8*, i8** %2
ret i8* %66
}

LLVM IR (-O2):
define i8* @getFilename(i8* %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %29, label %5
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 8
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = call i32 @strncpy(i8* %3, i8* %0, i32 4)
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 4
store i8 0, i8* %10
%11 = call i32 @atoi(i8* %3)
%12 = add i32 %11, -3011
%13 = icmp ult i32 %12, -1001
br i1 %13, label %29, label %14
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %0, i64 4
%16 = call i32 @strncpy(i8* %3, i8* %15, i32 2)
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 2
store i8 0, i8* %17
%18 = call i32 @atoi(i8* %3)
%19 = add i32 %18, -13
%20 = icmp ult i32 %19, -12
br i1 %20, label %29, label %21
21: ; preds = %14
%22 = getelementptr inbounds i8, i8* %0, i64 6
%23 = call i32 @strncpy(i8* %3, i8* %22, i32 2)
store i8 0, i8* %17
%24 = call i32 @atoi(i8* %3)
%25 = add i32 %24, -32
%26 = icmp ult i32 %25, -31
br i1 %26, label %29, label %27
27: ; preds = %21
%28 = call i8* @calculateFileName(i32* null, i32 %11, i32 %18, i32 %24)
br label %29
29: ; preds = %1, %5, %21, %14, %8, %27
%30 = phi i8* [ %28, %27 ], [ null, %8 ], [ null, %14 ], [ null, %21 ], [ null, %5 ], [ null, %1 ]
ret i8* %30
}