#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*/ ascienc(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *getstr();
scalar_t__ htmlenc(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *in, *out;
  char *s;
  if (argc == 3) {
    if (!(in = fopen(*(argv + 1), "r")) || !(out = fopen(*(argv + 2), "w")))
      goto openerr;
    if (htmlenc(in, out))
      goto ioerr;
  } else {
    printf("HTML String Encoder\n");
    printf("Enter Input Filename  : ");
    if (!(s = getstr()))
      goto allocerr;
    if (!(in = fopen(s, "r")))
      goto openerr;
    printf("Enter Output Filename : ");
    free(s);
    if (!(s = getstr()))
      goto allocerr;
    if (!(out = fopen(s, "w")))
      goto openerr;
    printf("Encode into:\n1 - Regular HTML\n2 - Full ASCII\n? ");
    free(s);
    if (!(s = getstr()))
      goto allocerr;
    switch (*s) {
    case '1':
      if (htmlenc(in, out))
        goto ioerr;
      break;
    case '2':
      if (ascienc(in, out))
        goto ioerr;
      break;
    default:
      fprintf(stderr, "Invalid choice\nProgram terminates\n");
      break;
    }
    free(s);
  }
  fclose(in);
  fclose(out);
  return 0;
openerr:
  fprintf(stderr, "File open error!\nCore dumped!\n");
  exit(1);
ioerr:
  fprintf(stderr, "File IO error!\nCore dumped!\n");
  exit(2);
allocerr:
  fprintf(stderr, "Allocation error!\nCore dumped!\n");
  exit(3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    121a <main+0x8a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f4 <main+0x64>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe21(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11f9 <main+0x69>
jmp    1392 <main+0x202>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <htmlenc@plt>
cmp    $0x0,%rax
je     1215 <main+0x85>
jmp    13b1 <main+0x221>
jmp    1378 <main+0x1e8>
lea    0xde3(%rip),%rdi
call   1050 <printf@plt>
lea    0xdec(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <getstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    124c <main+0xbc>
jmp    13d0 <main+0x240>
mov    -0x28(%rbp),%rdi
lea    0xda9(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    126f <main+0xdf>
jmp    1392 <main+0x202>
lea    0xdbc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1060 <getstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    129e <main+0x10e>
jmp    13d0 <main+0x240>
mov    -0x28(%rbp),%rdi
lea    0xd59(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12c1 <main+0x131>
jmp    1392 <main+0x202>
lea    0xd83(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1060 <getstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12f0 <main+0x160>
jmp    13d0 <main+0x240>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x31,%eax
je     1319 <main+0x189>
jmp    1308 <main+0x178>
mov    -0x2c(%rbp),%eax
sub    $0x32,%eax
je     133a <main+0x1aa>
jmp    135a <main+0x1ca>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <htmlenc@plt>
cmp    $0x0,%rax
je     1335 <main+0x1a5>
jmp    13b1 <main+0x221>
jmp    136f <main+0x1df>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <ascienc@plt>
cmp    $0x0,%eax
je     1355 <main+0x1c5>
jmp    13b1 <main+0x221>
jmp    136f <main+0x1df>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
lea    0xd11(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
lea    0xcfc(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
lea    0xcfc(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    0x2c09(%rip),%rax
mov    (%rax),%edi
lea    0xcfa(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1201 <main+0x61>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xf3a(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1338 <main+0x198>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe29(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1338 <main+0x198>
mov    %rax,%r12
mov    %r14,%rdi
mov    %rax,%rsi
call   10c0 <htmlenc@plt>
test   %rax,%rax
je     131a <main+0x17a>
jmp    12de <main+0x13e>
lea    0xedb(%rip),%rdi
call   1040 <puts@plt>
lea    0xdee(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <getstr@plt>
test   %rax,%rax
je     1357 <main+0x1b7>
mov    %rax,%rbx
lea    0xec2(%rip),%rsi
mov    %rax,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1338 <main+0x198>
mov    %rax,%r14
lea    0xdcd(%rip),%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1070 <getstr@plt>
test   %rax,%rax
je     1357 <main+0x1b7>
mov    %rax,%rbx
lea    0xd8b(%rip),%rsi
mov    %rax,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1338 <main+0x198>
mov    %rax,%r12
lea    0xda4(%rip),%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1070 <getstr@plt>
test   %rax,%rax
je     1357 <main+0x1b7>
mov    %rax,%r15
movsbl (%rax),%eax
cmp    $0x32,%eax
je     12cf <main+0x12f>
cmp    $0x31,%eax
jne    12fd <main+0x15d>
mov    %r14,%rdi
mov    %r12,%rsi
call   10c0 <htmlenc@plt>
test   %rax,%rax
je     1312 <main+0x172>
jmp    12de <main+0x13e>
mov    %r14,%rdi
mov    %r12,%rsi
call   1090 <ascienc@plt>
test   %eax,%eax
je     1312 <main+0x172>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
lea    0xd57(%rip),%rsi
call   1080 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
lea    0xd3f(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
lea    0xd5c(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [21 x i8] c"HTML String Encoder\0A\00"
@.str.3 = [25 x i8] c"Enter Input Filename : \00"
@.str.4 = [25 x i8] c"Enter Output Filename : \00"
@.str.5 = [48 x i8] c"Encode into:\0A1 - Regular HTML\0A2 - Full ASCII\0A? \00"
@stderr = global i32 0
@.str.6 = [35 x i8] c"Invalid choice\0AProgram terminates\0A\00"
@.str.7 = [31 x i8] c"File open error!\0ACore dumped!\0A\00"
@.str.8 = [29 x i8] c"File IO error!\0ACore dumped!\0A\00"
@.str.9 = [32 x i8] c"Allocation error!\0ACore dumped!\0A\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 3
br i1 %10, label %11, label %31
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %17, %11
br label %90
24: ; preds = %17
%25 = load i32*, i32** %6
%26 = load i32*, i32** %7
%27 = call i64 @htmlenc(i32* %25, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
br label %94
30: ; preds = %24
br label %85
31: ; preds = %2
%32 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%34 = call i8* (...) @getstr()
store i8* %34, i8** %8
%35 = icmp ne i8* %34, null
br i1 %35, label %37, label %36
36: ; preds = %31
br label %98
37: ; preds = %31
%38 = load i8*, i8** %8
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %39, i32** %6
%40 = icmp ne i32* %39, null
br i1 %40, label %42, label %41
41: ; preds = %37
br label %90
42: ; preds = %37
%43 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%44 = load i8*, i8** %8
%45 = call i32 @free(i8* %44)
%46 = call i8* (...) @getstr()
store i8* %46, i8** %8
%47 = icmp ne i8* %46, null
br i1 %47, label %49, label %48
48: ; preds = %42
br label %98
49: ; preds = %42
%50 = load i8*, i8** %8
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %51, i32** %7
%52 = icmp ne i32* %51, null
br i1 %52, label %54, label %53
53: ; preds = %49
br label %90
54: ; preds = %49
%55 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
%56 = load i8*, i8** %8
%57 = call i32 @free(i8* %56)
%58 = call i8* (...) @getstr()
store i8* %58, i8** %8
%59 = icmp ne i8* %58, null
br i1 %59, label %61, label %60
60: ; preds = %54
br label %98
61: ; preds = %54
%62 = load i8*, i8** %8
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
switch i32 %64, label %79 [
i32 49, label %65
i32 50, label %72
]
65: ; preds = %61
%66 = load i32*, i32** %6
%67 = load i32*, i32** %7
%68 = call i64 @htmlenc(i32* %66, i32* %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %65
br label %94
71: ; preds = %65
br label %82
72: ; preds = %61
%73 = load i32*, i32** %6
%74 = load i32*, i32** %7
%75 = call i32 @ascienc(i32* %73, i32* %74)
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %72
br label %94
78: ; preds = %72
br label %82
79: ; preds = %61
%80 = load i32, i32* @stderr
%81 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
br label %82
82: ; preds = %79, %78, %71
%83 = load i8*, i8** %8
%84 = call i32 @free(i8* %83)
br label %85
85: ; preds = %82, %30
%86 = load i32*, i32** %6
%87 = call i32 @fclose(i32* %86)
%88 = load i32*, i32** %7
%89 = call i32 @fclose(i32* %88)
ret i32 0
90: ; preds = %53, %41, %23
%91 = load i32, i32* @stderr
%92 = call i32 @fprintf(i32 %91, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %77, %70, %29
%95 = load i32, i32* @stderr
%96 = call i32 @fprintf(i32 %95, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%97 = call i32 @exit(i32 2)
unreachable
98: ; preds = %60, %48, %36
%99 = load i32, i32* @stderr
%100 = call i32 @fprintf(i32 %99, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
%101 = call i32 @exit(i32 3)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [25 x i8] c"Enter Input Filename : \00"
@.str.4 = [25 x i8] c"Enter Output Filename : \00"
@.str.5 = [48 x i8] c"Encode into:\0A1 - Regular HTML\0A2 - Full ASCII\0A? \00"
@stderr = global i32 0
@.str.6 = [35 x i8] c"Invalid choice\0AProgram terminates\0A\00"
@.str.7 = [31 x i8] c"File open error!\0ACore dumped!\0A\00"
@.str.8 = [29 x i8] c"File IO error!\0ACore dumped!\0A\00"
@.str.9 = [32 x i8] c"Allocation error!\0ACore dumped!\0A\00"
@str = [20 x i8] c"HTML String Encoder\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %17
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %57, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %57, label %14
14: ; preds = %9
%15 = tail call i64 @htmlenc(i32* %7, i32* %12)
%16 = icmp eq i64 %15, 0
br i1 %16, label %52, label %61
17: ; preds = %2
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%20 = tail call i8* (...) @getstr()
%21 = icmp eq i8* %20, null
br i1 %21, label %65, label %22
22: ; preds = %17
%23 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %57, label %25
25: ; preds = %22
%26 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%27 = tail call i32 @free(i8* %20)
%28 = tail call i8* (...) @getstr()
%29 = icmp eq i8* %28, null
br i1 %29, label %65, label %30
30: ; preds = %25
%31 = tail call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %57, label %33
33: ; preds = %30
%34 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
%35 = tail call i32 @free(i8* %28)
%36 = tail call i8* (...) @getstr()
%37 = icmp eq i8* %36, null
br i1 %37, label %65, label %38
38: ; preds = %33
%39 = load i8, i8* %36
%40 = sext i8 %39 to i32
switch i32 %40, label %47 [
i32 49, label %41
i32 50, label %44
]
41: ; preds = %38
%42 = tail call i64 @htmlenc(i32* %23, i32* %31)
%43 = icmp eq i64 %42, 0
br i1 %43, label %50, label %61
44: ; preds = %38
%45 = tail call i32 @ascienc(i32* %23, i32* %31)
%46 = icmp eq i32 %45, 0
br i1 %46, label %50, label %61
47: ; preds = %38
%48 = load i32, i32* @stderr
%49 = tail call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
br label %50
50: ; preds = %44, %41, %47
%51 = tail call i32 @free(i8* %36)
br label %52
52: ; preds = %14, %50
%53 = phi i32* [ %7, %14 ], [ %23, %50 ]
%54 = phi i32* [ %12, %14 ], [ %31, %50 ]
%55 = tail call i32 @fclose(i32* %53)
%56 = tail call i32 @fclose(i32* %54)
ret i32 0
57: ; preds = %30, %22, %4, %9
%58 = load i32, i32* @stderr
%59 = tail call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%60 = tail call i32 @exit(i32 1)
unreachable
61: ; preds = %44, %41, %14
%62 = load i32, i32* @stderr
%63 = tail call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
%64 = tail call i32 @exit(i32 2)
unreachable
65: ; preds = %33, %25, %17
%66 = load i32, i32* @stderr
%67 = tail call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
%68 = tail call i32 @exit(i32 3)
unreachable
}