#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 */
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int, int, int);
int strlen(char *);
char *calculateFileName(char *current, int year, int month, int day) {
  int len = strlen("/var/log/safed") + 14;
  char *filename = (char *)realloc(current, strlen("/var/log/safed") + 14);
  if (month < 10) {
    if (day < 10) {
      snprintf(filename, len, "%s/%d0%d0%d.log", "/var/log/safed", year, month,
               day);
    } else {
      snprintf(filename, len, "%s/%d0%d%d.log", "/var/log/safed", year, month,
               day);
    }
  } else {
    if (day < 10) {
      snprintf(filename, len, "%s/%d%d0%d.log", "/var/log/safed", year, month,
               day);
    } else {
      snprintf(filename, len, "%s/%d%d%d.log", "/var/log/safed", year, month,
               day);
    }
  }
  return filename;
}


x86 assembly (clang, -O0):
<calculateFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    0xeb4(%rip),%rdi
call   1030 <strlen@plt>
add    $0xe,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
add    $0xe,%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    11eb <calculateFileName+0xbb>
cmpl   $0xa,-0x14(%rbp)
jge    11be <calculateFileName+0x8e>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
mov    -0x14(%rbp),%eax
lea    0xe65(%rip),%rdx
lea    0xe4f(%rip),%rcx
mov    %eax,(%rsp)
call   1040 <snprintf@plt>
jmp    11e6 <calculateFileName+0xb6>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
mov    -0x14(%rbp),%eax
lea    0xe48(%rip),%rdx
lea    0xe22(%rip),%rcx
mov    %eax,(%rsp)
call   1040 <snprintf@plt>
jmp    124f <calculateFileName+0x11f>
cmpl   $0xa,-0x14(%rbp)
jge    1222 <calculateFileName+0xf2>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
mov    -0x14(%rbp),%eax
lea    0xe20(%rip),%rdx
lea    0xdeb(%rip),%rcx
mov    %eax,(%rsp)
call   1040 <snprintf@plt>
jmp    124a <calculateFileName+0x11a>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
mov    -0x14(%rbp),%eax
lea    0xe02(%rip),%rdx
lea    0xdbe(%rip),%rcx
mov    %eax,(%rsp)
call   1040 <snprintf@plt>
jmp    124f <calculateFileName+0x11f>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateFileName>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %edx,%r12d
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xeb3(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    0xe(%rax),%r13d
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    0xe(%rax),%esi
mov    %rbx,%rdi
call   1050 <realloc@plt>
cmp    $0xa,%ebp
lea    0xe99(%rip),%rcx
lea    0xea2(%rip),%rsi
cmovl  %rcx,%rsi
lea    0xea6(%rip),%rcx
lea    0xeae(%rip),%rdx
cmovl  %rcx,%rdx
mov    %rax,%rbx
cmp    $0xa,%r12d
cmovl  %rsi,%rdx
mov    %ebp,(%rsp)
mov    %rax,%rdi
mov    %r13d,%esi
mov    %r15,%rcx
mov    %r14d,%r8d
mov    %r12d,%r9d
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/var/log/safed\00"
@.str.1 = [16 x i8] c"%s/%d0%d0%d.log\00"
@.str.2 = [15 x i8] c"%s/%d0%d%d.log\00"
@.str.3 = [15 x i8] c"%s/%d%d0%d.log\00"
@.str.4 = [14 x i8] c"%s/%d%d%d.log\00"
define i8* @calculateFileName(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = add nsw i32 %11, 14
store i32 %12, i32* %9
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%15 = add nsw i32 %14, 14
%16 = call i64 @realloc(i8* %13, i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %10
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 10
br i1 %19, label %20, label %38
20: ; preds = %4
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 10
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i8*, i8** %10
%25 = load i32, i32* %9
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = call i32 @snprintf(i8* %24, i32 %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %27, i32 %28)
br label %37
30: ; preds = %20
%31 = load i8*, i8** %10
%32 = load i32, i32* %9
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = call i32 @snprintf(i8* %31, i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %34, i32 %35)
br label %37
37: ; preds = %30, %23
br label %56
38: ; preds = %4
%39 = load i32, i32* %8
%40 = icmp slt i32 %39, 10
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = load i8*, i8** %10
%43 = load i32, i32* %9
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = load i32, i32* %8
%47 = call i32 @snprintf(i8* %42, i32 %43, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %44, i32 %45, i32 %46)
br label %55
48: ; preds = %38
%49 = load i8*, i8** %10
%50 = load i32, i32* %9
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = load i32, i32* %8
%54 = call i32 @snprintf(i8* %49, i32 %50, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %51, i32 %52, i32 %53)
br label %55
55: ; preds = %48, %41
br label %56
56: ; preds = %55, %37
%57 = load i8*, i8** %10
ret i8* %57
}

LLVM IR (-O2):
@.str = [15 x i8] c"/var/log/safed\00"
@.str.1 = [16 x i8] c"%s/%d0%d0%d.log\00"
@.str.2 = [15 x i8] c"%s/%d0%d%d.log\00"
@.str.3 = [15 x i8] c"%s/%d%d0%d.log\00"
@.str.4 = [14 x i8] c"%s/%d%d%d.log\00"
define i8* @calculateFileName(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = add nsw i32 %5, 14
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = add nsw i32 %7, 14
%9 = tail call i64 @realloc(i8* %0, i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = icmp slt i32 %2, 10
%12 = icmp slt i32 %3, 10
%13 = select i1 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0)
%14 = select i1 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0)
%15 = select i1 %11, i8* %13, i8* %14
%16 = tail call i32 @snprintf(i8* %10, i32 %6, i8* %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2, i32 %3)
ret i8* %10
}