#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  FILE *pFile;
  if (argv[1] == NULL) {
    printf("Fatal Error: no file specified\n");
    return 1;
  } else if (strcmp(argv[1], "-lines") == 0) {
    int c;
    int n = 0;
    pFile = fopen(argv[2], "r");
    if (pFile == NULL)
      perror("Error opening file");
    else {
      do {
        c = fgetc(pFile);
        if (c == '\n')
          n++;
      } while (c != EOF);
      fclose(pFile);
      printf("The file contains %d lines.\n", n);
    }
    return 0;
  } else {
    char sentence[256];
    printf("Enter sentence to append: ");
    fgets(sentence, 256, stdin);
    pFile = fopen(argv[1], "a");
    fputs(sentence, pFile);
    fclose(pFile);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11c2 <main+0x42>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e1 <main+0x161>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4f(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    127c <main+0xfc>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe31(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121b <main+0x9b>
lea    0xe18(%rip),%rdi
call   10a0 <perror@plt>
jmp    1270 <main+0xf0>
jmp    1220 <main+0xa0>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jne    123f <main+0xbf>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1244 <main+0xc4>
mov    -0x1c(%rbp),%eax
mov    0x2d92(%rip),%rcx
cmp    (%rcx),%eax
jne    1220 <main+0xa0>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%esi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e1 <main+0x161>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2d50(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1070 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc1(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    12da <main+0x15a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     1209 <main+0x79>
mov    %rsi,%rbx
lea    0xe52(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     121c <main+0x8c>
lea    0xe7a(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   1080 <fgets@plt>
mov    0x8(%rbx),%rdi
lea    0xe68(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1271 <main+0xe1>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
jmp    1271 <main+0xe1>
mov    0x10(%rbx),%rdi
lea    0xde0(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     127f <main+0xef>
mov    %rax,%rbp
xor    %ebx,%ebx
mov    0x2da3(%rip),%r14
nopl   (%rax)
mov    %rbp,%rdi
call   1070 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebx
cmp    (%r14),%eax
jne    1240 <main+0xb0>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xdb6(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd83(%rip),%rdi
call   10b0 <perror@plt>
xor    %ebp,%ebp
jmp    1271 <main+0xe1>

LLVM IR (-O0):
@.str = [32 x i8] c"Fatal Error: no file specified\0A\00"
@.str.1 = [7 x i8] c"-lines\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [19 x i8] c"Error opening file\00"
@EOF = global i32 0
@.str.4 = [29 x i8] c"The file contains %d lines.\0A\00"
@.str.5 = [27 x i8] c"Enter sentence to append: \00"
@stdin = global i32 0
@.str.6 = [2 x i8] c"a\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %67
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %51
22: ; preds = %16
store i32 0, i32* %8
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %26, i32** %6
%27 = load i32*, i32** %6
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %50
31: ; preds = %22
br label %32
32: ; preds = %41, %31
%33 = load i32*, i32** %6
%34 = call i32 @fgetc(i32* %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %40
40: ; preds = %37, %32
br label %41
41: ; preds = %40
%42 = load i32, i32* %7
%43 = load i32, i32* @EOF
%44 = icmp ne i32 %42, %43
br i1 %44, label %32, label %45
45: ; preds = %41
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
%48 = load i32, i32* %8
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %45, %29
store i32 0, i32* %3
br label %67
51: ; preds = %16
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%54 = load i32, i32* @stdin
%55 = call i32 @fgets(i8* %53, i32 256, i32 %54)
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i32* @fopen(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %59, i32** %6
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%61 = load i32*, i32** %6
%62 = call i32 @fputs(i8* %60, i32* %61)
%63 = load i32*, i32** %6
%64 = call i32 @fclose(i32* %63)
br label %65
65: ; preds = %51
br label %66
66: ; preds = %65
store i32 0, i32* %3
br label %67
67: ; preds = %66, %50, %14
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"-lines\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [19 x i8] c"Error opening file\00"
@EOF = global i32 0
@.str.4 = [29 x i8] c"The file contains %d lines.\0A\00"
@.str.5 = [27 x i8] c"Enter sentence to append: \00"
@stdin = global i32 0
@.str.6 = [2 x i8] c"a\00"
@str = [31 x i8] c"Fatal Error: no file specified\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %39
9: ; preds = %2
%10 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %30
12: ; preds = %9
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %39
19: ; preds = %12, %19
%20 = phi i32 [ %24, %19 ], [ 0, %12 ]
%21 = tail call i32 @fgetc(i32* %15)
%22 = icmp eq i32 %21, 10
%23 = zext i1 %22 to i32
%24 = add nuw nsw i32 %20, %23
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %21, %25
br i1 %26, label %27, label %19
27: ; preds = %19
%28 = tail call i32 @fclose(i32* %15)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %24)
br label %39
30: ; preds = %9
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32, i32* @stdin
%34 = call i32 @fgets(i8* %31, i32 256, i32 %33)
%35 = load i8*, i8** %4
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%37 = call i32 @fputs(i8* %31, i32* %36)
%38 = call i32 @fclose(i32* %36)
br label %39
39: ; preds = %17, %27, %30, %7
%40 = phi i32 [ 1, %7 ], [ 0, %30 ], [ 0, %27 ], [ 0, %17 ]
ret i32 %40
}