#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ log_println(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
void log_event(char *alias, char *message, int day, int month, int hour,
               int min) {
  FILE *log;
  char filename[256];
  snprintf(filename, 256, "%s/.msn/%s.log", getenv("HOME"), alias);
  log = fopen(filename, "a");
  if (log == NULL) {
    log_println("eERROR: unable to open log file. (perhaps disk is full)");
    return;
  }
  fprintf(log, "[ A: %s D: %d/%d T: %d:%d ]\n", alias, month, day, hour, min);
  fprintf(log, "%s\n", message);
  fprintf(log, "~\n");
  fclose(log);
}


x86 assembly (clang, -O0):
<log_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    0xe79(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x138(%rbp),%rdi
mov    %rax,%rcx
mov    -0x8(%rbp),%r8
mov    $0x100,%esi
lea    0xe4b(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x130(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ed <log_event+0x8d>
lea    0xe33(%rip),%rdi
call   1060 <log_println@plt>
jmp    1245 <log_event+0xe5>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x20(%rbp),%eax
lea    0xe44(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_event>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %ecx,%r13d
mov    %edx,%r12d
mov    %rsi,0x8(%rsp)
mov    %rdi,%rbp
lea    0xe73(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe58(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rcx
mov    %rbp,%r8
call   1050 <snprintf@plt>
lea    0xe4d(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1231 <log_event+0xc1>
mov    %rax,%rbx
mov    %r14d,(%rsp)
lea    0xe6c(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
mov    %r13d,%ecx
mov    %r12d,%r8d
mov    %r15d,%r9d
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    123d <log_event+0xcd>
lea    0xdde(%rip),%rdi
call   1060 <log_println@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%s/.msn/%s.log\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [56 x i8] c"eERROR: unable to open log file. (perhaps disk is full)\00"
@.str.4 = [29 x i8] c"[ A: %s D: %d/%d T: %d:%d ]\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [3 x i8] c"~\0A\00"
define void @log_event(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca [256 x i8]
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%16 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8*, i8** %7
%18 = call i32 @snprintf(i8* %15, i32 256, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %13
%21 = load i32*, i32** %13
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %6
%24 = call i32 @log_println(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
br label %40
25: ; preds = %6
%26 = load i32*, i32** %13
%27 = load i8*, i8** %7
%28 = load i32, i32* %10
%29 = load i32, i32* %9
%30 = load i32, i32* %11
%31 = load i32, i32* %12
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %27, i32 %28, i32 %29, i32 %30, i32 %31)
%33 = load i32*, i32** %13
%34 = load i8*, i8** %8
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %34)
%36 = load i32*, i32** %13
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%38 = load i32*, i32** %13
%39 = call i32 @fclose(i32* %38)
br label %40
40: ; preds = %25, %23
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"%s/.msn/%s.log\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [56 x i8] c"eERROR: unable to open log file. (perhaps disk is full)\00"
@.str.4 = [29 x i8] c"[ A: %s D: %d/%d T: %d:%d ]\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [3 x i8] c"~\0A\00"
define void @log_event(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca [256 x i8]
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %0)
%11 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = call i32 @log_println(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
br label %20
15: ; preds = %6
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %3, i32 %2, i32 %4, i32 %5)
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %1)
%18 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 2, i64 1, i32* %11)
%19 = call i32 @fclose(i32* %11)
br label %20
20: ; preds = %15, %13
ret void
}