#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 errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
int append_line(char *word, char *history_file) {
  int errnum = 0;
  FILE *fp = fopen(history_file, "a");
  if (fp == NULL) {
    errnum = errno;
    perror("Error opening the history file: ");
  } else {
    fprintf(fp, "%s\n", word);
    fclose(fp);
  }
  return errnum;
}


x86 assembly (clang, -O0):
<append_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1193 <append_line+0x53>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    0xe79(%rip),%rdi
call   1060 <perror@plt>
jmp    11b0 <append_line+0x70>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_line>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xeaf(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1187 <append_line+0x47>
mov    %rax,%rbx
lea    0xebb(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e52(%rip),%rax
mov    (%rax),%ebx
lea    0xe6b(%rip),%rdi
call   1060 <perror@plt>
jmp    117d <append_line+0x3d>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@errno = global i32 0
@.str.1 = [33 x i8] c"Error opening the history file: \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @append_line(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @errno
store i32 %12, i32* %5
%13 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %20
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = load i8*, i8** %3
%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** %6
%19 = call i32 @fclose(i32* %18)
br label %20
20: ; preds = %14, %11
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@errno = global i32 0
@.str.1 = [33 x i8] c"Error opening the history file: \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @append_line(i8* %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, 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* @errno
%7 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 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* %0)
%10 = tail call i32 @fclose(i32* %3)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ %6, %5 ], [ 0, %8 ]
ret i32 %12
}