#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 const *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
size_t fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int strlen(char *);
void log_message(const char *file_path, char *buffer) {
  FILE *file;
  size_t result;
  int len;
  if ((file = fopen(file_path, "ab")) != NULL) {
    len = strlen(buffer);
    if ((result = fwrite(buffer, sizeof(char), len, file)) != len)
      fputs("fwrite() error", stderr);
    fclose(file);
  }
}


x86 assembly (clang, -O0):
<log_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ce <log_message+0x7e>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    %rax,-0x20(%rbp)
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
je     11c5 <log_message+0x75>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    0xe43(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_message>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b0 <log_message+0x60>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
movslq %ebp,%rcx
cmp    %rcx,%rax
je     11a4 <log_message+0x54>
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0xe64(%rip),%rdi
call   1050 <fputs@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ab\00"
@.str.1 = [15 x i8] c"fwrite() error\00"
@stderr = global i32 0
define void @log_message(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %27
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %7
%14 = load i8*, i8** %4
%15 = load i32, i32* %7
%16 = load i32*, i32** %5
%17 = call i64 @fwrite(i8* %14, i32 1, i32 %15, i32* %16)
store i64 %17, i64* %6
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = icmp ne i64 %17, %19
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = load i32, i32* @stderr
%23 = call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %11
%25 = load i32*, i32** %5
%26 = call i32 @fclose(i32* %25)
br label %27
27: ; preds = %24, %2
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"ab\00"
@.str.1 = [15 x i8] c"fwrite() error\00"
@stderr = global i32 0
define void @log_message(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %1)
%7 = tail call i64 @fwrite(i8* %1, i32 1, i32 %6, i32* %3)
%8 = sext i32 %6 to i64
%9 = icmp eq i64 %7, %8
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %10, %5
%14 = tail call i32 @fclose(i32* %3)
br label %15
15: ; preds = %13, %2
ret void
}