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

/* Variables and functions */
scalar_t__ calloc(int, int);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *get_logname(void) {
  time_t clocker;
  struct tm *tm;
  char buf[10], bufs[10], *p;
  time(&clocker);
  tm = localtime(&clocker);
  strftime(buf, sizeof(buf), "%Y%W", tm);
  sprintf(bufs, "%s", buf);
  p = (char *)calloc(sizeof(char), 10);
  strcpy(p, bufs);
  return p;
}


x86 assembly (clang, -O0):
<get_logname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x4(%rbp),%rdi
call   1060 <time@plt>
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1a(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xa,%esi
lea    0xe6e(%rip),%rdx
call   1070 <strftime@plt>
lea    -0x24(%rbp),%rdi
lea    -0x1a(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1080 <sprintf@plt>
mov    $0x1,%edi
mov    $0xa,%esi
call   1050 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_logname>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
lea    0xe8f(%rip),%rdx
lea    0xe(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %rax,%rcx
call   1070 <strftime@plt>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    $0x1,%edi
mov    $0xa,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [5 x i8] c"%Y%W\00"
@.str.1 = [3 x i8] c"%s\00"
define i8* @get_logname() {
%1 = alloca i32
%2 = alloca %struct.tm*
%3 = alloca [10 x i8]
%4 = alloca [10 x i8]
%5 = alloca i8*
%6 = call i32 @time(i32* %1)
%7 = call %struct.tm* @localtime(i32* %1)
store %struct.tm* %7, %struct.tm** %2
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%9 = load %struct.tm*, %struct.tm** %2
%10 = call i32 @strftime(i8* %8, i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.tm* %9)
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i64 @calloc(i32 1, i32 10)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %5
ret i8* %19
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [5 x i8] c"%Y%W\00"
define i8* @get_logname() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca [10 x i8]
%4 = bitcast i32* %1 to i8*
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = call i32 @time(i32* %1)
%8 = call %struct.tm* @localtime(i32* %1)
%9 = call i32 @strftime(i8* %5, i32 10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.tm* %8)
%10 = call i8* bitcast (i32 (i8*, i8*)* @strcpy to i8* (i8*, i8*)*)(i8* %6, i8* %5)
%11 = call i64 @calloc(i32 1, i32 10)
%12 = inttoptr i64 %11 to i8*
%13 = call i32 @strcpy(i8* %12, i8* %6)
ret i8* %12
}