#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char const *,
                           char const *);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ const *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
scalar_t__ to_irc_lower(char *, int /*<<< orphan*/);
void write_out(char *channame, const char *nickname, const char *mesg) {
  const time_t t = time(NULL);
  char timebuf[strlen("YYYY-MM-DD HH:MM:SS") + 1];
  strftime(timebuf, sizeof timebuf, "%F %T", localtime(&t));
  char outpath[256] = "out";
  if (*channame && to_irc_lower(channame, strlen(channame)))
    snprintf(outpath, sizeof outpath, "%s/%s", channame, "out");
  FILE *outfile = fopen(outpath, "a");
  if (!outfile && !(outfile = fopen("out", "a")))
    return;
  fprintf(outfile, "%s <%s> %s\n", timebuf, nickname, mesg);
  fclose(outfile);
}


x86 assembly (clang, -O0):
<write_out>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe36(%rip),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x148(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    %eax,-0x140(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    -0x148(%rbp),%rdi
mov    -0x140(%rbp),%esi
mov    %eax,%ecx
lea    0xdf7(%rip),%rdx
call   10b0 <strftime@plt>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
movb   $0x6f,-0x130(%rbp)
movb   $0x75,-0x12f(%rbp)
movb   $0x74,-0x12e(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12a9 <write_out+0x109>
mov    -0x8(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x150(%rbp),%rdi
mov    %eax,%esi
call   1090 <to_irc_lower@plt>
cmp    $0x0,%rax
je     12a9 <write_out+0x109>
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
lea    0xd7d(%rip),%rdx
lea    0xd7c(%rip),%r8
call   1060 <snprintf@plt>
lea    -0x130(%rbp),%rdi
lea    0xd6d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
jne    1304 <write_out+0x164>
lea    0xd48(%rip),%rdi
lea    0xd45(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x138(%rbp)
cmp    $0x0,%rax
jne    1304 <write_out+0x164>
movl   $0x1,-0x13c(%rbp)
jmp    133c <write_out+0x19c>
mov    -0x148(%rbp),%rdx
mov    -0x138(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xd05(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x138(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x13c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_out>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdx,-0x38(%rbp)
mov    %rsi,%r15
mov    %rdi,%r12
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,-0x2c(%rbp)
lea    0xe41(%rip),%rdi
call   1050 <strlen@plt>
mov    %rsp,%r14
lea    0x1(%rax),%ebx
mov    %rsp,%r13
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    -0x2c(%rbp),%rdi
call   1030 <localtime@plt>
lea    0xe29(%rip),%rdx
mov    %r13,%rdi
mov    %ebx,%esi
mov    %eax,%ecx
call   10a0 <strftime@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,-0x140(%rbp)
movaps %xmm0,-0x50(%rbp)
movaps %xmm0,-0x60(%rbp)
movaps %xmm0,-0x70(%rbp)
movaps %xmm0,-0x80(%rbp)
movaps %xmm0,-0x90(%rbp)
movaps %xmm0,-0xa0(%rbp)
movaps %xmm0,-0xb0(%rbp)
movaps %xmm0,-0xc0(%rbp)
movaps %xmm0,-0xd0(%rbp)
movaps %xmm0,-0xe0(%rbp)
movaps %xmm0,-0xf0(%rbp)
movaps %xmm0,-0x100(%rbp)
movaps %xmm0,-0x110(%rbp)
movaps %xmm0,-0x120(%rbp)
movaps %xmm0,-0x130(%rbp)
movw   $0x756f,-0x140(%rbp)
6f 75
movb   $0x74,-0x13e(%rbp)
cmpb   $0x0,(%r12)
je     12ae <write_out+0x11e>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1080 <to_irc_lower@plt>
test   %rax,%rax
je     12ae <write_out+0x11e>
lea    0xd87(%rip),%rdx
lea    0xd86(%rip),%r8
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
mov    %r12,%rcx
call   1060 <snprintf@plt>
lea    0xd6f(%rip),%rsi
lea    -0x140(%rbp),%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12e4 <write_out+0x154>
lea    0xd50(%rip),%rdi
lea    0xd4d(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1305 <write_out+0x175>
lea    0xd3b(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r15,%rcx
mov    -0x38(%rbp),%r8
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"YYYY-MM-DD HH:MM:SS\00"
@.str.1 = [6 x i8] c"%F %T\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [4 x i8] c"out\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [12 x i8] c"%s <%s> %s\0A\00"
define void @write_out(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca [256 x i8]
%11 = alloca i32*
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%13 = call i32 @time(i32* null)
store i32 %13, i32* %7
%14 = call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = trunc i64 %16 to i32
%20 = call i32 @localtime(i32* %7)
%21 = call i32 @strftime(i8* %18, i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = bitcast [256 x i8]* %10 to i8*
%23 = bitcast i8* %22 to [256 x i8]*
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %23, i32 0, i32 0
store i8 111, i8* %24
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %23, i32 0, i32 1
store i8 117, i8* %25
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %23, i32 0, i32 2
store i8 116, i8* %26
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %3
%32 = load i8*, i8** %4
%33 = load i8*, i8** %4
%34 = call i32 @strlen(i8* %33)
%35 = call i64 @to_irc_lower(i8* %32, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%39 = load i8*, i8** %4
%40 = call i32 @snprintf(i8* %38, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %37, %31, %3
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %43, i32** %11
%44 = load i32*, i32** %11
%45 = icmp ne i32* %44, null
br i1 %45, label %50, label %46
46: ; preds = %41
%47 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %47, i32** %11
%48 = icmp ne i32* %47, null
br i1 %48, label %50, label %49
49: ; preds = %46
store i32 1, i32* %12
br label %57
50: ; preds = %46, %41
%51 = load i32*, i32** %11
%52 = load i8*, i8** %5
%53 = load i8*, i8** %6
%54 = call i32 @fprintf(i32* %51, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %18, i8* %52, i8* %53)
%55 = load i32*, i32** %11
%56 = call i32 @fclose(i32* %55)
store i32 0, i32* %12
br label %57
57: ; preds = %50, %49
%58 = load i8*, i8** %8
%59 = load i32, i32* %12
switch i32 %59, label %61 [
i32 0, label %60
i32 1, label %60
]
60: ; preds = %57, %57
ret void
61: ; preds = %57
unreachable
}

LLVM IR (-O2):
@.str = [20 x i8] c"YYYY-MM-DD HH:MM:SS\00"
@.str.1 = [6 x i8] c"%F %T\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [4 x i8] c"out\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [12 x i8] c"%s <%s> %s\0A\00"
define void @write_out(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @time(i32* null)
store i32 %7, i32* %4
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = add nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = call i32 @localtime(i32* %4)
%14 = call i32 @strftime(i8* %12, i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
store i8 111, i8* %15
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 1
store i8 117, i8* %16
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 2
store i8 116, i8* %17
%18 = load i8, i8* %0
%19 = icmp eq i8 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %3
%21 = call i32 @strlen(i8* %0)
%22 = call i64 @to_irc_lower(i8* %0, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = call i32 @snprintf(i8* %15, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %20, %3
%27 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %36, label %32
32: ; preds = %29, %26
%33 = phi i32* [ %27, %26 ], [ %30, %29 ]
%34 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %12, i8* %1, i8* %2)
%35 = call i32 @fclose(i32* %33)
br label %36
36: ; preds = %29, %32
ret void
}