#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 */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, ...);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void debug(FILE *fd, int connection_counter, char *msg) {
  time_t now;
  time(&now);
  char buffer[100];
  strftime(buffer, 100, "%Y-%m-%d %H:%M:%S.000", localtime(&now));
  if (connection_counter != -1) {
    fprintf(fd, "%s - [%i]: %s\n", buffer, connection_counter, msg);
  } else {
    fprintf(fd, "%s - %s\n", buffer, msg);
  }
  fflush(fd);
}


x86 assembly (clang, -O0):
<debug>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
call   1050 <time@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%ecx
mov    $0x64,%esi
lea    0xe68(%rip),%rdx
call   1070 <strftime@plt>
cmpl   $0xffffffff,-0xc(%rbp)
je     11c9 <debug+0x79>
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%r8
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11e3 <debug+0x93>
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fflush@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
lea    0xe82(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
mov    %eax,%ecx
call   1070 <strftime@plt>
cmp    $0xffffffff,%ebp
je     11b1 <debug+0x61>
lea    0xe7b(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r15,%rdi
mov    %ebp,%ecx
mov    %r14,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11ca <debug+0x7a>
lea    0xe6d(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r15,%rdi
call   1060 <fflush@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"%Y-%m-%d %H:%M:%S.000\00"
@.str.1 = [15 x i8] c"%s - [%i]: %s\0A\00"
@.str.2 = [9 x i8] c"%s - %s\0A\00"
define void @debug(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [100 x i8]
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = call i32 @time(i32* %7)
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%11 = call i32 @localtime(i32* %7)
%12 = call i32 @strftime(i8* %10, i32 100, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = load i32*, i32** %4
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%18 = load i32, i32* %5
%19 = load i8*, i8** %6
%20 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 %18, i8* %19)
br label %26
21: ; preds = %3
%22 = load i32*, i32** %4
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%24 = load i8*, i8** %6
%25 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %24)
br label %26
26: ; preds = %21, %15
%27 = load i32*, i32** %4
%28 = call i32 @fflush(i32* %27)
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"%Y-%m-%d %H:%M:%S.000\00"
@.str.1 = [15 x i8] c"%s - [%i]: %s\0A\00"
@.str.2 = [9 x i8] c"%s - %s\0A\00"
define void @debug(i32* nocapture %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = bitcast i32* %4 to i8*
%7 = call i32 @time(i32* %4)
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%9 = call i32 @localtime(i32* %4)
%10 = call i32 @strftime(i8* %8, i32 100, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %1, -1
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 %1, i8* %2)
br label %16
14: ; preds = %3
%15 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %2)
br label %16
16: ; preds = %14, %12
%17 = call i32 @fflush(i32* %0)
ret void
}