#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 tm_mday;
  int tm_mon;
  int tm_year;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int getpid();
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int, int,
                           char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void log(char *message) {
  FILE *fd;
  char logbuffer[8096 * 2];
  time_t ltime;
  struct tm *Tm;
  ltime = time(NULL);
  Tm = localtime(&ltime);
  (void)sprintf(logbuffer, "%02d/%02d/%04d %02d:%02d:%02d PID %d %s",
                Tm->tm_mday, Tm->tm_mon + 1, Tm->tm_year + 1900, Tm->tm_hour,
                Tm->tm_min, Tm->tm_sec, getpid(), message);
  if ((fd = fopen("/tmp/streamer.log", "a")) != NULL) {
    fprintf(fd, "%s\n", logbuffer);
    fclose(fd);
  }
}


x86 assembly (clang, -O0):
<log>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x3fa8,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x3f64(%rbp)
lea    -0x3f64(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x3f70(%rbp)
lea    -0x3f60(%rbp),%rax
mov    %rax,-0x3f90(%rbp)
mov    -0x3f70(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3f84(%rbp)
mov    -0x3f70(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x1,%eax
mov    %eax,-0x3f80(%rbp)
mov    -0x3f70(%rbp),%rax
mov    0x8(%rax),%eax
add    $0x76c,%eax
mov    %eax,-0x3f7c(%rbp)
mov    -0x3f70(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x3f78(%rbp)
mov    -0x3f70(%rbp),%rax
mov    0x10(%rax),%ebx
mov    -0x3f70(%rbp),%rax
mov    0x14(%rax),%eax
mov    %eax,-0x3f74(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x3f90(%rbp),%rdi
mov    -0x3f84(%rbp),%edx
mov    -0x3f80(%rbp),%ecx
mov    -0x3f7c(%rbp),%r8d
mov    -0x3f78(%rbp),%r9d
mov    -0x3f74(%rbp),%r11d
mov    %eax,%r10d
mov    -0x10(%rbp),%rax
lea    0xdb2(%rip),%rsi
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1090 <sprintf@plt>
lea    0xdbc(%rip),%rdi
lea    0xdc7(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12a6 <log+0x136>
mov    -0x18(%rbp),%rdi
lea    -0x3f60(%rbp),%rdx
lea    0xda4(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x3fa8,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<log>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f58,%rsp
mov    %rdi,0x8(%rsp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%r15d
mov    0x4(%rax),%ebx
mov    $0x76c,%ebp
add    0x8(%rax),%ebp
add    $0x1,%ebx
mov    0xc(%rax),%r12d
mov    0x10(%rax),%r13d
mov    0x14(%rax),%r14d
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe3a(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r12d,%r9d
push   0x8(%rsp)
push   %rax
push   %r14
push   %r13
call   1090 <sprintf@plt>
add    $0x20,%rsp
lea    0xe39(%rip),%rdi
lea    0xe44(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     121f <log+0xaf>
mov    %rax,%rbx
lea    0xe32(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x3f58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [40 x i8] c"%02d/%02d/%04d %02d:%02d:%02d PID %d %s\00"
@.str.1 = [18 x i8] c"/tmp/streamer.log\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @log(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [16192 x i8]
%5 = alloca i32
%6 = alloca %struct.tm*
store i8* %0, i8** %2
%7 = call i32 @time(i32* null)
store i32 %7, i32* %5
%8 = call %struct.tm* @localtime(i32* %5)
store %struct.tm* %8, %struct.tm** %6
%9 = getelementptr inbounds [16192 x i8], [16192 x i8]* %4, i64 0, i64 0
%10 = load %struct.tm*, %struct.tm** %6
%11 = getelementptr inbounds %struct.tm, %struct.tm* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load %struct.tm*, %struct.tm** %6
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
%17 = load %struct.tm*, %struct.tm** %6
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 2
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1900
%21 = load %struct.tm*, %struct.tm** %6
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i32 0, i32 3
%23 = load i32, i32* %22
%24 = load %struct.tm*, %struct.tm** %6
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 4
%26 = load i32, i32* %25
%27 = load %struct.tm*, %struct.tm** %6
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 5
%29 = load i32, i32* %28
%30 = call i32 (...) @getpid()
%31 = load i8*, i8** %2
%32 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %16, i32 %20, i32 %23, i32 %26, i32 %29, i32 %30, i8* %31)
%33 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %3
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %41
35: ; preds = %1
%36 = load i32*, i32** %3
%37 = getelementptr inbounds [16192 x i8], [16192 x i8]* %4, i64 0, i64 0
%38 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i32*, i32** %3
%40 = call i32 @fclose(i32* %39)
br label %41
41: ; preds = %35, %1
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [40 x i8] c"%02d/%02d/%04d %02d:%02d:%02d PID %d %s\00"
@.str.1 = [18 x i8] c"/tmp/streamer.log\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @log(i8* %0) {
%2 = alloca [16192 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [16192 x i8], [16192 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %3
%7 = call %struct.tm* @localtime(i32* %3)
%8 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
%13 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 2
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1900
%16 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 3
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 5
%21 = load i32, i32* %20
%22 = call i32 (...) @getpid()
%23 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %12, i32 %15, i32 %17, i32 %19, i32 %21, i32 %22, i8* %0)
%24 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %1
%27 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%28 = call i32 @fclose(i32* %24)
br label %29
29: ; preds = %26, %1
ret void
}