#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*/ LOG_ERR;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *);
void log_message(char *filename, char *message) {
  FILE *logfile;
  logfile = fopen(filename, "a");
  if (!logfile) {
    syslog(LOG_ERR, "Can not open file %s", filename);
    return;
  }
  fprintf(logfile, "%s\n", message);
  fclose(logfile);
}


x86 assembly (clang, -O0):
<log_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118d <log_message+0x4d>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe7f(%rip),%rsi
call   1050 <syslog@plt>
jmp    11aa <log_message+0x6a>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe7b(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_message>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     117e <log_message+0x3e>
mov    %rax,%rbx
lea    0xeb1(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
mov    %r15,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <syslog@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@LOG_ERR = global i32 0
@.str.1 = [21 x i8] c"Can not open file %s\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @log_message(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp ne i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @LOG_ERR
%12 = load i8*, i8** %3
%13 = call i32 @syslog(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %20
14: ; preds = %2
%15 = load i32*, i32** %5
%16 = load i8*, i8** %4
%17 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %5
%19 = call i32 @fclose(i32* %18)
br label %20
20: ; preds = %14, %10
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@LOG_ERR = global i32 0
@.str.1 = [21 x i8] c"Can not open file %s\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @log_message(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @LOG_ERR
%7 = tail call i32 @syslog(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %11
8: ; preds = %2
%9 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%10 = tail call i32 @fclose(i32* %3)
br label %11
11: ; preds = %8, %5
ret void
}