#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*/ tmstr;
typedef scalar_t__ time_t;
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ path;

/* Variables and functions */
scalar_t__ get_time();
int /*<<< orphan*/ localtime(scalar_t__ *);
int mkdir(char *, int);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *, ...);
int stat(char *, struct stat *);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int get_log_path(char *buf, size_t buf_len) {
  time_t tm = get_time();
  char tmstr[32];
  strftime(tmstr, sizeof(tmstr), "%Y-%m-%d", localtime(&tm));
  char path[strlen("../crawler_logs") + strlen(tmstr) + 3];
  snprintf(path, sizeof(path), "%s/%s/", "../crawler_logs", tmstr);
  struct stat st;
  if (stat("../crawler_logs", &st) == -1) {
    if (mkdir("../crawler_logs", 0700) == -1) {
      return -1;
    }
  }
  if (stat(path, &st) == -1) {
    if (mkdir(path, 0700) == -1) {
      return -1;
    }
  }
  snprintf(buf, buf_len, "%s/%llu.cwl", path, (long long unsigned)tm);
  return 0;
}


x86 assembly (clang, -O0):
<get_log_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
call   1070 <get_time@plt>
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <localtime@plt>
mov    %eax,%ecx
lea    0xe60(%rip),%rdx
lea    -0x40(%rbp),%rdi
mov    %rdi,-0x78(%rbp)
mov    $0x20,%esi
call   1090 <strftime@plt>
lea    0xe50(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    %rax,-0x70(%rbp)
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
lea    0x3(%rax,%rcx,1),%rsi
mov    %rsp,%rdx
mov    %rdx,-0x48(%rbp)
lea    0x12(%rax,%rcx,1),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rdi
sub    %rax,%rdi
mov    %rdi,-0x68(%rbp)
mov    %rdi,%rsp
mov    %rsi,-0x50(%rbp)
lea    -0x40(%rbp),%r8
lea    0xe16(%rip),%rdx
lea    0xdff(%rip),%rcx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    0xdf1(%rip),%rdi
lea    -0x58(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    125c <get_log_path+0xec>
lea    0xdd8(%rip),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1257 <get_log_path+0xe7>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    12cd <get_log_path+0x15d>
jmp    125c <get_log_path+0xec>
mov    -0x68(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    12a1 <get_log_path+0x131>
mov    -0x68(%rbp),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    129c <get_log_path+0x12c>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    12cd <get_log_path+0x15d>
jmp    12a1 <get_log_path+0x131>
mov    -0x68(%rbp),%rcx
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%r8
lea    0xd68(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_log_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,-0x40(%rbp)
mov    %rdi,%r15
xor    %eax,%eax
call   1070 <get_time@plt>
mov    %rax,-0x38(%rbp)
lea    -0x38(%rbp),%rdi
call   1030 <localtime@plt>
lea    0xe5d(%rip),%rdx
lea    -0x60(%rbp),%r12
mov    %r12,%rdi
mov    $0x20,%esi
mov    %eax,%ecx
call   1090 <strftime@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rsp,%r14
lea    0x12(%rax),%rsi
mov    %rsp,%rbx
add    $0x21,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe3c(%rip),%rdx
lea    0xe25(%rip),%r13
mov    %rbx,%rdi
mov    %r13,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
lea    -0x30(%rbp),%rsi
mov    %r13,%rdi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    121b <get_log_path+0xab>
lea    0xdfd(%rip),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
je     125f <get_log_path+0xef>
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    123e <get_log_path+0xce>
mov    %rbx,%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
je     125f <get_log_path+0xef>
mov    -0x38(%rbp),%r8
lea    0xdd7(%rip),%rdx
xor    %r12d,%r12d
mov    %r15,%rdi
mov    -0x40(%rbp),%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
jmp    1265 <get_log_path+0xf5>
mov    $0xffffffff,%r12d
mov    %r14,%rsp
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [9 x i8] c"%Y-%m-%d\00"
@.str.1 = [16 x i8] c"../crawler_logs\00"
@.str.2 = [7 x i8] c"%s/%s/\00"
@.str.3 = [12 x i8] c"%s/%llu.cwl\00"
define i32 @get_log_path(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca [32 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.stat
%11 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%12 = call i64 (...) @get_time()
store i64 %12, i64* %6
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%14 = call i32 @localtime(i64* %6)
%15 = call i32 @strftime(i8* %13, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i64 @strlen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %16, %18
%20 = add nsw i64 %19, 3
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %8
%22 = alloca i8, i64 %20
store i64 %20, i64* %9
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%24 = call i32 (i8*, i64, i8*, i8*, ...) @snprintf(i8* %22, i64 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = call i32 @stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %10)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %32
27: ; preds = %2
%28 = call i32 @mkdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 448)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 -1, i32* %3
store i32 1, i32* %11
br label %45
31: ; preds = %27
br label %32
32: ; preds = %31, %2
%33 = call i32 @stat(i8* %22, %struct.stat* %10)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = call i32 @mkdir(i8* %22, i32 448)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 -1, i32* %3
store i32 1, i32* %11
br label %45
39: ; preds = %35
br label %40
40: ; preds = %39, %32
%41 = load i8*, i8** %4
%42 = load i64, i64* %5
%43 = load i64, i64* %6
%44 = call i32 (i8*, i64, i8*, i8*, ...) @snprintf(i8* %41, i64 %42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %22, i64 %43)
store i32 0, i32* %3
store i32 1, i32* %11
br label %45
45: ; preds = %40, %38, %30
%46 = load i8*, i8** %8
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [9 x i8] c"%Y-%m-%d\00"
@.str.1 = [16 x i8] c"../crawler_logs\00"
@.str.2 = [7 x i8] c"%s/%s/\00"
@.str.3 = [12 x i8] c"%s/%llu.cwl\00"
define i32 @get_log_path(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca [32 x i8]
%5 = alloca %struct.stat
%6 = bitcast i64* %3 to i8*
%7 = tail call i64 (...) @get_time()
store i64 %7, i64* %3
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%9 = call i32 @localtime(i64* %3)
%10 = call i32 @strftime(i8* %8, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i64 @strlen(i8* %8)
%12 = add nsw i64 %11, 18
%13 = call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = call i32 (i8*, i64, i8*, i8*, ...) @snprintf(i8* %14, i64 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%16 = bitcast %struct.stat* %5 to i8*
%17 = call i32 @stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %5)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 @mkdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 448)
%21 = icmp eq i32 %20, -1
br i1 %21, label %31, label %22
22: ; preds = %19, %2
%23 = call i32 @stat(i8* %14, %struct.stat* %5)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = call i32 @mkdir(i8* %14, i32 448)
%27 = icmp eq i32 %26, -1
br i1 %27, label %31, label %28
28: ; preds = %25, %22
%29 = load i64, i64* %3
%30 = call i32 (i8*, i64, i8*, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %14, i64 %29)
br label %31
31: ; preds = %25, %19, %28
%32 = phi i32 [ 0, %28 ], [ -1, %19 ], [ -1, %25 ]
ret i32 %32
}