#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*/ SEEK_END;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void log_comment(char *file_path, const char *comment) {
  char temp_com[81];
  int com_len = 0;
  FILE *fp = NULL;
  assert(comment != NULL);
  fp = fopen(file_path, "r+");
  com_len = strlen(comment);
  if (fp) {
    if (com_len > (81 - 1)) {
      strncpy(temp_com, comment, 81 - 1);
      temp_com[81 - 1] = '\0';
    } else {
      strncpy(temp_com, comment, com_len);
      temp_com[com_len] = '\0';
    }
    fseek(fp, 0, SEEK_END);
    fprintf(fp, "%s", "#");
    fprintf(fp, "%s\n", temp_com);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<log_comment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x74(%rbp)
movq   $0x0,-0x80(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x74(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     124c <log_comment+0xdc>
cmpl   $0x50,-0x74(%rbp)
jle    11f4 <log_comment+0x84>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x20(%rbp)
jmp    120d <log_comment+0x9d>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x74(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x74(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
mov    -0x80(%rbp),%rdi
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x80(%rbp),%rdi
lea    0xdd7(%rip),%rsi
lea    0xdd3(%rip),%rdx
call   1070 <fprintf@plt>
mov    -0x80(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    0xdc1(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x80(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_comment>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1070 <assert@plt>
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %rbx,%rbx
je     1219 <log_comment+0x99>
mov    %eax,%ebp
mov    %rsp,%rdi
mov    %r14,%rsi
cmp    $0x51,%eax
jl     11d9 <log_comment+0x59>
mov    $0x50,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x50(%rsp)
jmp    11e7 <log_comment+0x67>
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    $0x23,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
lea    0xdf5(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@SEEK_END = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"#\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @log_comment(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [81 x i8]
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32* null, i32** %7
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %6
%16 = load i32*, i32** %7
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %43
18: ; preds = %2
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, 80
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%23 = load i8*, i8** %4
%24 = call i32 @strncpy(i8* %22, i8* %23, i32 80)
%25 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 80
store i8 0, i8* %25
br label %34
26: ; preds = %18
%27 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%28 = load i8*, i8** %4
%29 = load i32, i32* %6
%30 = call i32 @strncpy(i8* %27, i8* %28, i32 %29)
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %26, %21
%35 = load i32*, i32** %7
%36 = load i32, i32* @SEEK_END
%37 = call i32 @fseek(i32* %35, i32 0, i32 %36)
%38 = load i32*, i32** %7
%39 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32*, i32** %7
%41 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%42 = call i32 @fprintf(i32* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %34, %2
%44 = load i32*, i32** %7
%45 = call i32 @fclose(i32* %44)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@SEEK_END = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
define void @log_comment(i8* nocapture %0, i8* %1) {
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%5 = icmp ne i8* %1, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @strlen(i8* %1)
%10 = icmp eq i32* %8, null
br i1 %10, label %25, label %11
11: ; preds = %2
%12 = icmp sgt i32 %9, 80
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = call i32 @strncpy(i8* %4, i8* %1, i32 80)
%15 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 80
store i8 0, i8* %15
br label %20
16: ; preds = %11
%17 = call i32 @strncpy(i8* %4, i8* %1, i32 %9)
%18 = sext i32 %9 to i64
%19 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %16, %13
%21 = load i32, i32* @SEEK_END
%22 = call i32 @fseek(i32* %8, i32 0, i32 %21)
%23 = call i32 @fputc(i32 35, i32* %8)
%24 = call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %25
25: ; preds = %20, %2
%26 = call i32 @fclose(i32* %8)
ret void
}