#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*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ *get_log_file();
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ open_log_file();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void append_log() {
  open_log_file();
  FILE *log_out = get_log_file();
  time_t rawtime;
  time(&rawtime);
  char *array = (char *)malloc(512 * sizeof(char));
  struct tm *timeinfo = localtime(&rawtime);
  strftime(array, 512, "%d.%m.%y_%H:%M:%S", timeinfo);
  if (log_out != NULL) {
    fprintf(log_out, "%s at %s\n", "child process was terminated", array);
    fclose(log_out);
  } else {
    perror("ERROR : cann't open log file");
  }
}


x86 assembly (clang, -O0):
<append_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   10b0 <open_log_file@plt>
mov    $0x0,%al
call   1090 <get_log_file@plt>
mov    %rax,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <time@plt>
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x200,%esi
lea    0xe1e(%rip),%rdx
call   1080 <strftime@plt>
cmpq   $0x0,-0x8(%rbp)
je     121b <append_log+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
lea    0xe11(%rip),%rsi
lea    0xe14(%rip),%rdx
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1227 <append_log+0x97>
lea    0xe17(%rip),%rdi
call   10a0 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_log>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   10b0 <open_log_file@plt>
xor    %eax,%eax
call   1090 <get_log_file@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1060 <time@plt>
mov    $0x200,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <localtime@plt>
lea    0xe2d(%rip),%rdx
mov    %r14,%rdi
mov    $0x200,%esi
mov    %rax,%rcx
call   1080 <strftime@plt>
test   %rbx,%rbx
je     1213 <append_log+0x83>
lea    0xe23(%rip),%rsi
lea    0xe26(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rcx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe1f(%rip),%rdi
call   10a0 <perror@plt>
jmp    1209 <append_log+0x79>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%d.%m.%y_%H:%M:%S\00"
@.str.1 = [10 x i8] c"%s at %s\0A\00"
@.str.2 = [29 x i8] c"child process was terminated\00"
@.str.3 = [29 x i8] c"ERROR : cann't open log file\00"
define void @append_log() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.tm*
%5 = call i32 (...) @open_log_file()
%6 = call i32* (...) @get_log_file()
store i32* %6, i32** %1
%7 = call i32 @time(i32* %2)
%8 = call i64 @malloc(i32 512)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %10, %struct.tm** %4
%11 = load i8*, i8** %3
%12 = load %struct.tm*, %struct.tm** %4
%13 = call i32 @strftime(i8* %11, i32 512, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %12)
%14 = load i32*, i32** %1
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %22
16: ; preds = %0
%17 = load i32*, i32** %1
%18 = load i8*, i8** %3
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32*, i32** %1
%21 = call i32 @fclose(i32* %20)
br label %24
22: ; preds = %0
%23 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [18 x i8] c"%d.%m.%y_%H:%M:%S\00"
@.str.1 = [10 x i8] c"%s at %s\0A\00"
@.str.2 = [29 x i8] c"child process was terminated\00"
@.str.3 = [29 x i8] c"ERROR : cann't open log file\00"
define void @append_log() {
%1 = alloca i32
%2 = tail call i32 (...) @open_log_file()
%3 = tail call i32* (...) @get_log_file()
%4 = bitcast i32* %1 to i8*
%5 = call i32 @time(i32* %1)
%6 = call i64 @malloc(i32 512)
%7 = inttoptr i64 %6 to i8*
%8 = call %struct.tm* @localtime(i32* %1)
%9 = call i32 @strftime(i8* %7, i32 512, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %8)
%10 = icmp eq i32* %3, null
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%13 = call i32 @fclose(i32* %3)
br label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
ret void
}