#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 *, ...);
unsigned int fread(void *, int, int, int /*<<< orphan*/ *);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ printHelp(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  int escType = 0;
  int c;
  FILE *inFilePtr = NULL;
  FILE *outFilePtr = NULL;
  while ((c = getopt(argc, argv, "he:i:o:")) != -1) {
    switch (c) {
    case 'h':
      printHelp(argv[0]);
      return 0;
    case 'e':
      if (strcmp("url", optarg) == 0)
        escType = 0;
      else if (strcmp("php", optarg) == 0)
        escType = 1;
      else if (strcmp("html", optarg) == 0)
        escType = 2;
      else if (strcmp("urlalphanum", optarg) == 0)
        escType = 3;
      else {
        fprintf(stderr, "%s: unknown escape type '%s'\n", argv[0], optarg);
        return -1;
      }
      break;
    case 'i':
      inFilePtr = fopen(optarg, "rb");
      if (inFilePtr == NULL) {
        fprintf(stderr, "%s: failed to open file '%s'\n", argv[0], optarg);
        return -1;
      }
      break;
    case 'o':
      outFilePtr = fopen(optarg, "wb");
      if (outFilePtr == NULL) {
        fprintf(stderr, "%s: failed to open file '%s'\n", argv[0], optarg);
        return -1;
      }
      break;
    default:
      break;
    }
  }
  if (inFilePtr == NULL) {
    inFilePtr = stdin;
  }
  if (outFilePtr == NULL) {
    outFilePtr = stdout;
  }
  unsigned char buf[1024];
  unsigned int bytesRead;
  while ((bytesRead = fread((void *)buf, sizeof(char), 1024, inFilePtr)) != 0) {
    int n;
    for (n = 0; n < 1024 && n < bytesRead; n++) {
      switch (escType) {
      case 0:
        fprintf(outFilePtr, "%%%02x", buf[n]);
        break;
      case 3:
        if ((buf[n] >= 0x30 && buf[n] <= 0x39) ||
            (buf[n] >= 0x41 && buf[n] <= 0x5A) ||
            (buf[n] >= 0x61 && buf[n] <= 0x7A)) {
          fprintf(outFilePtr, "%c", buf[n]);
        } else if (buf[n] == 0x20) {
          fprintf(outFilePtr, "+");
        } else {
          fprintf(outFilePtr, "%%%02x", buf[n]);
        }
        break;
      case 1:
        fprintf(outFilePtr, "\\x%02x", buf[n]);
        break;
      case 2:
        fprintf(outFilePtr, "&#%d;", buf[n]);
        break;
      }
    }
  }
  if (outFilePtr == stdout)
    printf("\n");
  fclose(inFilePtr);
  fclose(outFilePtr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     13d3 <main+0x253>
mov    -0x18(%rbp),%eax
add    $0xffffff9b,%eax
mov    %eax,%ecx
mov    %rcx,-0x440(%rbp)
sub    $0xa,%eax
ja     13c9 <main+0x249>
mov    -0x440(%rbp),%rax
lea    0xe1b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <printHelp@plt>
movl   $0x0,-0x4(%rbp)
jmp    167c <main+0x4fc>
mov    0x2ddb(%rip),%rax
mov    (%rax),%rsi
lea    0xe1d(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1241 <main+0xc1>
movl   $0x0,-0x14(%rbp)
jmp    1306 <main+0x186>
mov    0x2db0(%rip),%rax
mov    (%rax),%rsi
lea    0xdf6(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    126c <main+0xec>
movl   $0x1,-0x14(%rbp)
jmp    1301 <main+0x181>
mov    0x2d85(%rip),%rax
mov    (%rax),%rsi
lea    0xdcf(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1297 <main+0x117>
movl   $0x2,-0x14(%rbp)
jmp    12fc <main+0x17c>
mov    0x2d5a(%rip),%rax
mov    (%rax),%rsi
lea    0xda9(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12c2 <main+0x142>
movl   $0x3,-0x14(%rbp)
jmp    12f7 <main+0x177>
mov    0x2d07(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    0x2d1e(%rip),%rax
mov    (%rax),%rcx
lea    0xd79(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    167c <main+0x4fc>
jmp    12fc <main+0x17c>
jmp    1301 <main+0x181>
jmp    1306 <main+0x186>
jmp    13ce <main+0x24e>
mov    0x2ce6(%rip),%rax
mov    (%rax),%rdi
lea    0xd5f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1365 <main+0x1e5>
mov    0x2c99(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    0x2cb0(%rip),%rax
mov    (%rax),%rcx
lea    0xd2c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    167c <main+0x4fc>
jmp    13ce <main+0x24e>
mov    0x2c87(%rip),%rax
mov    (%rax),%rdi
lea    0xd21(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    13c4 <main+0x244>
mov    0x2c3a(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    0x2c51(%rip),%rax
mov    (%rax),%rcx
lea    0xccd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    167c <main+0x4fc>
jmp    13ce <main+0x24e>
jmp    13ce <main+0x24e>
jmp    11b0 <main+0x30>
cmpq   $0x0,-0x20(%rbp)
jne    13ec <main+0x26c>
mov    0x2bfb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1405 <main+0x285>
mov    0x2bca(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    140a <main+0x28a>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %eax,-0x434(%rbp)
cmp    $0x0,%eax
je     1643 <main+0x4c3>
movl   $0x0,-0x438(%rbp)
xor    %eax,%eax
cmpl   $0x400,-0x438(%rbp)
mov    %al,-0x441(%rbp)
jge    146a <main+0x2ea>
mov    -0x438(%rbp),%eax
cmp    -0x434(%rbp),%eax
setb   %al
mov    %al,-0x441(%rbp)
mov    -0x441(%rbp),%al
test   $0x1,%al
jne    147d <main+0x2fd>
jmp    163e <main+0x4be>
mov    -0x14(%rbp),%eax
mov    %rax,-0x450(%rbp)
sub    $0x3,%rax
ja     1625 <main+0x4a5>
mov    -0x450(%rbp),%rax
lea    0xb61(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x28(%rbp),%rdi
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%edx
ff
lea    0xbdd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1625 <main+0x4a5>
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%eax
ff
cmp    $0x30,%eax
jl     14fe <main+0x37e>
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%eax
ff
cmp    $0x39,%eax
jle    155e <main+0x3de>
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%eax
ff
cmp    $0x41,%eax
jl     152e <main+0x3ae>
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%eax
ff
cmp    $0x5a,%eax
jle    155e <main+0x3de>
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%eax
ff
cmp    $0x61,%eax
jl     1584 <main+0x404>
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%eax
ff
cmp    $0x7a,%eax
jg     1584 <main+0x404>
mov    -0x28(%rbp),%rdi
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%edx
ff
lea    0xb2e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15d9 <main+0x459>
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jne    15b3 <main+0x433>
mov    -0x28(%rbp),%rdi
lea    0xb02(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15d4 <main+0x454>
mov    -0x28(%rbp),%rdi
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%edx
ff
lea    0xad2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15d9 <main+0x459>
jmp    1625 <main+0x4a5>
mov    -0x28(%rbp),%rdi
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%edx
ff
lea    0xab3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1625 <main+0x4a5>
mov    -0x28(%rbp),%rdi
movslq -0x438(%rbp),%rax
movzbl -0x430(%rbp,%rax,1),%edx
ff
lea    0xa94(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    162a <main+0x4aa>
mov    -0x438(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x438(%rbp)
jmp    143d <main+0x2bd>
jmp    140a <main+0x28a>
mov    -0x28(%rbp),%rax
mov    0x297a(%rip),%rcx
cmp    (%rcx),%rax
jne    1663 <main+0x4e3>
lea    0xa3c(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
xor    %r14d,%r14d
lea    0xe8c(%rip),%r12
lea    0xe49(%rip),%r13
xor    %eax,%eax
mov    %rax,(%rsp)
xor    %ebx,%ebx
jmp    11d9 <main+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     12fd <main+0x16d>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   10b0 <getopt@plt>
lea    -0x65(%rax),%ecx
cmp    $0xa,%ecx
ja     11d0 <main+0x40>
movslq 0x0(%r13,%rcx,4),%rax
add    %r13,%rax
jmp    *%rax
mov    0x2df9(%rip),%rax
mov    (%rax),%rsi
lea    0xe3b(%rip),%rdi
mov    %rsi,0x8(%rsp)
call   1080 <strcmp@plt>
mov    $0x0,%r14d
test   %eax,%eax
je     11d9 <main+0x49>
lea    0xe24(%rip),%rdi
mov    0x8(%rsp),%rsi
call   1080 <strcmp@plt>
mov    $0x1,%r14d
test   %eax,%eax
je     11d9 <main+0x49>
lea    0xe0d(%rip),%rdi
mov    0x8(%rsp),%rsi
call   1080 <strcmp@plt>
mov    $0x2,%r14d
test   %eax,%eax
je     11d9 <main+0x49>
lea    0xdf7(%rip),%rdi
mov    0x8(%rsp),%rsi
call   1080 <strcmp@plt>
mov    $0x3,%r14d
test   %eax,%eax
je     11d9 <main+0x49>
jmp    14a1 <main+0x311>
mov    0x2d7a(%rip),%rax
mov    (%rax),%rdi
lea    0xdf3(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rcx
mov    %rax,(%rsp)
test   %rax,%rax
jne    11d9 <main+0x49>
jmp    12c1 <main+0x131>
mov    0x2d52(%rip),%rax
mov    (%rax),%rdi
lea    0xdec(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d9 <main+0x49>
mov    0x2d08(%rip),%rax
movslq (%rax),%rdi
mov    (%r15),%rdx
mov    0x2d23(%rip),%rax
mov    (%rax),%rcx
lea    0xd9f(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    148f <main+0x2ff>
mov    (%r15),%rdi
call   1030 <printHelp@plt>
jmp    148d <main+0x2fd>
cmpq   $0x0,(%rsp)
jne    1312 <main+0x182>
mov    0x2cd5(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
mov    0x2caf(%rip),%rax
test   %rbx,%rbx
jne    1321 <main+0x191>
mov    (%rax),%rbx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    (%rsp),%rcx
call   1050 <fread@plt>
test   %eax,%eax
je     1466 <main+0x2d6>
mov    %r14d,%ecx
lea    0xce1(%rip),%rdx
movslq (%rdx,%rcx,4),%r15
add    %rdx,%r15
lea    0xd46(%rip),%rbp
lea    0xd4d(%rip),%r13
jmp    1390 <main+0x200>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    (%rsp),%rcx
call   1050 <fread@plt>
test   %eax,%eax
je     1466 <main+0x2d6>
mov    %eax,%r14d
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
jmp    *%r15
movzbl 0x10(%rsp,%r12,1),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
jmp    1440 <main+0x2b0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x10(%rsp,%r12,1),%edx
mov    %rbx,%rdi
lea    0xcd6(%rip),%rsi
jmp    1440 <main+0x2b0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x10(%rsp,%r12,1),%edx
mov    %rbx,%rdi
mov    %r13,%rsi
jmp    1440 <main+0x2b0>
xchg   %ax,%ax
movzbl 0x10(%rsp,%r12,1),%edx
lea    -0x30(%rdx),%eax
cmp    $0xa,%al
jb     1417 <main+0x287>
lea    -0x41(%rdx),%eax
cmp    $0x1a,%al
jb     1417 <main+0x287>
lea    -0x61(%rdx),%eax
cmp    $0x19,%al
jbe    1417 <main+0x287>
cmp    $0x20,%dl
jne    142f <main+0x29f>
mov    $0x2b,%edi
jmp    1419 <main+0x289>
mov    %edx,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
cmp    $0x3fe,%r12
jbe    1454 <main+0x2c4>
jmp    1370 <main+0x1e0>
mov    %rbx,%rdi
mov    %rbp,%rsi
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1090 <fprintf@plt>
cmp    $0x3fe,%r12
ja     1370 <main+0x1e0>
add    $0x1,%r12
cmp    %r14,%r12
jb     13a0 <main+0x210>
jmp    1370 <main+0x1e0>
mov    0x2b5b(%rip),%rax
cmp    (%rax),%rbx
jne    147c <main+0x2ec>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    (%rsp),%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b28(%rip),%rax
movslq (%rax),%rdi
mov    (%r15),%rdx
lea    0xba8(%rip),%rsi
mov    0x8(%rsp),%rcx
jmp    12df <main+0x14f>

LLVM IR (-O0):
@.str = [8 x i8] c"he:i:o:\00"
@.str.1 = [4 x i8] c"url\00"
@optarg = global i8* null
@.str.2 = [4 x i8] c"php\00"
@.str.3 = [5 x i8] c"html\00"
@.str.4 = [12 x i8] c"urlalphanum\00"
@stderr = global i32 0
@.str.5 = [30 x i8] c"%s: unknown escape type '%s'\0A\00"
@.str.6 = [3 x i8] c"rb\00"
@.str.7 = [30 x i8] c"%s: failed to open file '%s'\0A\00"
@.str.8 = [3 x i8] c"wb\00"
@stdin = global i32* null
@stdout = global i32* null
@.str.9 = [7 x i8] c"%%%02x\00"
@.str.10 = [3 x i8] c"%c\00"
@.str.11 = [2 x i8] c"+\00"
@.str.12 = [7 x i8] c"\\x%02x\00"
@.str.13 = [6 x i8] c"&#%d;\00"
@.str.14 = [2 x i8] c"\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 i32*
%9 = alloca i32*
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32* null, i32** %8
store i32* null, i32** %9
br label %13
13: ; preds = %89, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %7
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %90
18: ; preds = %13
%19 = load i32, i32* %7
switch i32 %19, label %88 [
i32 104, label %20
i32 101, label %25
i32 105, label %58
i32 111, label %73
]
20: ; preds = %18
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 @printHelp(i8* %23)
store i32 0, i32* %3
br label %228
25: ; preds = %18
%26 = load i8*, i8** @optarg
%27 = call i32 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 0, i32* %6
br label %57
30: ; preds = %25
%31 = load i8*, i8** @optarg
%32 = call i32 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 1, i32* %6
br label %56
35: ; preds = %30
%36 = load i8*, i8** @optarg
%37 = call i32 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 2, i32* %6
br label %55
40: ; preds = %35
%41 = load i8*, i8** @optarg
%42 = call i32 @strcmp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 3, i32* %6
br label %54
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = sext i32 %46 to i64
%48 = inttoptr i64 %47 to i32*
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 0
%51 = load i8*, i8** %50
%52 = load i8*, i8** @optarg
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %51, i8* %52)
store i32 -1, i32* %3
br label %228
54: ; preds = %44
br label %55
55: ; preds = %54, %39
br label %56
56: ; preds = %55, %34
br label %57
57: ; preds = %56, %29
br label %89
58: ; preds = %18
%59 = load i8*, i8** @optarg
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %60, i32** %8
%61 = load i32*, i32** %8
%62 = icmp eq i32* %61, null
br i1 %62, label %63, label %72
63: ; preds = %58
%64 = load i32, i32* @stderr
%65 = sext i32 %64 to i64
%66 = inttoptr i64 %65 to i32*
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 0
%69 = load i8*, i8** %68
%70 = load i8*, i8** @optarg
%71 = call i32 (i32*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %69, i8* %70)
store i32 -1, i32* %3
br label %228
72: ; preds = %58
br label %89
73: ; preds = %18
%74 = load i8*, i8** @optarg
%75 = call i32* @fopen(i8* %74, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %75, i32** %9
%76 = load i32*, i32** %9
%77 = icmp eq i32* %76, null
br i1 %77, label %78, label %87
78: ; preds = %73
%79 = load i32, i32* @stderr
%80 = sext i32 %79 to i64
%81 = inttoptr i64 %80 to i32*
%82 = load i8**, i8*** %5
%83 = getelementptr inbounds i8*, i8** %82, i64 0
%84 = load i8*, i8** %83
%85 = load i8*, i8** @optarg
%86 = call i32 (i32*, i8*, ...) @fprintf(i32* %81, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %84, i8* %85)
store i32 -1, i32* %3
br label %228
87: ; preds = %73
br label %89
88: ; preds = %18
br label %89
89: ; preds = %88, %87, %72, %57
br label %13
90: ; preds = %13
%91 = load i32*, i32** %8
%92 = icmp eq i32* %91, null
br i1 %92, label %93, label %95
93: ; preds = %90
%94 = load i32*, i32** @stdin
store i32* %94, i32** %8
br label %95
95: ; preds = %93, %90
%96 = load i32*, i32** %9
%97 = icmp eq i32* %96, null
br i1 %97, label %98, label %100
98: ; preds = %95
%99 = load i32*, i32** @stdout
store i32* %99, i32** %9
br label %100
100: ; preds = %98, %95
br label %101
101: ; preds = %216, %100
%102 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%103 = load i32*, i32** %8
%104 = call i32 @fread(i8* %102, i32 1, i32 1024, i32* %103)
store i32 %104, i32* %11
%105 = icmp ne i32 %104, 0
br i1 %105, label %106, label %217
106: ; preds = %101
store i32 0, i32* %12
br label %107
107: ; preds = %213, %106
%108 = load i32, i32* %12
%109 = icmp slt i32 %108, 1024
br i1 %109, label %110, label %114
110: ; preds = %107
%111 = load i32, i32* %12
%112 = load i32, i32* %11
%113 = icmp ult i32 %111, %112
br label %114
114: ; preds = %110, %107
%115 = phi i1 [ false, %107 ], [ %113, %110 ]
br i1 %115, label %116, label %216
116: ; preds = %114
%117 = load i32, i32* %6
switch i32 %117, label %212 [
i32 0, label %118
i32 3, label %126
i32 1, label %196
i32 2, label %204
]
118: ; preds = %116
%119 = load i32*, i32** %9
%120 = load i32, i32* %12
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %121
%123 = load i8, i8* %122
%124 = zext i8 %123 to i32
%125 = call i32 (i32*, i8*, ...) @fprintf(i32* %119, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %124)
br label %212
126: ; preds = %116
%127 = load i32, i32* %12
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %128
%130 = load i8, i8* %129
%131 = zext i8 %130 to i32
%132 = icmp sge i32 %131, 48
br i1 %132, label %133, label %140
133: ; preds = %126
%134 = load i32, i32* %12
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %135
%137 = load i8, i8* %136
%138 = zext i8 %137 to i32
%139 = icmp sle i32 %138, 57
br i1 %139, label %168, label %140
140: ; preds = %133, %126
%141 = load i32, i32* %12
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %142
%144 = load i8, i8* %143
%145 = zext i8 %144 to i32
%146 = icmp sge i32 %145, 65
br i1 %146, label %147, label %154
147: ; preds = %140
%148 = load i32, i32* %12
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %149
%151 = load i8, i8* %150
%152 = zext i8 %151 to i32
%153 = icmp sle i32 %152, 90
br i1 %153, label %168, label %154
154: ; preds = %147, %140
%155 = load i32, i32* %12
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %156
%158 = load i8, i8* %157
%159 = zext i8 %158 to i32
%160 = icmp sge i32 %159, 97
br i1 %160, label %161, label %176
161: ; preds = %154
%162 = load i32, i32* %12
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %163
%165 = load i8, i8* %164
%166 = zext i8 %165 to i32
%167 = icmp sle i32 %166, 122
br i1 %167, label %168, label %176
168: ; preds = %161, %147, %133
%169 = load i32*, i32** %9
%170 = load i32, i32* %12
%171 = sext i32 %170 to i64
%172 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %171
%173 = load i8, i8* %172
%174 = zext i8 %173 to i32
%175 = call i32 (i32*, i8*, ...) @fprintf(i32* %169, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 %174)
br label %195
176: ; preds = %161, %154
%177 = load i32, i32* %12
%178 = sext i32 %177 to i64
%179 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %178
%180 = load i8, i8* %179
%181 = zext i8 %180 to i32
%182 = icmp eq i32 %181, 32
br i1 %182, label %183, label %186
183: ; preds = %176
%184 = load i32*, i32** %9
%185 = call i32 (i32*, i8*, ...) @fprintf(i32* %184, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %194
186: ; preds = %176
%187 = load i32*, i32** %9
%188 = load i32, i32* %12
%189 = sext i32 %188 to i64
%190 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %189
%191 = load i8, i8* %190
%192 = zext i8 %191 to i32
%193 = call i32 (i32*, i8*, ...) @fprintf(i32* %187, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %192)
br label %194
194: ; preds = %186, %183
br label %195
195: ; preds = %194, %168
br label %212
196: ; preds = %116
%197 = load i32*, i32** %9
%198 = load i32, i32* %12
%199 = sext i32 %198 to i64
%200 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %199
%201 = load i8, i8* %200
%202 = zext i8 %201 to i32
%203 = call i32 (i32*, i8*, ...) @fprintf(i32* %197, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i32 %202)
br label %212
204: ; preds = %116
%205 = load i32*, i32** %9
%206 = load i32, i32* %12
%207 = sext i32 %206 to i64
%208 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %207
%209 = load i8, i8* %208
%210 = zext i8 %209 to i32
%211 = call i32 (i32*, i8*, ...) @fprintf(i32* %205, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0), i32 %210)
br label %212
212: ; preds = %116, %204, %196, %195, %118
br label %213
213: ; preds = %212
%214 = load i32, i32* %12
%215 = add nsw i32 %214, 1
store i32 %215, i32* %12
br label %107
216: ; preds = %114
br label %101
217: ; preds = %101
%218 = load i32*, i32** %9
%219 = load i32*, i32** @stdout
%220 = icmp eq i32* %218, %219
br i1 %220, label %221, label %223
221: ; preds = %217
%222 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
br label %223
223: ; preds = %221, %217
%224 = load i32*, i32** %8
%225 = call i32 @fclose(i32* %224)
%226 = load i32*, i32** %9
%227 = call i32 @fclose(i32* %226)
store i32 0, i32* %3
br label %228
228: ; preds = %223, %78, %63, %45, %20
%229 = load i32, i32* %3
ret i32 %229
}

LLVM IR (-O2):
@.str = [8 x i8] c"he:i:o:\00"
@.str.1 = [4 x i8] c"url\00"
@optarg = global i8* null
@.str.2 = [4 x i8] c"php\00"
@.str.3 = [5 x i8] c"html\00"
@.str.4 = [12 x i8] c"urlalphanum\00"
@stderr = global i32 0
@.str.5 = [30 x i8] c"%s: unknown escape type '%s'\0A\00"
@.str.6 = [3 x i8] c"rb\00"
@.str.7 = [30 x i8] c"%s: failed to open file '%s'\0A\00"
@.str.8 = [3 x i8] c"wb\00"
@stdin = global i32* null
@stdout = global i32* null
@.str.9 = [7 x i8] c"%%%02x\00"
@.str.12 = [7 x i8] c"\\x%02x\00"
@.str.13 = [6 x i8] c"&#%d;\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1024 x i8]
br label %4
4: ; preds = %22, %2
%5 = phi i32 [ 0, %2 ], [ %23, %22 ]
%6 = phi i32* [ null, %2 ], [ %9, %22 ]
%7 = phi i32* [ null, %2 ], [ %12, %22 ]
br label %8
8: ; preds = %4, %39
%9 = phi i32* [ %6, %4 ], [ %41, %39 ]
%10 = phi i32* [ %7, %4 ], [ %12, %39 ]
br label %11
11: ; preds = %8, %50
%12 = phi i32* [ %10, %8 ], [ %52, %50 ]
br label %13
13: ; preds = %11, %13
%14 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
switch i32 %14, label %13 [
i32 -1, label %61
i32 104, label %15
i32 101, label %18
i32 105, label %39
i32 111, label %50
]
15: ; preds = %13
%16 = load i8*, i8** %1
%17 = tail call i32 @printHelp(i8* %16)
br label %129
18: ; preds = %13
%19 = load i8*, i8** @optarg
%20 = tail call i32 @strcmp(i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18, %24, %27, %30
%23 = phi i32 [ 3, %30 ], [ 2, %27 ], [ 1, %24 ], [ 0, %18 ]
br label %4
24: ; preds = %18
%25 = tail call i32 @strcmp(i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(1) %19)
%26 = icmp eq i32 %25, 0
br i1 %26, label %22, label %27
27: ; preds = %24
%28 = tail call i32 @strcmp(i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* dereferenceable(1) %19)
%29 = icmp eq i32 %28, 0
br i1 %29, label %22, label %30
30: ; preds = %27
%31 = tail call i32 @strcmp(i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* dereferenceable(1) %19)
%32 = icmp eq i32 %31, 0
br i1 %32, label %22, label %33
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i32*
%37 = load i8*, i8** %1
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %37, i8* %19)
br label %129
39: ; preds = %13
%40 = load i8*, i8** @optarg
%41 = tail call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %8
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = sext i32 %44 to i64
%46 = inttoptr i64 %45 to i32*
%47 = load i8*, i8** %1
%48 = load i8*, i8** @optarg
%49 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %47, i8* %48)
br label %129
50: ; preds = %13
%51 = load i8*, i8** @optarg
%52 = tail call i32* @fopen(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %11
54: ; preds = %50
%55 = load i32, i32* @stderr
%56 = sext i32 %55 to i64
%57 = inttoptr i64 %56 to i32*
%58 = load i8*, i8** %1
%59 = load i8*, i8** @optarg
%60 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %58, i8* %59)
br label %129
61: ; preds = %13
%62 = icmp eq i32* %9, null
%63 = load i32*, i32** @stdin
%64 = select i1 %62, i32* %63, i32* %9
%65 = icmp eq i32* %12, null
%66 = load i32*, i32** @stdout
%67 = select i1 %65, i32* %66, i32* %12
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%69 = call i32 @fread(i8* %68, i32 1, i32 1024, i32* %64)
%70 = icmp eq i32 %69, 0
br i1 %70, label %121, label %74
71: ; preds = %116
%72 = call i32 @fread(i8* %68, i32 1, i32 1024, i32* %64)
%73 = icmp eq i32 %72, 0
br i1 %73, label %121, label %74
74: ; preds = %61, %71
%75 = phi i32 [ %72, %71 ], [ %69, %61 ]
%76 = zext i32 %75 to i64
br label %77
77: ; preds = %74, %116
%78 = phi i64 [ 0, %74 ], [ %117, %116 ]
switch i32 %5, label %115 [
i32 0, label %79
i32 3, label %84
i32 1, label %105
i32 2, label %110
]
79: ; preds = %77
%80 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %78
%81 = load i8, i8* %80
%82 = zext i8 %81 to i32
%83 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %82)
br label %116
84: ; preds = %77
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %78
%86 = load i8, i8* %85
%87 = add i8 %86, -48
%88 = icmp ult i8 %87, 10
%89 = add i8 %86, -65
%90 = icmp ult i8 %89, 26
%91 = or i1 %88, %90
%92 = add i8 %86, -97
%93 = icmp ult i8 %92, 26
%94 = select i1 %91, i1 true, i1 %93
br i1 %94, label %95, label %98
95: ; preds = %84
%96 = zext i8 %86 to i32
%97 = tail call i32 @fputc(i32 %96, i32* %67)
br label %116
98: ; preds = %84
%99 = icmp eq i8 %86, 32
br i1 %99, label %100, label %102
100: ; preds = %98
%101 = tail call i32 @fputc(i32 43, i32* %67)
br label %116
102: ; preds = %98
%103 = zext i8 %86 to i32
%104 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %103)
br label %116
105: ; preds = %77
%106 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %78
%107 = load i8, i8* %106
%108 = zext i8 %107 to i32
%109 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i32 %108)
br label %116
110: ; preds = %77
%111 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %78
%112 = load i8, i8* %111
%113 = zext i8 %112 to i32
%114 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0), i32 %113)
br label %116
115: ; preds = %77
unreachable
116: ; preds = %79, %105, %110, %100, %102, %95
%117 = add nuw nsw i64 %78, 1
%118 = icmp ult i64 %78, 1023
%119 = icmp ult i64 %117, %76
%120 = and i1 %118, %119
br i1 %120, label %77, label %71
121: ; preds = %71, %61
%122 = load i32*, i32** @stdout
%123 = icmp eq i32* %67, %122
br i1 %123, label %124, label %126
124: ; preds = %121
%125 = tail call i32 @putchar(i32 10)
br label %126
126: ; preds = %124, %121
%127 = tail call i32 @fclose(i32* %64)
%128 = tail call i32 @fclose(i32* %67)
br label %129
129: ; preds = %126, %54, %43, %33, %15
%130 = phi i32 [ -1, %54 ], [ -1, %43 ], [ -1, %33 ], [ 0, %15 ], [ 0, %126 ]
ret i32 %130
}