#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 /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *, int, int,
                           float, int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void generate_filename(char *filename, const char *results_dir_name,
                       int runs_per_test, float interval) {
  time_t today;
  struct tm *tmp = NULL;
  char timestr[16];
  FILE *test = NULL;
  int count = 1;
  today = time(NULL);
  tmp = localtime(&today);
  if (tmp == NULL) {
    perror("localtime");
    return;
  }
  strftime(timestr, 16, "%Y.%m.%d", tmp);
  do {
    sprintf(filename, "%s/%s-Results-Ping6_%d_%d_%f-%d.txt", results_dir_name,
            timestr, 1, runs_per_test, interval, count++);
  } while ((test = fopen(filename, "r")) != NULL);
  if (test != NULL) {
    fclose(test);
  }
}


x86 assembly (clang, -O0):
<generate_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movss  %xmm0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d4 <generate_filename+0x64>
lea    0xe36(%rip),%rdi
call   1080 <perror@plt>
jmp    1254 <generate_filename+0xe4>
lea    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x10,%esi
lea    0xe22(%rip),%rdx
call   1060 <strftime@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x40(%rbp),%rcx
mov    -0x14(%rbp),%r9d
movss  -0x18(%rbp),%xmm0
mov    -0x4c(%rbp),%eax
mov    %eax,%esi
add    $0x1,%esi
mov    %esi,-0x4c(%rbp)
lea    0xdff(%rip),%rsi
mov    $0x1,%r8d
mov    %eax,(%rsp)
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    11ed <generate_filename+0x7d>
cmpq   $0x0,-0x48(%rbp)
je     1254 <generate_filename+0xe4>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_filename>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movss  %xmm0,0x8(%rsp)
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1219 <generate_filename+0xb9>
lea    0xe68(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
mov    %rax,%rcx
call   1050 <strftime@plt>
mov    $0x1,%r15d
lea    0xe52(%rip),%r12
lea    0xe6f(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %r15d,(%rsp)
add    $0x1,%r15d
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
lea    0x10(%rsp),%rcx
mov    $0x1,%r8d
mov    %r14d,%r9d
movss  0x8(%rsp),%xmm0
call   1080 <sprintf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11d0 <generate_filename+0x70>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde0(%rip),%rdi
call   1070 <perror@plt>
jmp    120a <generate_filename+0xaa>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [10 x i8] c"localtime\00"
@.str.1 = [9 x i8] c"%Y.%m.%d\00"
@.str.2 = [36 x i8] c"%s/%s-Results-Ping6_%d_%d_%f-%d.txt\00"
@.str.3 = [2 x i8] c"r\00"
define void @generate_filename(i8* %0, i8* %1, i32 %2, float %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca float
%9 = alloca i32
%10 = alloca %struct.tm*
%11 = alloca [16 x i8]
%12 = alloca i32*
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store float %3, float* %8
store %struct.tm* null, %struct.tm** %10
store i32* null, i32** %12
store i32 1, i32* %13
%14 = call i32 @time(i32* null)
store i32 %14, i32* %9
%15 = call %struct.tm* @localtime(i32* %9)
store %struct.tm* %15, %struct.tm** %10
%16 = load %struct.tm*, %struct.tm** %10
%17 = icmp eq %struct.tm* %16, null
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %43
20: ; preds = %4
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%22 = load %struct.tm*, %struct.tm** %10
%23 = call i32 @strftime(i8* %21, i32 16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %22)
br label %24
24: ; preds = %33, %20
%25 = load i8*, i8** %5
%26 = load i8*, i8** %6
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%28 = load i32, i32* %7
%29 = load float, float* %8
%30 = load i32, i32* %13
%31 = add nsw i32 %30, 1
store i32 %31, i32* %13
%32 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %27, i32 1, i32 %28, float %29, i32 %30)
br label %33
33: ; preds = %24
%34 = load i8*, i8** %5
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %35, i32** %12
%36 = icmp ne i32* %35, null
br i1 %36, label %24, label %37
37: ; preds = %33
%38 = load i32*, i32** %12
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32*, i32** %12
%42 = call i32 @fclose(i32* %41)
br label %43
43: ; preds = %18, %40, %37
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [10 x i8] c"localtime\00"
@.str.1 = [9 x i8] c"%Y.%m.%d\00"
@.str.2 = [36 x i8] c"%s/%s-Results-Ping6_%d_%d_%f-%d.txt\00"
@.str.3 = [2 x i8] c"r\00"
define void @generate_filename(i8* nocapture %0, i8* %1, i32 %2, float %3) {
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = bitcast i32* %5 to i8*
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%9 = tail call i32 @time(i32* null)
store i32 %9, i32* %5
%10 = call %struct.tm* @localtime(i32* %5)
%11 = icmp eq %struct.tm* %10, null
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %22
14: ; preds = %4
%15 = call i32 @strftime(i8* %8, i32 16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %10)
br label %16
16: ; preds = %16, %14
%17 = phi i32 [ 1, %14 ], [ %18, %16 ]
%18 = add nuw nsw i32 %17, 1
%19 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %8, i32 1, i32 %2, float %3, i32 %17)
%20 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %16
22: ; preds = %16, %12
ret void
}