#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char const *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_opt_choice(int /*<<< orphan*/ *, char *);
char getc(int /*<<< orphan*/);
char getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcat(char *, char const *);
int strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
int /*<<< orphan*/ writechars(char **, int);
void write_ch_to_opt(const char *chaptername, const char *option,
                     char *optanswer) {
  FILE *pfile;
  char *preadrows[23];
  const char opt[] = "<option>";
  char fopt[80] = "<", eopt[80] = "</";
  int i;
  if (option != NULL) {
    strcat(fopt, option);
    strcat(fopt, ">");
    strcat(eopt, option);
    strcat(eopt, ">");
  }
  pfile = fopen(chaptername, "r");
  if (pfile) {
    preadrows[0] = (char *)malloc(sizeof(char) * (80 + 1));
    if (option != NULL) {
      while (fgets(preadrows[0], 80, pfile) &&
             strncmp(fopt, preadrows[0], strlen(option) + 2))
        ;
    }
    i = 0;
    while (fgets(preadrows[i], 80, pfile) && i <= 23) {
      preadrows[i + 1] = (char *)malloc(sizeof(char) * (80 + 1));
      if (!strncmp(opt, preadrows[i], strlen(opt)))
        break;
      else if (i == 23) {
        writechars(preadrows, i);
        while (getc(stdin) != '\n')
          ;
        i = -1;
      } else if (option != NULL &&
                 !strncmp(eopt, preadrows[i], strlen(option) + 3)) {
        break;
      }
      preadrows[i][strlen(preadrows[i]) - 1] = '\0';
      i++;
    }
    writechars(preadrows, i);
    if (!option)
      get_opt_choice(pfile, optanswer);
    else {
      while (getchar() != '\n') {
        printf("Waiting for newl");
      }
    }
    fclose(pfile);
    for (i = i + 1; i >= 0; i--)
      free(preadrows[i]);
  } else
    fprintf(stderr, "\n%s%s\n", "Can not open file: ", chaptername);
}


x86 assembly (clang, -O0):
<write_ch_to_opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0xdf2(%rip),%rax
mov    %rax,-0xe9(%rbp)
mov    0xded(%rip),%al
mov    %al,-0xe1(%rbp)
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   10a0 <memset@plt>
movb   $0x3c,-0x140(%rbp)
lea    -0x190(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   10a0 <memset@plt>
movb   $0x3c,-0x190(%rbp)
movb   $0x2f,-0x18f(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12ad <write_ch_to_opt+0xbd>
lea    -0x140(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1100 <strcat@plt>
lea    -0x140(%rbp),%rdi
lea    0xd82(%rip),%rsi
call   1100 <strcat@plt>
lea    -0x190(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1100 <strcat@plt>
lea    -0x190(%rbp),%rdi
lea    0xd5f(%rip),%rsi
call   1100 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xd51(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1607 <write_ch_to_opt+0x417>
mov    $0x51,%edi
call   10e0 <malloc@plt>
mov    %rax,-0xe0(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     137e <write_ch_to_opt+0x18e>
jmp    12ed <write_ch_to_opt+0xfd>
mov    -0xe0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x50,%esi
call   10b0 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x195(%rbp)
je     1361 <write_ch_to_opt+0x171>
lea    -0x140(%rbp),%rax
mov    %rax,-0x1a8(%rbp)
mov    -0xe0(%rbp),%rax
mov    %rax,-0x1a0(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x1a8(%rbp),%rdi
mov    -0x1a0(%rbp),%rsi
mov    %eax,%edx
add    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x195(%rbp)
mov    -0x195(%rbp),%al
test   $0x1,%al
jne    1374 <write_ch_to_opt+0x184>
jmp    1379 <write_ch_to_opt+0x189>
jmp    12ed <write_ch_to_opt+0xfd>
jmp    137e <write_ch_to_opt+0x18e>
movl   $0x0,-0x194(%rbp)
movslq -0x194(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rdi
ff
mov    -0x20(%rbp),%rdx
mov    $0x50,%esi
call   10b0 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1a9(%rbp)
je     13ca <write_ch_to_opt+0x1da>
cmpl   $0x17,-0x194(%rbp)
setle  %al
mov    %al,-0x1a9(%rbp)
mov    -0x1a9(%rbp),%al
test   $0x1,%al
jne    13dd <write_ch_to_opt+0x1ed>
jmp    1558 <write_ch_to_opt+0x368>
mov    $0x51,%edi
call   10e0 <malloc@plt>
mov    %rax,%rcx
mov    -0x194(%rbp),%eax
add    $0x1,%eax
cltq
mov    %rcx,-0xe0(%rbp,%rax,8)
ff
lea    -0xe9(%rbp),%rax
mov    %rax,-0x1c0(%rbp)
movslq -0x194(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x1b8(%rbp)
lea    -0xe9(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x1c0(%rbp),%rdi
mov    -0x1b8(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1451 <write_ch_to_opt+0x261>
jmp    1558 <write_ch_to_opt+0x368>
cmpl   $0x17,-0x194(%rbp)
jne    149e <write_ch_to_opt+0x2ae>
lea    -0xe0(%rbp),%rdi
mov    -0x194(%rbp),%esi
call   1050 <writechars@plt>
mov    0x2b71(%rip),%rax
mov    (%rax),%edi
call   1110 <getc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     148f <write_ch_to_opt+0x29f>
jmp    1470 <write_ch_to_opt+0x280>
movl   $0xffffffff,-0x194(%rbp)
ff ff ff
jmp    1502 <write_ch_to_opt+0x312>
cmpq   $0x0,-0x10(%rbp)
je     14fd <write_ch_to_opt+0x30d>
lea    -0x190(%rbp),%rax
mov    %rax,-0x1d0(%rbp)
movslq -0x194(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x1c8(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x1d0(%rbp),%rdi
mov    -0x1c8(%rbp),%rsi
mov    %eax,%edx
add    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    14fd <write_ch_to_opt+0x30d>
jmp    1558 <write_ch_to_opt+0x368>
jmp    1502 <write_ch_to_opt+0x312>
jmp    1507 <write_ch_to_opt+0x317>
movslq -0x194(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x1d8(%rbp)
movslq -0x194(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rdi
ff
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x1d8(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x194(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x194(%rbp)
jmp    1388 <write_ch_to_opt+0x198>
lea    -0xe0(%rbp),%rdi
mov    -0x194(%rbp),%esi
call   1050 <writechars@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1587 <write_ch_to_opt+0x397>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <get_opt_choice@plt>
jmp    15b5 <write_ch_to_opt+0x3c5>
jmp    158c <write_ch_to_opt+0x39c>
mov    $0x0,%al
call   10c0 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     15b0 <write_ch_to_opt+0x3c0>
lea    0xa65(%rip),%rdi
call   1080 <printf@plt>
jmp    158c <write_ch_to_opt+0x39c>
jmp    15b5 <write_ch_to_opt+0x3c5>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x194(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x194(%rbp)
cmpl   $0x0,-0x194(%rbp)
jl     1602 <write_ch_to_opt+0x412>
movslq -0x194(%rbp),%rax
mov    -0xe0(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x194(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x194(%rbp)
jmp    15cd <write_ch_to_opt+0x3dd>
jmp    1627 <write_ch_to_opt+0x437>
mov    0x29ca(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rcx
lea    0xa01(%rip),%rsi
lea    0xa01(%rip),%rdx
call   10d0 <fprintf@plt>
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_ch_to_opt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x178,%rsp
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r12
movabs $0x3e6e6f6974706f3c,%rax
6f 6e 3e
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movb   $0x3c,0x70(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movw   $0x2f3c,0x20(%rsp)
test   %rsi,%rsi
je     129d <write_ch_to_opt+0xbd>
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10f0 <strcat@plt>
lea    0xd90(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   10f0 <strcat@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10f0 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10f0 <strcat@plt>
lea    0xd65(%rip),%rsi
mov    %r12,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1450 <write_ch_to_opt+0x270>
mov    %rax,%r14
mov    $0x51,%edi
call   10d0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0xc0(%rsp)
test   %rbp,%rbp
je     1310 <write_ch_to_opt+0x130>
lea    0x70(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1310 <write_ch_to_opt+0x130>
mov    %rbp,%rdi
call   1070 <strlen@plt>
lea    0x2(%rax),%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <strncmp@plt>
test   %rax,%rax
jne    12e0 <write_ch_to_opt+0x100>
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
mov    %rbp,(%rsp)
mov    %r15,0x18(%rsp)
je     1474 <write_ch_to_opt+0x294>
xor    %ebx,%ebx
lea    0xc0(%rsp),%r15
mov    0x2ca5(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%r12
mov    $0x51,%edi
call   10d0 <malloc@plt>
movslq %ebx,%rcx
mov    %rax,0xc8(%rsp,%rcx,8)
mov    (%r15),%r14
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1478 <write_ch_to_opt+0x298>
cmp    $0x17,%ebx
jne    13d0 <write_ch_to_opt+0x1f0>
lea    0xc0(%rsp),%rdi
mov    $0x17,%esi
call   1050 <writechars@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13),%edi
call   1100 <getc@plt>
cmp    $0xa,%al
jne    13b0 <write_ch_to_opt+0x1d0>
mov    $0xffffffff,%ebx
jmp    1400 <write_ch_to_opt+0x220>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1400 <write_ch_to_opt+0x220>
mov    (%r15),%rbp
call   1070 <strlen@plt>
lea    0x3(%rax),%edx
lea    0x20(%rsp),%rdi
mov    %rbp,%rsi
call   1040 <strncmp@plt>
test   %rax,%rax
mov    %r12,%r14
jne    1403 <write_ch_to_opt+0x223>
jmp    1516 <write_ch_to_opt+0x336>
xchg   %ax,%ax
mov    %r12,%r14
movslq %ebx,%rbp
mov    0xc0(%rsp,%rbp,8),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0x1(%rbp),%ebx
mov    0xc8(%rsp,%rbp,8),%rdi
mov    $0x50,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     147b <write_ch_to_opt+0x29b>
lea    (%rsp,%rbp,8),%r15
add    $0xc8,%r15
cmp    $0x17,%ebp
jl     1350 <write_ch_to_opt+0x170>
jmp    147b <write_ch_to_opt+0x29b>
mov    0x2b81(%rip),%rax
mov    (%rax),%edi
lea    0xbbc(%rip),%rsi
lea    0xbbc(%rip),%rdx
mov    %r12,%rcx
call   10c0 <fprintf@plt>
jmp    1504 <write_ch_to_opt+0x324>
xor    %ebx,%ebx
jmp    147b <write_ch_to_opt+0x29b>
mov    %r12,%r14
lea    0xc0(%rsp),%rdi
mov    %ebx,%esi
call   1050 <writechars@plt>
cmpq   $0x0,(%rsp)
je     14c5 <write_ch_to_opt+0x2e5>
xor    %eax,%eax
call   10b0 <getchar@plt>
cmp    $0xa,%al
je     14d2 <write_ch_to_opt+0x2f2>
lea    0xb68(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1080 <printf@plt>
xor    %eax,%eax
call   10b0 <getchar@plt>
cmp    $0xa,%al
jne    14b0 <write_ch_to_opt+0x2d0>
jmp    14d2 <write_ch_to_opt+0x2f2>
mov    %r14,%rdi
mov    0x18(%rsp),%rsi
call   1090 <get_opt_choice@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
cmp    $0xffffffff,%ebx
jl     1504 <write_ch_to_opt+0x324>
lea    0x1(%rbx),%eax
add    $0x2,%ebx
lea    (%rsp,%rax,8),%rbp
add    $0xc0,%rbp
mov    0x0(%rbp),%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebx
add    $0xfffffffffffffff8,%rbp
test   %ebx,%ebx
jg     14f0 <write_ch_to_opt+0x310>
add    $0x178,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc0(%rsp),%rdi
mov    %ebx,%esi
call   1050 <writechars@plt>
jmp    1491 <write_ch_to_opt+0x2b1>

LLVM IR (-O0):
@__const.write_ch_to_opt.opt = [9 x i8] c"<option>\00"
@.str = [2 x i8] c">\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [17 x i8] c"Waiting for newl\00"
@stderr = global i32 0
@.str.3 = [7 x i8] c"\0A%s%s\0A\00"
@.str.4 = [20 x i8] c"Can not open file: \00"
define void @write_ch_to_opt(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [23 x i8*]
%9 = alloca [9 x i8]
%10 = alloca [80 x i8]
%11 = alloca [80 x i8]
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%13 = bitcast [9 x i8]* %9 to i8*
%14 = bitcast [80 x i8]* %10 to i8*
%15 = bitcast i8* %14 to [80 x i8]*
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %15, i32 0, i32 0
store i8 60, i8* %16
%17 = bitcast [80 x i8]* %11 to i8*
%18 = bitcast i8* %17 to [80 x i8]*
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %18, i32 0, i32 0
store i8 60, i8* %19
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %18, i32 0, i32 1
store i8 47, i8* %20
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %34
23: ; preds = %3
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%25 = load i8*, i8** %5
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%30 = load i8*, i8** %5
%31 = call i32 @strcat(i8* %29, i8* %30)
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %23, %3
%35 = load i8*, i8** %4
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %36, i32** %7
%37 = load i32*, i32** %7
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %178
39: ; preds = %34
%40 = call i64 @malloc(i32 81)
%41 = inttoptr i64 %40 to i8*
%42 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 0
store i8* %41, i8** %42
%43 = load i8*, i8** %5
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %65
45: ; preds = %39
br label %46
46: ; preds = %63, %45
%47 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 0
%48 = load i8*, i8** %47
%49 = load i32*, i32** %7
%50 = call i64 @fgets(i8* %48, i32 80, i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %61
52: ; preds = %46
%53 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%54 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 0
%55 = load i8*, i8** %54
%56 = load i8*, i8** %5
%57 = call i32 @strlen(i8* %56)
%58 = add nsw i32 %57, 2
%59 = call i64 @strncmp(i8* %53, i8* %55, i32 %58)
%60 = icmp ne i64 %59, 0
br label %61
61: ; preds = %52, %46
%62 = phi i1 [ false, %46 ], [ %60, %52 ]
br i1 %62, label %63, label %64
63: ; preds = %61
br label %46
64: ; preds = %61
br label %65
65: ; preds = %64, %39
store i32 0, i32* %12
br label %66
66: ; preds = %127, %65
%67 = load i32, i32* %12
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 %68
%70 = load i8*, i8** %69
%71 = load i32*, i32** %7
%72 = call i64 @fgets(i8* %70, i32 80, i32* %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %66
%75 = load i32, i32* %12
%76 = icmp sle i32 %75, 23
br label %77
77: ; preds = %74, %66
%78 = phi i1 [ false, %66 ], [ %76, %74 ]
br i1 %78, label %79, label %142
79: ; preds = %77
%80 = call i64 @malloc(i32 81)
%81 = inttoptr i64 %80 to i8*
%82 = load i32, i32* %12
%83 = add nsw i32 %82, 1
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 %84
store i8* %81, i8** %85
%86 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%87 = load i32, i32* %12
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 %88
%90 = load i8*, i8** %89
%91 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%92 = call i32 @strlen(i8* %91)
%93 = call i64 @strncmp(i8* %86, i8* %90, i32 %92)
%94 = icmp ne i64 %93, 0
br i1 %94, label %96, label %95
95: ; preds = %79
br label %142
96: ; preds = %79
%97 = load i32, i32* %12
%98 = icmp eq i32 %97, 23
br i1 %98, label %99, label %110
99: ; preds = %96
%100 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 0
%101 = load i32, i32* %12
%102 = call i32 @writechars(i8** %100, i32 %101)
br label %103
103: ; preds = %108, %99
%104 = load i32, i32* @stdin
%105 = call signext i8 @getc(i32 %104)
%106 = sext i8 %105 to i32
%107 = icmp ne i32 %106, 10
br i1 %107, label %108, label %109
108: ; preds = %103
br label %103
109: ; preds = %103
store i32 -1, i32* %12
br label %126
110: ; preds = %96
%111 = load i8*, i8** %5
%112 = icmp ne i8* %111, null
br i1 %112, label %113, label %125
113: ; preds = %110
%114 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%115 = load i32, i32* %12
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 %116
%118 = load i8*, i8** %117
%119 = load i8*, i8** %5
%120 = call i32 @strlen(i8* %119)
%121 = add nsw i32 %120, 3
%122 = call i64 @strncmp(i8* %114, i8* %118, i32 %121)
%123 = icmp ne i64 %122, 0
br i1 %123, label %125, label %124
124: ; preds = %113
br label %142
125: ; preds = %113, %110
br label %126
126: ; preds = %125, %109
br label %127
127: ; preds = %126
%128 = load i32, i32* %12
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 %129
%131 = load i8*, i8** %130
%132 = load i32, i32* %12
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 %133
%135 = load i8*, i8** %134
%136 = call i32 @strlen(i8* %135)
%137 = sub nsw i32 %136, 1
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i8, i8* %131, i64 %138
store i8 0, i8* %139
%140 = load i32, i32* %12
%141 = add nsw i32 %140, 1
store i32 %141, i32* %12
br label %66
142: ; preds = %124, %95, %77
%143 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 0
%144 = load i32, i32* %12
%145 = call i32 @writechars(i8** %143, i32 %144)
%146 = load i8*, i8** %5
%147 = icmp ne i8* %146, null
br i1 %147, label %152, label %148
148: ; preds = %142
%149 = load i32*, i32** %7
%150 = load i8*, i8** %6
%151 = call i32 @get_opt_choice(i32* %149, i8* %150)
br label %160
152: ; preds = %142
br label %153
153: ; preds = %157, %152
%154 = call signext i8 (...) @getchar()
%155 = sext i8 %154 to i32
%156 = icmp ne i32 %155, 10
br i1 %156, label %157, label %159
157: ; preds = %153
%158 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %153
159: ; preds = %153
br label %160
160: ; preds = %159, %148
%161 = load i32*, i32** %7
%162 = call i32 @fclose(i32* %161)
%163 = load i32, i32* %12
%164 = add nsw i32 %163, 1
store i32 %164, i32* %12
br label %165
165: ; preds = %174, %160
%166 = load i32, i32* %12
%167 = icmp sge i32 %166, 0
br i1 %167, label %168, label %177
168: ; preds = %165
%169 = load i32, i32* %12
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds [23 x i8*], [23 x i8*]* %8, i64 0, i64 %170
%172 = load i8*, i8** %171
%173 = call i32 @free(i8* %172)
br label %174
174: ; preds = %168
%175 = load i32, i32* %12
%176 = add nsw i32 %175, -1
store i32 %176, i32* %12
br label %165
177: ; preds = %165
br label %182
178: ; preds = %34
%179 = load i32, i32* @stderr
%180 = load i8*, i8** %4
%181 = call i32 @fprintf(i32 %179, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %180)
br label %182
182: ; preds = %178, %177
ret void
}

LLVM IR (-O2):
@__const.write_ch_to_opt.opt = [9 x i8] c"<option>\00"
@.str = [2 x i8] c">\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [17 x i8] c"Waiting for newl\00"
@stderr = global i32 0
@.str.3 = [7 x i8] c"\0A%s%s\0A\00"
@.str.4 = [20 x i8] c"Can not open file: \00"
define void @write_ch_to_opt(i8* %0, i8* %1, i8* %2) {
%4 = alloca [23 x i8*]
%5 = alloca [9 x i8]
%6 = alloca [80 x i8]
%7 = alloca [80 x i8]
%8 = bitcast [23 x i8*]* %4 to i8*
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
store i8 60, i8* %10
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
store i8 60, i8* %11
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 1
store i8 47, i8* %12
%13 = icmp eq i8* %1, null
br i1 %13, label %19, label %14
14: ; preds = %3
%15 = call i32 @strcat(i8* %10, i8* %1)
%16 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @strcat(i8* %11, i8* %1)
%18 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %14, %3
%20 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %111, label %22
22: ; preds = %19
%23 = call i64 @malloc(i32 81)
%24 = inttoptr i64 %23 to i8*
%25 = getelementptr inbounds [23 x i8*], [23 x i8*]* %4, i64 0, i64 0
store i8* %24, i8** %25
br i1 %13, label %34, label %26
26: ; preds = %22, %29
%27 = call i64 @fgets(i8* %24, i32 80, i32* %20)
%28 = icmp eq i64 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = call i32 @strlen(i8* %1)
%31 = add nsw i32 %30, 2
%32 = call i64 @strncmp(i8* %10, i8* %24, i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %26
34: ; preds = %29, %26, %22
%35 = call i64 @fgets(i8* %24, i32 80, i32* %20)
%36 = icmp eq i64 %35, 0
br i1 %36, label %83, label %37
37: ; preds = %34, %66
%38 = phi i8** [ %77, %66 ], [ %25, %34 ]
%39 = phi i32 [ %75, %66 ], [ 0, %34 ]
%40 = call i64 @malloc(i32 81)
%41 = inttoptr i64 %40 to i8*
%42 = add nsw i32 %39, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [23 x i8*], [23 x i8*]* %4, i64 0, i64 %43
store i8* %41, i8** %44
%45 = load i8*, i8** %38
%46 = call i32 @strlen(i8* %9)
%47 = call i64 @strncmp(i8* %9, i8* %45, i32 %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %83, label %49
49: ; preds = %37
%50 = icmp eq i32 %39, 23
br i1 %50, label %51, label %57
51: ; preds = %49
%52 = call i32 @writechars(i8** %25, i32 23)
br label %53
53: ; preds = %53, %51
%54 = load i32, i32* @stdin
%55 = call signext i8 @getc(i32 %54)
%56 = icmp eq i8 %55, 10
br i1 %56, label %66, label %53
57: ; preds = %49
br i1 %13, label %66, label %58
58: ; preds = %57
%59 = load i8*, i8** %38
%60 = call i32 @strlen(i8* %1)
%61 = add nsw i32 %60, 3
%62 = call i64 @strncmp(i8* %11, i8* %59, i32 %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %58
%65 = call i32 @writechars(i8** %25, i32 %39)
br label %86
66: ; preds = %53, %58, %57
%67 = phi i32 [ %39, %58 ], [ %39, %57 ], [ -1, %53 ]
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [23 x i8*], [23 x i8*]* %4, i64 0, i64 %68
%70 = load i8*, i8** %69
%71 = call i32 @strlen(i8* %70)
%72 = add nsw i32 %71, -1
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %70, i64 %73
store i8 0, i8* %74
%75 = add nsw i32 %67, 1
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [23 x i8*], [23 x i8*]* %4, i64 0, i64 %76
%78 = load i8*, i8** %77
%79 = call i64 @fgets(i8* %78, i32 80, i32* %20)
%80 = icmp ne i64 %79, 0
%81 = icmp slt i32 %67, 23
%82 = select i1 %80, i1 %81, i1 false
br i1 %82, label %37, label %83
83: ; preds = %66, %37, %34
%84 = phi i32 [ 0, %34 ], [ %39, %37 ], [ %75, %66 ]
%85 = call i32 @writechars(i8** %25, i32 %84)
br i1 %13, label %90, label %86
86: ; preds = %64, %83
%87 = phi i32 [ %39, %64 ], [ %84, %83 ]
%88 = call signext i8 (...) @getchar()
%89 = icmp eq i8 %88, 10
br i1 %89, label %96, label %92
90: ; preds = %83
%91 = call i32 @get_opt_choice(i32* %20, i8* %2)
br label %96
92: ; preds = %86, %92
%93 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%94 = call signext i8 (...) @getchar()
%95 = icmp eq i8 %94, 10
br i1 %95, label %96, label %92
96: ; preds = %92, %86, %90
%97 = phi i32 [ %87, %86 ], [ %84, %90 ], [ %87, %92 ]
%98 = call i32 @fclose(i32* %20)
%99 = icmp sgt i32 %97, -2
br i1 %99, label %100, label %114
100: ; preds = %96
%101 = add i32 %97, 1
%102 = zext i32 %101 to i64
br label %103
103: ; preds = %100, %103
%104 = phi i64 [ %102, %100 ], [ %108, %103 ]
%105 = getelementptr inbounds [23 x i8*], [23 x i8*]* %4, i64 0, i64 %104
%106 = load i8*, i8** %105
%107 = call i32 @free(i8* %106)
%108 = add nsw i64 %104, -1
%109 = trunc i64 %104 to i32
%110 = icmp sgt i32 %109, 0
br i1 %110, label %103, label %114
111: ; preds = %19
%112 = load i32, i32* @stderr
%113 = call i32 @fprintf(i32 %112, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %114
114: ; preds = %103, %96, %111
ret void
}