#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*/ va_list;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timeval {
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ log_write(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
void log_doit(const char *filename, int line, const char *function,
              const char *fmt, va_list args) {
  struct tm tm_now;
  struct timeval tv_now;
  char buff[128];
  gettimeofday(&tv_now, NULL);
  localtime_r(&(tv_now.tv_sec), &tm_now);
  snprintf(buff, sizeof(buff), "[%04d-%02d-%02d %02d:%02d:%02d] ",
           tm_now.tm_year + 1900, tm_now.tm_mon + 1, tm_now.tm_mday,
           tm_now.tm_hour, tm_now.tm_min, tm_now.tm_sec);
  log_write(buff, strlen(buff));
  snprintf(buff, sizeof(buff), "<%s (%s:%d)>: ", filename, function, line);
  log_write(buff, strlen(buff));
  vsnprintf(buff, sizeof(buff), fmt, args);
  while (buff[strlen(buff) - 1] == '\n')
    buff[strlen(buff) - 1] = '\0';
  log_write(buff, strlen(buff));
  log_write("\n", 1);
  fflush(stderr);
}


x86 assembly (clang, -O0):
<log_doit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
lea    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <localtime_r@plt>
lea    -0xd0(%rbp),%rdi
mov    -0x40(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x3c(%rbp),%r8d
add    $0x1,%r8d
mov    -0x38(%rbp),%r9d
mov    -0x34(%rbp),%r11d
mov    -0x30(%rbp),%r10d
mov    -0x2c(%rbp),%eax
mov    $0x80,%esi
lea    0xe25(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0xd0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    -0xd0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xe0(%rbp),%rdi
mov    %eax,%esi
call   1090 <log_write@plt>
lea    -0xd0(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0xc(%rbp),%r9d
mov    $0x80,%esi
lea    0xdeb(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0xd0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0xd0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xd8(%rbp),%rdi
mov    %eax,%esi
call   1090 <log_write@plt>
lea    -0xd0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    $0x80,%esi
call   1040 <vsnprintf@plt>
lea    -0xd0(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0xd0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12bd <log_doit+0x14d>
lea    -0xd0(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0xd0(%rbp,%rax,1)
jmp    127d <log_doit+0x10d>
lea    -0xd0(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    -0xd0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xe8(%rbp),%rdi
mov    %eax,%esi
call   1090 <log_write@plt>
lea    0xd44(%rip),%rdi
mov    $0x1,%esi
call   1090 <log_write@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_doit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %r8d,0xc(%rsp)
mov    %rcx,%r15
mov    %rdx,%r12
mov    %esi,%r13d
mov    %rdi,%r14
lea    0x28(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
lea    0x10(%rsp),%rsi
mov    %rbp,%rdi
call   1030 <localtime_r@plt>
mov    $0x76c,%ecx
add    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x18(%rsp),%r9d
add    $0x1,%r8d
mov    0x1c(%rsp),%r10d
mov    0x20(%rsp),%r11d
mov    0x24(%rsp),%ebx
sub    $0x8,%rsp
lea    0xe22(%rip),%rdx
lea    0x38(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x80,%esi
xor    %eax,%eax
push   %rbx
push   %r11
push   %r10
call   1060 <snprintf@plt>
add    $0x20,%rsp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1090 <log_write@plt>
lea    0xe0d(%rip),%rdx
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %r14,%rcx
mov    %r12,%r8
mov    %r13d,%r9d
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1090 <log_write@plt>
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %r15,%rdx
mov    0xc(%rsp),%ecx
call   1040 <vsnprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbp,1)
jne    1282 <log_doit+0x112>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
jmp    1260 <log_doit+0xf0>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <log_write@plt>
lea    0xd90(%rip),%rdi
mov    $0x1,%esi
call   1090 <log_write@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
add    $0xb8,%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 }
%struct.timeval = type { i32 }
@.str = [33 x i8] c"[%04d-%02d-%02d %02d:%02d:%02d] \00"
@.str.1 = [15 x i8] c"<%s (%s:%d)>: \00"
@.str.2 = [2 x i8] c"\0A\00"
@stderr = global i32 0
define void @log_doit(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca %struct.tm
%12 = alloca %struct.timeval
%13 = alloca [128 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%14 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%16 = call i32 @localtime_r(i32* %15, %struct.tm* %11)
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%18 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 0
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1900
%21 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 1
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1
%24 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 2
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 3
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 4
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 5
%31 = load i32, i32* %30
%32 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %17, i32 128, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %23, i32 %25, i32 %27, i32 %29, i32 %31)
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @log_write(i8* %33, i32 %35)
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%38 = load i8*, i8** %6
%39 = load i8*, i8** %8
%40 = load i32, i32* %7
%41 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %37, i32 128, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %38, i8* %39, i32 %40)
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
%45 = call i32 @log_write(i8* %42, i32 %44)
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%47 = load i8*, i8** %9
%48 = load i32, i32* %10
%49 = call i32 @vsnprintf(i8* %46, i32 128, i8* %47, i32 %48)
br label %50
50: ; preds = %59, %5
%51 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%52 = call i32 @strlen(i8* %51)
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 10
br i1 %58, label %59, label %65
59: ; preds = %50
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 %63
store i8 0, i8* %64
br label %50
65: ; preds = %50
%66 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%67 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%68 = call i32 @strlen(i8* %67)
%69 = call i32 @log_write(i8* %66, i32 %68)
%70 = call i32 @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%71 = load i32, i32* @stderr
%72 = call i32 @fflush(i32 %71)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
%struct.timeval = type { i32 }
@.str = [33 x i8] c"[%04d-%02d-%02d %02d:%02d:%02d] \00"
@.str.1 = [15 x i8] c"<%s (%s:%d)>: \00"
@.str.2 = [2 x i8] c"\0A\00"
@stderr = global i32 0
define void @log_doit(i8* %0, i32 %1, i8* %2, i8* nocapture %3, i32 %4) {
%6 = alloca %struct.tm
%7 = alloca %struct.timeval
%8 = alloca [128 x i8]
%9 = bitcast %struct.tm* %6 to i8*
%10 = bitcast %struct.timeval* %7 to i8*
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%12 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%14 = call i32 @localtime_r(i32* %13, %struct.tm* %6)
%15 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1900
%18 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 1
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
%21 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 2
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 3
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 4
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 5
%28 = load i32, i32* %27
%29 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %11, i32 128, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %20, i32 %22, i32 %24, i32 %26, i32 %28)
%30 = call i32 @strlen(i8* %11)
%31 = call i32 @log_write(i8* %11, i32 %30)
%32 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %11, i32 128, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %2, i32 %1)
%33 = call i32 @strlen(i8* %11)
%34 = call i32 @log_write(i8* %11, i32 %33)
%35 = call i32 @vsnprintf(i8* %11, i32 128, i8* %3, i32 %4)
%36 = call i32 @strlen(i8* %11)
%37 = add nsw i32 %36, -1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 10
br i1 %41, label %42, label %53
42: ; preds = %5, %42
%43 = call i32 @strlen(i8* %11)
%44 = add nsw i32 %43, -1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %45
store i8 0, i8* %46
%47 = call i32 @strlen(i8* %11)
%48 = add nsw i32 %47, -1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = icmp eq i8 %51, 10
br i1 %52, label %42, label %53
53: ; preds = %42, %5
%54 = call i32 @strlen(i8* %11)
%55 = call i32 @log_write(i8* %11, i32 %54)
%56 = call i32 @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%57 = load i32, i32* @stderr
%58 = call i32 @fflush(i32 %57)
ret void
}