#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 */
char EOF;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  FILE *ifPtr = stdin;
  FILE *ofPtr = stdout;
  printf("argc = %d\n", argc);
  char c, sentence[120];
  int i = 0;
  if (argc < 2)
    fputs("Enter a line of text: ", ofPtr);
  else if (argc > 1) {
    if ((ifPtr = fopen(argv[1], "r")) == NULL) {
      printf("Error - unable to open file \"%s\"\n", argv[1]);
      return -1;
    }
    if (argc > 2) {
      if ((ofPtr = fopen(argv[2], "w")) == NULL) {
        printf("Error - unable to open file \"%s\"\n", argv[2]);
        return -1;
      }
    }
  }
  if (argc < 2) {
    while ((c = fgetc(ifPtr)) != '\n')
      sentence[i++] = c;
    sentence[i] = '\0';
    fputs("\nThe line entered was: ", ofPtr);
    fputs(sentence, ofPtr);
  } else {
    while ((c = fgetc(ifPtr)) != EOF) {
      sentence[i++] = c;
      if (c == '\n') {
        sentence[i] = '\0';
        i = 0;
        fputs(sentence, ofPtr);
      }
    }
    sentence[i] = '\0';
    fputs(sentence, ofPtr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xa4(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11af <main+0x6f>
mov    -0x20(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1040 <fputs@plt>
jmp    125a <main+0x11a>
cmpl   $0x1,-0x8(%rbp)
jle    1255 <main+0x115>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fd <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137b <main+0x23b>
cmpl   $0x2,-0x8(%rbp)
jle    1250 <main+0x110>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe30(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    124b <main+0x10b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137b <main+0x23b>
jmp    1250 <main+0x110>
jmp    1255 <main+0x115>
jmp    125a <main+0x11a>
cmpl   $0x2,-0x8(%rbp)
jge    12d7 <main+0x197>
jmp    1269 <main+0x129>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     12a3 <main+0x163>
mov    -0x21(%rbp),%cl
mov    -0xa4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xa4(%rbp)
cltq
mov    %cl,-0xa0(%rbp,%rax,1)
jmp    1269 <main+0x129>
movslq -0xa4(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
mov    -0x20(%rbp),%rsi
lea    0xd8b(%rip),%rdi
call   1040 <fputs@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fputs@plt>
jmp    1374 <main+0x234>
jmp    12dc <main+0x19c>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2cee(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1355 <main+0x215>
mov    -0x21(%rbp),%cl
mov    -0xa4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xa4(%rbp)
cltq
mov    %cl,-0xa0(%rbp,%rax,1)
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    1350 <main+0x210>
movslq -0xa4(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
movl   $0x0,-0xa4(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fputs@plt>
jmp    12dc <main+0x19c>
movslq -0xa4(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fputs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e7e(%rip),%rax
mov    (%rax),%rbx
mov    0x2e5c(%rip),%rax
mov    (%rax),%r15
lea    0xe82(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x2,%ebp
jge    11b8 <main+0x68>
lea    0xe78(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
xor    %r14d,%r14d
cmp    $0xa,%al
jne    121b <main+0xcb>
xor    %eax,%eax
jmp    1235 <main+0xe5>
mov    0x8(%r14),%rdi
lea    0xe5f(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     125f <main+0x10f>
mov    %rax,%rbx
cmp    $0x3,%ebp
jb     11f5 <main+0xa5>
mov    0x10(%r14),%rdi
lea    0xe62(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     129f <main+0x14f>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2ddc(%rip),%r13
xor    %r14d,%r14d
mov    $0x0,%ebp
cmp    0x0(%r13),%al
jne    1265 <main+0x115>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
jmp    1252 <main+0x102>
xor    %ebp,%ebp
nopl   (%rax)
mov    %al,(%rsp,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    $0xa,%al
jne    1220 <main+0xd0>
mov    %ebp,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe08(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
mov    %rsp,%rdi
mov    %r15,%rsi
call   1040 <fputs@plt>
jmp    12b7 <main+0x167>
mov    0x8(%r14),%rsi
jmp    12a3 <main+0x153>
xor    %ebp,%ebp
mov    %rsp,%r12
jmp    127e <main+0x12e>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    0x0(%r13),%al
je     1212 <main+0xc2>
movslq %ebp,%rbp
mov    %al,(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    $0xa,%al
jne    1270 <main+0x120>
movb   $0x0,(%rsp,%rbp,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fputs@plt>
xor    %ebp,%ebp
jmp    1270 <main+0x120>
mov    0x10(%r14),%rsi
lea    0xd7a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32* null
@.str = [11 x i8] c"argc = %d\0A\00"
@.str.1 = [23 x i8] c"Enter a line of text: \00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [34 x i8] c"Error - unable to open file \22%s\22\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [24 x i8] c"\0AThe line entered was: \00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8
%9 = alloca [120 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32*, i32** @stdin
store i32* %11, i32** %6
%12 = load i32*, i32** @stdout
store i32* %12, i32** %7
%13 = load i32, i32* %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 0, i32* %10
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32*, i32** %7
%19 = call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32* %18)
br label %51
20: ; preds = %2
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 1
br i1 %22, label %23, label %50
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %6
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %32)
store i32 -1, i32* %3
br label %108
34: ; preds = %23
%35 = load i32, i32* %4
%36 = icmp sgt i32 %35, 2
br i1 %36, label %37, label %49
37: ; preds = %34
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %41, i32** %7
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %48
43: ; preds = %37
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %46)
store i32 -1, i32* %3
br label %108
48: ; preds = %37
br label %49
49: ; preds = %48, %34
br label %50
50: ; preds = %49, %20
br label %51
51: ; preds = %50, %17
%52 = load i32, i32* %4
%53 = icmp slt i32 %52, 2
br i1 %53, label %54, label %75
54: ; preds = %51
br label %55
55: ; preds = %60, %54
%56 = load i32*, i32** %6
%57 = call signext i8 @fgetc(i32* %56)
store i8 %57, i8* %8
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 10
br i1 %59, label %60, label %66
60: ; preds = %55
%61 = load i8, i8* %8
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
%64 = sext i32 %62 to i64
%65 = getelementptr inbounds [120 x i8], [120 x i8]* %9, i64 0, i64 %64
store i8 %61, i8* %65
br label %55
66: ; preds = %55
%67 = load i32, i32* %10
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [120 x i8], [120 x i8]* %9, i64 0, i64 %68
store i8 0, i8* %69
%70 = load i32*, i32** %7
%71 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32* %70)
%72 = getelementptr inbounds [120 x i8], [120 x i8]* %9, i64 0, i64 0
%73 = load i32*, i32** %7
%74 = call i32 @fputs(i8* %72, i32* %73)
br label %107
75: ; preds = %51
br label %76
76: ; preds = %99, %75
%77 = load i32*, i32** %6
%78 = call signext i8 @fgetc(i32* %77)
store i8 %78, i8* %8
%79 = sext i8 %78 to i32
%80 = load i8, i8* @EOF
%81 = sext i8 %80 to i32
%82 = icmp ne i32 %79, %81
br i1 %82, label %83, label %100
83: ; preds = %76
%84 = load i8, i8* %8
%85 = load i32, i32* %10
%86 = add nsw i32 %85, 1
store i32 %86, i32* %10
%87 = sext i32 %85 to i64
%88 = getelementptr inbounds [120 x i8], [120 x i8]* %9, i64 0, i64 %87
store i8 %84, i8* %88
%89 = load i8, i8* %8
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 10
br i1 %91, label %92, label %99
92: ; preds = %83
%93 = load i32, i32* %10
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [120 x i8], [120 x i8]* %9, i64 0, i64 %94
store i8 0, i8* %95
store i32 0, i32* %10
%96 = getelementptr inbounds [120 x i8], [120 x i8]* %9, i64 0, i64 0
%97 = load i32*, i32** %7
%98 = call i32 @fputs(i8* %96, i32* %97)
br label %99
99: ; preds = %92, %83
br label %76
100: ; preds = %76
%101 = load i32, i32* %10
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [120 x i8], [120 x i8]* %9, i64 0, i64 %102
store i8 0, i8* %103
%104 = getelementptr inbounds [120 x i8], [120 x i8]* %9, i64 0, i64 0
%105 = load i32*, i32** %7
%106 = call i32 @fputs(i8* %104, i32* %105)
br label %107
107: ; preds = %100, %66
store i32 0, i32* %3
br label %108
108: ; preds = %107, %43, %29
%109 = load i32, i32* %3
ret i32 %109
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@.str = [11 x i8] c"argc = %d\0A\00"
@.str.1 = [23 x i8] c"Enter a line of text: \00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [34 x i8] c"Error - unable to open file \22%s\22\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [24 x i8] c"\0AThe line entered was: \00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [120 x i8]
%4 = load i32*, i32** @stdin
%5 = load i32*, i32** @stdout
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 0
%8 = icmp slt i32 %0, 2
br i1 %8, label %32, label %9
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %71
17: ; preds = %9
%18 = icmp ugt i32 %0, 2
br i1 %18, label %19, label %27
19: ; preds = %17
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i8*, i8** %20
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %71
27: ; preds = %19, %17
%28 = phi i32* [ %5, %17 ], [ %22, %19 ]
%29 = tail call signext i8 @fgetc(i32* %12)
%30 = load i8, i8* @EOF
%31 = icmp eq i8 %29, %30
br i1 %31, label %66, label %50
32: ; preds = %2
%33 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 22, i64 1, i32* %5)
%34 = tail call signext i8 @fgetc(i32* %4)
%35 = icmp eq i8 %34, 10
br i1 %35, label %45, label %36
36: ; preds = %32, %36
%37 = phi i64 [ %39, %36 ], [ 0, %32 ]
%38 = phi i8 [ %41, %36 ], [ %34, %32 ]
%39 = add nuw i64 %37, 1
%40 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 %37
store i8 %38, i8* %40
%41 = tail call signext i8 @fgetc(i32* %4)
%42 = icmp eq i8 %41, 10
br i1 %42, label %43, label %36
43: ; preds = %36
%44 = and i64 %39, 4294967295
br label %45
45: ; preds = %43, %32
%46 = phi i64 [ 0, %32 ], [ %44, %43 ]
%47 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 %46
store i8 0, i8* %47
%48 = tail call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i64 23, i64 1, i32* %5)
%49 = call i32 @fputs(i8* %7, i32* %5)
br label %71
50: ; preds = %27, %61
%51 = phi i8 [ %63, %61 ], [ %29, %27 ]
%52 = phi i32 [ %62, %61 ], [ 0, %27 ]
%53 = add nsw i32 %52, 1
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 %54
store i8 %51, i8* %55
%56 = icmp eq i8 %51, 10
br i1 %56, label %57, label %61
57: ; preds = %50
%58 = sext i32 %53 to i64
%59 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 %58
store i8 0, i8* %59
%60 = call i32 @fputs(i8* %7, i32* %28)
br label %61
61: ; preds = %57, %50
%62 = phi i32 [ 0, %57 ], [ %53, %50 ]
%63 = tail call signext i8 @fgetc(i32* %12)
%64 = load i8, i8* @EOF
%65 = icmp eq i8 %63, %64
br i1 %65, label %66, label %50
66: ; preds = %61, %27
%67 = phi i32 [ 0, %27 ], [ %62, %61 ]
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 %68
store i8 0, i8* %69
%70 = call i32 @fputs(i8* %7, i32* %28)
br label %71
71: ; preds = %45, %66, %24, %14
%72 = phi i32 [ -1, %14 ], [ -1, %24 ], [ 0, %66 ], [ 0, %45 ]
ret i32 %72
}