#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char const *,
                           char const *);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void log(const char *msg1, const char *msg2) {
  time_t t;
  char *ct;
  FILE *log;
  time(&t);
  ct = ctime(&t);
  ct[strlen(ct) - 1] = 0;
  log = fopen("java.log.txt", "a");
  if (log == 0) {
    printf("*** Unable to open java.log.txt ! ***");
    return;
  }
  fprintf(log, "[%s] %s%s\n", ct, msg1, msg2);
  fclose(log);
}


x86 assembly (clang, -O0):
<log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1080 <time@plt>
lea    -0x14(%rbp),%rdi
call   1040 <ctime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xe42(%rip),%rdi
lea    0xe48(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ea <log+0x7a>
lea    0xe2f(%rip),%rdi
call   1060 <printf@plt>
jmp    120f <log+0x9f>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe34(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <time@plt>
mov    %rbx,%rdi
call   1040 <ctime@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
lea    0xe53(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11e3 <log+0x73>
mov    %rax,%rbx
lea    0xe6d(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11ef <log+0x7f>
lea    0xe25(%rip),%rdi
call   1060 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"java.log.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [38 x i8] c"*** Unable to open java.log.txt ! ***\00"
@.str.3 = [11 x i8] c"[%s] %s%s\0A\00"
define void @log(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = call i32 @time(i32* %5)
%9 = call i8* @ctime(i32* %5)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
store i8 0, i8* %15
%16 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %29
21: ; preds = %2
%22 = load i32*, i32** %7
%23 = load i8*, i8** %6
%24 = load i8*, i8** %3
%25 = load i8*, i8** %4
%26 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %23, i8* %24, i8* %25)
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
br label %29
29: ; preds = %21, %19
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"java.log.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [38 x i8] c"*** Unable to open java.log.txt ! ***\00"
@.str.3 = [11 x i8] c"[%s] %s%s\0A\00"
define void @log(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @time(i32* %3)
%6 = call i8* @ctime(i32* %3)
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
store i8 0, i8* %10
%11 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %18
15: ; preds = %2
%16 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* %0, i8* %1)
%17 = call i32 @fclose(i32* %11)
br label %18
18: ; preds = %15, %13
ret void
}