#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 */
char *asctime(struct tm *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
char *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void log_message(const char *message) {
  FILE *fptr = NULL;
  char *log_str = NULL;
  size_t size = -1;
  time_t cur_time = time(NULL);
  struct tm *local_tm = localtime(&cur_time);
  char *time_str = asctime(local_tm);
  if ((fptr = fopen("/tmp/leetcode.log", "a")) == NULL)
    return;
  size = strlen(time_str) + strlen(message) + 2;
  printf("%s\n", time_str);
  printf("%d\n", strlen(time_str));
  if ((log_str = malloc(size)) == NULL) {
    fclose(fptr);
    fptr = NULL;
    return;
  }
  sprintf(log_str, "%s %s\n\n", time_str, message);
  printf("%s\n", log_str);
  printf("%d\n", strlen(log_str));
  fwrite(log_str, sizeof(char), strlen(log_str), fptr);
  fflush(fptr);
  fclose(fptr);
  fptr = NULL;
  free(log_str);
  log_str = NULL;
}


x86 assembly (clang, -O0):
<log_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0xffffffffffffffff,-0x20(%rbp)
ff
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <asctime@plt>
mov    %rax,-0x38(%rbp)
lea    0xdef(%rip),%rdi
lea    0xdfa(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1230 <log_message+0x70>
jmp    1340 <log_message+0x180>
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%esi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    12ad <log_message+0xed>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x10(%rbp)
jmp    1340 <log_message+0x180>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xd5c(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x18(%rbp),%rsi
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%esi
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_message>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1040 <localtime@plt>
mov    %rax,%rdi
call   1080 <asctime@plt>
mov    %rax,%r12
lea    0xdfe(%rip),%rdi
lea    0xe09(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12d5 <log_message+0x105>
mov    %rax,%r15
mov    %r12,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1070 <strlen@plt>
add    %ebx,%eax
add    $0x2,%eax
movslq %eax,%rbx
mov    %r12,%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
call   1070 <strlen@plt>
lea    0xdc9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
call   10b0 <malloc@plt>
test   %rax,%rax
je     12cd <log_message+0xfd>
mov    %rax,%rbx
lea    0xdad(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r14,%rcx
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
lea    0xd84(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   10f0 <fwrite@plt>
mov    %r15,%rdi
call   10c0 <fflush@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    12d5 <log_message+0x105>
mov    %r15,%rdi
call   1060 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [18 x i8] c"/tmp/leetcode.log\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [8 x i8] c"%s %s\0A\0A\00"
define void @log_message(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.tm*
%8 = alloca i8*
store i8* %0, i8** %2
store i32* null, i32** %3
store i8* null, i8** %4
store i64 -1, i64* %5
%9 = call i32 @time(i32* null)
store i32 %9, i32* %6
%10 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %10, %struct.tm** %7
%11 = load %struct.tm*, %struct.tm** %7
%12 = call i8* @asctime(%struct.tm* %11)
store i8* %12, i8** %8
%13 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %3
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %1
br label %56
16: ; preds = %1
%17 = load i8*, i8** %8
%18 = call i32 @strlen(i8* %17)
%19 = load i8*, i8** %2
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %18, %20
%22 = add nsw i32 %21, 2
%23 = sext i32 %22 to i64
store i64 %23, i64* %5
%24 = load i8*, i8** %8
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %8
%27 = call i32 @strlen(i8* %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i64, i64* %5
%30 = call i8* @malloc(i64 %29)
store i8* %30, i8** %4
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %16
%33 = load i32*, i32** %3
%34 = call i32 @fclose(i32* %33)
store i32* null, i32** %3
br label %56
35: ; preds = %16
%36 = load i8*, i8** %4
%37 = load i8*, i8** %8
%38 = load i8*, i8** %2
%39 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %37, i8* %38)
%40 = load i8*, i8** %4
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = load i8*, i8** %4
%43 = call i32 @strlen(i8* %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = load i8*, i8** %4
%46 = load i8*, i8** %4
%47 = call i32 @strlen(i8* %46)
%48 = load i32*, i32** %3
%49 = call i32 @fwrite(i8* %45, i32 1, i32 %47, i32* %48)
%50 = load i32*, i32** %3
%51 = call i32 @fflush(i32* %50)
%52 = load i32*, i32** %3
%53 = call i32 @fclose(i32* %52)
store i32* null, i32** %3
%54 = load i8*, i8** %4
%55 = call i32 @free(i8* %54)
store i8* null, i8** %4
br label %56
56: ; preds = %35, %32, %15
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [18 x i8] c"/tmp/leetcode.log\00"
@.str.1 = [2 x i8] c"a\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [8 x i8] c"%s %s\0A\0A\00"
define void @log_message(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @time(i32* null)
store i32 %4, i32* %2
%5 = call %struct.tm* @localtime(i32* %2)
%6 = call i8* @asctime(%struct.tm* %5)
%7 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %32, label %9
9: ; preds = %1
%10 = call i32 @strlen(i8* %6)
%11 = call i32 @strlen(i8* %0)
%12 = add i32 %10, 2
%13 = add i32 %12, %11
%14 = sext i32 %13 to i64
%15 = call i32 @puts(i8* dereferenceable(1) %6)
%16 = call i32 @strlen(i8* %6)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = call i8* @malloc(i64 %14)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %9
%21 = call i32 @fclose(i32* %7)
br label %32
22: ; preds = %9
%23 = call i32 @sprintf(i8* %18, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %6, i8* %0)
%24 = call i32 @puts(i8* %18)
%25 = call i32 @strlen(i8* %18)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = call i32 @strlen(i8* %18)
%28 = call i32 @fwrite(i8* %18, i32 1, i32 %27, i32* %7)
%29 = call i32 @fflush(i32* %7)
%30 = call i32 @fclose(i32* %7)
%31 = call i32 @free(i8* %18)
br label %32
32: ; preds = %1, %22, %20
ret void
}