#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 *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int appendf(void) {
  FILE *fp;
  char input[256];
  char append[256];
  printf("source file destination:");
  scanf("%s", input);
  fp = fopen(input, "a");
  if (fp == NULL) {
    perror("Error opening file.");
  } else {
    scanf("%s", append);
    fprintf(fp, "%s", append);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<appendf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bd <appendf+0x5d>
lea    0xe6b(%rip),%rdi
call   1080 <perror@plt>
jmp    11e7 <appendf+0x87>
lea    -0x210(%rbp),%rsi
lea    0xe4e(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x210(%rbp),%rdx
lea    0xe37(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appendf>:
push   %r14
push   %rbx
sub    $0x208,%rsp
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9c(%rip),%rdi
lea    0x100(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d4 <appendf+0x74>
lea    0xe6e(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1060 <scanf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe43(%rip),%rdi
call   1080 <perror@plt>
jmp    11c1 <appendf+0x61>

LLVM IR (-O0):
@.str = [25 x i8] c"source file destination:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [20 x i8] c"Error opening file.\00"
define i32 @appendf() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %20
14: ; preds = %0
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32*, i32** %2
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %14, %12
%21 = load i32*, i32** %2
%22 = call i32 @fclose(i32* %21)
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [25 x i8] c"source file destination:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [20 x i8] c"Error opening file.\00"
define i32 @appendf() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %14
11: ; preds = %0
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%13 = call i32 @fputs(i8* %4, i32* %7)
br label %14
14: ; preds = %11, %9
%15 = call i32 @fclose(i32* %7)
ret i32 undef
}