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

/* Variables and functions */
char *ctime(int *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int time(int /*<<< orphan*/ *);
void log_msg(FILE *f, char *msg) {
  time_t time_sec;
  char *buf;
  char *fmsg;
  time_sec = time(NULL);
  if (time_sec != -1) {
    buf = ctime(&time_sec);
    buf[strlen(buf) - 1] = ' ';
  } else {
    fprintf(f, "time error ! \n");
    fflush(f);
    exit(-1);
  }
  fmsg = malloc(strlen(buf) + 1 + strlen(msg) + 1);
  if (fmsg == NULL) {
    fprintf(f, "server: malloc %d failed \n",
            (int)(strlen(buf) + 1 + strlen(msg) + 1));
    exit(-1);
  }
  strcpy(fmsg, buf);
  fmsg = strcat(fmsg, msg);
  fprintf(f, fmsg);
  fflush(f);
  free(fmsg);
}


x86 assembly (clang, -O0):
<log_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     11f9 <log_msg+0x59>
lea    -0x14(%rbp),%rdi
call   1050 <ctime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    121e <log_msg+0x7e>
mov    -0x8(%rbp),%rdi
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <fflush@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x34(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1296 <log_msg+0xf6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x44(%rbp),%edx
mov    -0x40(%rbp),%rdi
add    %eax,%edx
add    $0x1,%edx
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <strcat@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <fflush@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_msg>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0x4(%rsp)
cmp    $0xffffffff,%eax
je     1253 <log_msg+0xa3>
lea    0x4(%rsp),%rdi
call   1050 <ctime@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x20,-0x1(%rax,%r12,1)
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     127e <log_msg+0xce>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   10a0 <fflush@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xda6(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10d0 <fwrite@plt>
mov    %r14,%rdi
call   10a0 <fflush@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    (%rbx,%rax,1),%edx
add    $0x2,%edx
lea    0xd72(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"time error ! \0A\00"
@.str.1 = [27 x i8] c"server: malloc %d failed \0A\00"
define void @log_msg(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
%8 = call i32 @time(i32* null)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = call i8* @ctime(i32* %5)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %13, i64 %17
store i8 32, i8* %18
br label %25
19: ; preds = %2
%20 = load i32*, i32** %3
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%22 = load i32*, i32** %3
%23 = call i32 @fflush(i32* %22)
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %11
%26 = load i8*, i8** %6
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %27, 1
%29 = load i8*, i8** %4
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %28, %30
%32 = add nsw i32 %31, 1
%33 = call i8* @malloc(i32 %32)
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %47
36: ; preds = %25
%37 = load i32*, i32** %3
%38 = load i8*, i8** %6
%39 = call i32 @strlen(i8* %38)
%40 = add nsw i32 %39, 1
%41 = load i8*, i8** %4
%42 = call i32 @strlen(i8* %41)
%43 = add nsw i32 %40, %42
%44 = add nsw i32 %43, 1
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = call i32 @exit(i32 -1)
unreachable
47: ; preds = %25
%48 = load i8*, i8** %7
%49 = load i8*, i8** %6
%50 = call i32 @strcpy(i8* %48, i8* %49)
%51 = load i8*, i8** %7
%52 = load i8*, i8** %4
%53 = call i8* @strcat(i8* %51, i8* %52)
store i8* %53, i8** %7
%54 = load i32*, i32** %3
%55 = load i8*, i8** %7
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* %55)
%57 = load i32*, i32** %3
%58 = call i32 @fflush(i32* %57)
%59 = load i8*, i8** %7
%60 = call i32 @free(i8* %59)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"time error ! \0A\00"
@.str.1 = [27 x i8] c"server: malloc %d failed \0A\00"
define void @log_msg(i32* nocapture %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %3
%6 = icmp eq i32 %5, -1
br i1 %6, label %19, label %7
7: ; preds = %2
%8 = call i8* @ctime(i32* %3)
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
store i8 32, i8* %12
%13 = call i32 @strlen(i8* %8)
%14 = call i32 @strlen(i8* %1)
%15 = add i32 %13, 2
%16 = add i32 %15, %14
%17 = call i8* @malloc(i32 %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %23, label %30
19: ; preds = %2
%20 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 14, i64 1, i32* %0)
%21 = tail call i32 @fflush(i32* %0)
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %7
%24 = call i32 @strlen(i8* %8)
%25 = call i32 @strlen(i8* %1)
%26 = add i32 %24, 2
%27 = add i32 %26, %25
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %7
%31 = call i32 @strcpy(i8* %17, i8* %8)
%32 = call i8* @strcat(i8* %17, i8* dereferenceable(1) %1)
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* %17)
%34 = call i32 @fflush(i32* %0)
%35 = call i32 @free(i8* %17)
ret void
}