#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 scalar_t__ time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct tm *localtime(scalar_t__ *);
int /*<<< orphan*/ stderr;
int strftime(char *, int, char *, struct tm *);
scalar_t__ time(int /*<<< orphan*/ *);
void get_current_time_formatted(char *formatted_time, int len) {
  bzero(formatted_time, len);
  time_t currtime = time(NULL);
  if (currtime == ((time_t)-1)) {
    fprintf(stderr, "Error: time(3) had an error."
                    "Log file will have invalid date time string.\n");
  }
  struct tm *timeinfo = localtime(&currtime);
  int x = strftime(formatted_time, len, "%a %b %d %T %Z %Y", timeinfo);
  if (x == 0) {
    fprintf(stderr, "Error: strftime failed.\n");
  }
}


x86 assembly (clang, -O0):
<get_current_time_formatted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <bzero@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    1198 <get_current_time_formatted+0x48>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
lea    -0x18(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
lea    0xe93(%rip),%rdx
call   1060 <strftime@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11de <get_current_time_formatted+0x8e>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_current_time_formatted>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1070 <bzero@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %rax,(%rsp)
cmp    $0xffffffffffffffff,%rax
jne    1183 <get_current_time_formatted+0x33>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1040 <fprintf@plt>
mov    %rsp,%rdi
call   1030 <localtime@plt>
lea    0xeb8(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
test   %eax,%eax
jne    11b8 <get_current_time_formatted+0x68>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@stderr = global i32 0
@.str = [74 x i8] c"Error: time(3) had an error.Log file will have invalid date time string.\0A\00"
@.str.1 = [18 x i8] c"%a %b %d %T %Z %Y\00"
@.str.2 = [25 x i8] c"Error: strftime failed.\0A\00"
define void @get_current_time_formatted(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca %struct.tm*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = load i32, i32* %4
%10 = call i32 @bzero(i8* %8, i32 %9)
%11 = call i64 @time(i32* null)
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = icmp eq i64 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %14, %2
%18 = call %struct.tm* @localtime(i64* %5)
store %struct.tm* %18, %struct.tm** %6
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = load %struct.tm*, %struct.tm** %6
%22 = call i32 @strftime(i8* %19, i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %25, %17
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@stderr = global i32 0
@.str = [74 x i8] c"Error: time(3) had an error.Log file will have invalid date time string.\0A\00"
@.str.1 = [18 x i8] c"%a %b %d %T %Z %Y\00"
@.str.2 = [25 x i8] c"Error: strftime failed.\0A\00"
define void @get_current_time_formatted(i8* %0, i32 %1) {
%3 = alloca i64
%4 = tail call i32 @bzero(i8* %0, i32 %1)
%5 = bitcast i64* %3 to i8*
%6 = tail call i64 @time(i32* null)
store i64 %6, i64* %3
%7 = icmp eq i64 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %2
%12 = call %struct.tm* @localtime(i64* %3)
%13 = call i32 @strftime(i8* %0, i32 %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %15, %11
ret void
}