#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*/ MCParse(int);
int /*<<< orphan*/ MCReadCat(int);
int /*<<< orphan*/ MCWriteCat(int);
int O_CREAT;
int O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ writeIfChanged(char *, int, int);
int main(int argc, char *argv[]) {
  int ofd, ifd, i;
  FILE *fptr;
  char *catfile = NULL;
  char *input = NULL;
  int lang = 0;
  int new = 0;
  int orConsts = 0;
  for (i = 1; i < argc; ++i) {
    if (argv[i][0] == '-') {
      if (strcmp(argv[i], "-lang") == 0) {
        ++i;
        if (strcmp(argv[i], "C") == 0)
          lang = 0;
        else if (strcmp(argv[i], "C++") == 0)
          lang = 1;
        else if (strcmp(argv[i], "ANSIC") == 0)
          lang = 2;
        else {
          fprintf(stderr, "gencat: Unrecognized language: %s\n", argv[i]);
          exit(1);
        }
      } else if (strncmp(argv[i], "-h", 2) == 0) {
        if (!input) {
          fprintf(
              stderr,
              "gencat: Can't write to a header before reading something.\n");
          exit(1);
        }
        ++i;
        writeIfChanged(argv[i], lang, orConsts);
      } else if (strncmp(argv[i], "-new", 4) == 0) {
        if (catfile) {
          fprintf(
              stderr,
              "gencat: You must specify -new before the catalog file name\n");
          exit(1);
        }
        new = ~0;
      } else if (strncmp(argv[i], "-or", 3) == 0) {
        orConsts = ~orConsts;
      } else {
        usage();
        exit(1);
      }
    } else {
      if (!catfile) {
        catfile = argv[i];
        if (new) {
          if ((ofd = open(catfile, O_WRONLY | O_TRUNC | O_CREAT, 0666)) < 0) {
            fprintf(stderr, "gencat: Unable to create a new %s.\n", catfile);
            exit(1);
          }
        } else if ((ofd = open(catfile, O_RDONLY)) < 0) {
          if ((ofd = open(catfile, O_WRONLY | O_CREAT, 0666)) < 0) {
            fprintf(stderr, "gencat: Unable to create %s.\n", catfile);
            exit(1);
          }
        } else {
          MCReadCat(ofd);
          close(ofd);
          if ((ofd = open(catfile, O_WRONLY | O_TRUNC)) < 0) {
            fprintf(stderr, "gencat: Unable to truncate %s.\n", catfile);
            exit(1);
          }
        }
      } else {
        input = argv[i];
        if ((ifd = open(input, O_RDONLY)) < 0) {
          fprintf(stderr, "gencat: Unable to read %s\n", input);
          exit(1);
        }
        MCParse(ifd);
        close(ifd);
      }
    }
  }
  if (catfile) {
    MCWriteCat(ofd);
    exit(0);
  } else {
    usage();
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1620 <main+0x470>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1438 <main+0x288>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdd7(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1307 <main+0x157>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdba(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    126f <main+0xbf>
movl   $0x0,-0x3c(%rbp)
jmp    1302 <main+0x152>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd84(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    129d <main+0xed>
movl   $0x1,-0x3c(%rbp)
jmp    12fd <main+0x14d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd5a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12cb <main+0x11b>
movl   $0x2,-0x3c(%rbp)
jmp    12f8 <main+0x148>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd29(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    12fd <main+0x14d>
jmp    1302 <main+0x152>
jmp    1433 <main+0x283>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd19(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    137f <main+0x1cf>
cmpq   $0x0,-0x38(%rbp)
jne    135a <main+0x1aa>
mov    0x2c88(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x44(%rbp),%edx
call   10d0 <writeIfChanged@plt>
jmp    142e <main+0x27e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xcdf(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    13de <main+0x22e>
cmpq   $0x0,-0x30(%rbp)
je     13d2 <main+0x222>
mov    0x2c10(%rip),%rax
mov    (%rax),%edi
lea    0xcb5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0xffffffff,-0x40(%rbp)
jmp    1429 <main+0x279>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xcc1(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1413 <main+0x263>
mov    -0x44(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    1424 <main+0x274>
mov    $0x0,%al
call   1090 <usage@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1429 <main+0x279>
jmp    142e <main+0x27e>
jmp    1433 <main+0x283>
jmp    160d <main+0x45d>
cmpq   $0x0,-0x30(%rbp)
jne    15a3 <main+0x3f3>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x40(%rbp)
je     14be <main+0x30e>
mov    -0x30(%rbp),%rdi
mov    0x2b50(%rip),%rax
mov    (%rax),%esi
mov    0x2b7f(%rip),%rax
or     (%rax),%esi
mov    0x2b7e(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    14b9 <main+0x309>
mov    0x2b2d(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xc0e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    159e <main+0x3ee>
mov    -0x30(%rbp),%rdi
mov    0x2b0f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1536 <main+0x386>
mov    -0x30(%rbp),%rdi
mov    0x2acf(%rip),%rax
mov    (%rax),%esi
mov    0x2b06(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1531 <main+0x381>
mov    0x2ab5(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xbba(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1599 <main+0x3e9>
mov    -0x14(%rbp),%edi
call   1040 <MCReadCat@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%rdi
mov    0x2a67(%rip),%rax
mov    (%rax),%esi
mov    0x2a96(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1594 <main+0x3e4>
mov    0x2a52(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xb75(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1599 <main+0x3e9>
jmp    159e <main+0x3ee>
jmp    1608 <main+0x458>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2a1a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    15f8 <main+0x448>
mov    0x29ee(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xb31(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
call   10c0 <MCParse@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
jmp    160d <main+0x45d>
jmp    1612 <main+0x462>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f2 <main+0x42>
cmpq   $0x0,-0x30(%rbp)
je     163a <main+0x48a>
mov    -0x14(%rbp),%edi
call   1080 <MCWriteCat@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1090 <usage@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     1468 <main+0x2b8>
mov    %rsi,%rbx
mov    %edi,%r12d
mov    $0x1,%r13d
movl   $0x0,0xc(%rsp)
movl   $0x0,(%rsp)
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %ebp,%ebp
jmp    120d <main+0x5d>
movl   $0x0,0x4(%rsp)
nopl   (%rax)
add    $0x1,%r13d
cmp    %r12d,%r13d
jge    1463 <main+0x2b3>
movslq %r13d,%r15
mov    (%rbx,%r15,8),%r14
cmpb   $0x2d,(%r14)
jne    12a0 <main+0xf0>
mov    %r14,%rdi
lea    0xdd8(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12e0 <main+0x130>
mov    (%rbx,%r15,8),%rdi
lea    0xdf2(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1390 <main+0x1e0>
mov    (%rbx,%r15,8),%rdi
lea    0xe12(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     13b7 <main+0x207>
mov    (%rbx,%r15,8),%rdi
lea    0xe35(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1468 <main+0x2b8>
notl   0xc(%rsp)
jmp    1200 <main+0x50>
nopl   0x0(%rax)
test   %rbp,%rbp
je     1341 <main+0x191>
mov    0x2d28(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     1489 <main+0x2d9>
mov    %eax,%r15d
mov    %eax,%edi
call   10c0 <MCParse@plt>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %r14,0x10(%rsp)
jmp    1200 <main+0x50>
lea    0x1(%r15),%r13d
mov    0x8(%rbx,%r15,8),%rdi
lea    0xd1e(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11f5 <main+0x45>
add    $0x1,%r15
mov    (%rbx,%r15,8),%rdi
lea    0xcf9(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     141a <main+0x26a>
mov    (%rbx,%r15,8),%rdi
lea    0xce4(%rip),%rsi
call   1060 <strcmp@plt>
movl   $0x2,0x4(%rsp)
test   %rax,%rax
je     1200 <main+0x50>
jmp    14bf <main+0x30f>
cmpl   $0x0,(%rsp)
je     13ce <main+0x21e>
mov    0x2c9e(%rip),%rax
mov    (%rax),%esi
mov    0x2c5d(%rip),%rax
or     (%rax),%esi
mov    0x2c94(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     149b <main+0x2eb>
mov    %eax,0x8(%rsp)
movl   $0xffffffff,(%rsp)
mov    %r14,%rbp
jmp    1200 <main+0x50>
cmpq   $0x0,0x10(%rsp)
je     14ad <main+0x2fd>
lea    0x1(%r15),%r13d
mov    0x8(%rbx,%r15,8),%rdi
mov    0x4(%rsp),%esi
mov    0xc(%rsp),%edx
call   10d0 <writeIfChanged@plt>
jmp    1200 <main+0x50>
test   %rbp,%rbp
jne    14d5 <main+0x325>
movl   $0xffffffff,(%rsp)
xor    %ebp,%ebp
jmp    1200 <main+0x50>
mov    0x2c03(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     1427 <main+0x277>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <MCReadCat@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x2bf4(%rip),%rax
mov    (%rax),%esi
mov    0x2bb3(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
jns    1450 <main+0x2a0>
jmp    14f6 <main+0x346>
movl   $0x1,0x4(%rsp)
jmp    1200 <main+0x50>
mov    0x2bca(%rip),%rax
mov    (%rax),%esi
mov    0x2b81(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     1508 <main+0x358>
mov    %eax,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %r14,%rbp
jmp    1200 <main+0x50>
test   %rbp,%rbp
jne    1479 <main+0x2c9>
xor    %eax,%eax
call   1090 <usage@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x8(%rsp),%edi
call   1080 <MCWriteCat@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2b38(%rip),%rax
mov    (%rax),%edi
lea    0xc7f(%rip),%rsi
jmp    1518 <main+0x368>
mov    0x2b26(%rip),%rax
mov    (%rax),%edi
lea    0xc0b(%rip),%rsi
jmp    1518 <main+0x368>
mov    0x2b14(%rip),%rax
mov    (%rax),%edi
lea    0xb79(%rip),%rsi
jmp    14e5 <main+0x335>
mov    0x2b02(%rip),%rax
mov    (%rax),%edi
mov    (%rbx,%r15,8),%rdx
lea    0xb3d(%rip),%rsi
jmp    151b <main+0x36b>
mov    0x2aec(%rip),%rax
mov    (%rax),%edi
lea    0xb91(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2acb(%rip),%rax
mov    (%rax),%edi
lea    0xbf2(%rip),%rsi
jmp    1518 <main+0x368>
mov    0x2ab9(%rip),%rax
mov    (%rax),%edi
lea    0xbc2(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"-lang\00"
@.str.1 = [2 x i8] c"C\00"
@.str.2 = [4 x i8] c"C++\00"
@.str.3 = [6 x i8] c"ANSIC\00"
@stderr = global i32 0
@.str.4 = [35 x i8] c"gencat: Unrecognized language: %s\0A\00"
@.str.5 = [3 x i8] c"-h\00"
@.str.6 = [59 x i8] c"gencat: Can't write to a header before reading something.\0A\00"
@.str.7 = [5 x i8] c"-new\00"
@.str.8 = [60 x i8] c"gencat: You must specify -new before the catalog file name\0A\00"
@.str.9 = [4 x i8] c"-or\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.10 = [36 x i8] c"gencat: Unable to create a new %s.\0A\00"
@O_RDONLY = global i32 0
@.str.11 = [30 x i8] c"gencat: Unable to create %s.\0A\00"
@.str.12 = [32 x i8] c"gencat: Unable to truncate %s.\0A\00"
@.str.13 = [27 x i8] c"gencat: Unable to read %s\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 i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %10
store i8* null, i8** %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 1, i32* %8
br label %15
15: ; preds = %223, %2
%16 = load i32, i32* %8
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %226
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 45
br i1 %28, label %29, label %138
29: ; preds = %19
%30 = load i8**, i8*** %5
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %78
37: ; preds = %29
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
%40 = load i8**, i8*** %5
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %37
store i32 0, i32* %12
br label %77
48: ; preds = %37
%49 = load i8**, i8*** %5
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %48
store i32 1, i32* %12
br label %76
57: ; preds = %48
%58 = load i8**, i8*** %5
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
%62 = load i8*, i8** %61
%63 = call i64 @strcmp(i8* %62, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %57
store i32 2, i32* %12
br label %75
66: ; preds = %57
%67 = load i32, i32* @stderr
%68 = load i8**, i8*** %5
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %72)
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %65
br label %76
76: ; preds = %75, %56
br label %77
77: ; preds = %76, %47
br label %137
78: ; preds = %29
%79 = load i8**, i8*** %5
%80 = load i32, i32* %8
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8*, i8** %79, i64 %81
%83 = load i8*, i8** %82
%84 = call i64 @strncmp(i8* %83, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%85 = icmp eq i64 %84, 0
br i1 %85, label %86, label %104
86: ; preds = %78
%87 = load i8*, i8** %11
%88 = icmp ne i8* %87, null
br i1 %88, label %93, label %89
89: ; preds = %86
%90 = load i32, i32* @stderr
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0))
%92 = call i32 @exit(i32 1)
unreachable
93: ; preds = %86
%94 = load i32, i32* %8
%95 = add nsw i32 %94, 1
store i32 %95, i32* %8
%96 = load i8**, i8*** %5
%97 = load i32, i32* %8
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8*, i8** %96, i64 %98
%100 = load i8*, i8** %99
%101 = load i32, i32* %12
%102 = load i32, i32* %14
%103 = call i32 @writeIfChanged(i8* %100, i32 %101, i32 %102)
br label %136
104: ; preds = %78
%105 = load i8**, i8*** %5
%106 = load i32, i32* %8
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i8*, i8** %105, i64 %107
%109 = load i8*, i8** %108
%110 = call i64 @strncmp(i8* %109, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 4)
%111 = icmp eq i64 %110, 0
br i1 %111, label %112, label %120
112: ; preds = %104
%113 = load i8*, i8** %10
%114 = icmp ne i8* %113, null
br i1 %114, label %115, label %119
115: ; preds = %112
%116 = load i32, i32* @stderr
%117 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.8, i64 0, i64 0))
%118 = call i32 @exit(i32 1)
unreachable
119: ; preds = %112
store i32 -1, i32* %13
br label %135
120: ; preds = %104
%121 = load i8**, i8*** %5
%122 = load i32, i32* %8
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds i8*, i8** %121, i64 %123
%125 = load i8*, i8** %124
%126 = call i64 @strncmp(i8* %125, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
%127 = icmp eq i64 %126, 0
br i1 %127, label %128, label %131
128: ; preds = %120
%129 = load i32, i32* %14
%130 = xor i32 %129, -1
store i32 %130, i32* %14
br label %134
131: ; preds = %120
%132 = call i32 (...) @usage()
%133 = call i32 @exit(i32 1)
unreachable
134: ; preds = %128
br label %135
135: ; preds = %134, %119
br label %136
136: ; preds = %135, %93
br label %137
137: ; preds = %136, %77
br label %222
138: ; preds = %19
%139 = load i8*, i8** %10
%140 = icmp ne i8* %139, null
br i1 %140, label %201, label %141
141: ; preds = %138
%142 = load i8**, i8*** %5
%143 = load i32, i32* %8
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds i8*, i8** %142, i64 %144
%146 = load i8*, i8** %145
store i8* %146, i8** %10
%147 = load i32, i32* %13
%148 = icmp ne i32 %147, 0
br i1 %148, label %149, label %164
149: ; preds = %141
%150 = load i8*, i8** %10
%151 = load i32, i32* @O_WRONLY
%152 = load i32, i32* @O_TRUNC
%153 = or i32 %151, %152
%154 = load i32, i32* @O_CREAT
%155 = or i32 %153, %154
%156 = call i32 (i8*, i32, ...) @open(i8* %150, i32 %155, i32 438)
store i32 %156, i32* %6
%157 = icmp slt i32 %156, 0
br i1 %157, label %158, label %163
158: ; preds = %149
%159 = load i32, i32* @stderr
%160 = load i8*, i8** %10
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %159, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %160)
%162 = call i32 @exit(i32 1)
unreachable
163: ; preds = %149
br label %200
164: ; preds = %141
%165 = load i8*, i8** %10
%166 = load i32, i32* @O_RDONLY
%167 = call i32 (i8*, i32, ...) @open(i8* %165, i32 %166)
store i32 %167, i32* %6
%168 = icmp slt i32 %167, 0
br i1 %168, label %169, label %182
169: ; preds = %164
%170 = load i8*, i8** %10
%171 = load i32, i32* @O_WRONLY
%172 = load i32, i32* @O_CREAT
%173 = or i32 %171, %172
%174 = call i32 (i8*, i32, ...) @open(i8* %170, i32 %173, i32 438)
store i32 %174, i32* %6
%175 = icmp slt i32 %174, 0
br i1 %175, label %176, label %181
176: ; preds = %169
%177 = load i32, i32* @stderr
%178 = load i8*, i8** %10
%179 = call i32 (i32, i8*, ...) @fprintf(i32 %177, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i8* %178)
%180 = call i32 @exit(i32 1)
unreachable
181: ; preds = %169
br label %199
182: ; preds = %164
%183 = load i32, i32* %6
%184 = call i32 @MCReadCat(i32 %183)
%185 = load i32, i32* %6
%186 = call i32 @close(i32 %185)
%187 = load i8*, i8** %10
%188 = load i32, i32* @O_WRONLY
%189 = load i32, i32* @O_TRUNC
%190 = or i32 %188, %189
%191 = call i32 (i8*, i32, ...) @open(i8* %187, i32 %190)
store i32 %191, i32* %6
%192 = icmp slt i32 %191, 0
br i1 %192, label %193, label %198
193: ; preds = %182
%194 = load i32, i32* @stderr
%195 = load i8*, i8** %10
%196 = call i32 (i32, i8*, ...) @fprintf(i32 %194, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %195)
%197 = call i32 @exit(i32 1)
unreachable
198: ; preds = %182
br label %199
199: ; preds = %198, %181
br label %200
200: ; preds = %199, %163
br label %221
201: ; preds = %138
%202 = load i8**, i8*** %5
%203 = load i32, i32* %8
%204 = sext i32 %203 to i64
%205 = getelementptr inbounds i8*, i8** %202, i64 %204
%206 = load i8*, i8** %205
store i8* %206, i8** %11
%207 = load i8*, i8** %11
%208 = load i32, i32* @O_RDONLY
%209 = call i32 (i8*, i32, ...) @open(i8* %207, i32 %208)
store i32 %209, i32* %7
%210 = icmp slt i32 %209, 0
br i1 %210, label %211, label %216
211: ; preds = %201
%212 = load i32, i32* @stderr
%213 = load i8*, i8** %11
%214 = call i32 (i32, i8*, ...) @fprintf(i32 %212, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i8* %213)
%215 = call i32 @exit(i32 1)
unreachable
216: ; preds = %201
%217 = load i32, i32* %7
%218 = call i32 @MCParse(i32 %217)
%219 = load i32, i32* %7
%220 = call i32 @close(i32 %219)
br label %221
221: ; preds = %216, %200
br label %222
222: ; preds = %221, %137
br label %223
223: ; preds = %222
%224 = load i32, i32* %8
%225 = add nsw i32 %224, 1
store i32 %225, i32* %8
br label %15
226: ; preds = %15
%227 = load i8*, i8** %10
%228 = icmp ne i8* %227, null
br i1 %228, label %229, label %233
229: ; preds = %226
%230 = load i32, i32* %6
%231 = call i32 @MCWriteCat(i32 %230)
%232 = call i32 @exit(i32 0)
unreachable
233: ; preds = %226
%234 = call i32 (...) @usage()
%235 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"-lang\00"
@.str.1 = [2 x i8] c"C\00"
@.str.2 = [4 x i8] c"C++\00"
@.str.3 = [6 x i8] c"ANSIC\00"
@stderr = global i32 0
@.str.4 = [35 x i8] c"gencat: Unrecognized language: %s\0A\00"
@.str.5 = [3 x i8] c"-h\00"
@.str.6 = [59 x i8] c"gencat: Can't write to a header before reading something.\0A\00"
@.str.7 = [5 x i8] c"-new\00"
@.str.8 = [60 x i8] c"gencat: You must specify -new before the catalog file name\0A\00"
@.str.9 = [4 x i8] c"-or\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.10 = [36 x i8] c"gencat: Unable to create a new %s.\0A\00"
@O_RDONLY = global i32 0
@.str.11 = [30 x i8] c"gencat: Unable to create %s.\0A\00"
@.str.12 = [32 x i8] c"gencat: Unable to truncate %s.\0A\00"
@.str.13 = [27 x i8] c"gencat: Unable to read %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %143
4: ; preds = %2, %128
%5 = phi i32 [ %135, %128 ], [ 0, %2 ]
%6 = phi i32 [ %134, %128 ], [ 0, %2 ]
%7 = phi i32 [ %133, %128 ], [ 0, %2 ]
%8 = phi i8* [ %132, %128 ], [ null, %2 ]
%9 = phi i8* [ %131, %128 ], [ null, %2 ]
%10 = phi i32 [ %130, %128 ], [ undef, %2 ]
%11 = phi i32 [ %136, %128 ], [ 1, %2 ]
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 45
br i1 %16, label %17, label %75
17: ; preds = %4
%18 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %40
20: ; preds = %17
%21 = add nsw i32 %11, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = tail call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %128, label %27
27: ; preds = %20
%28 = load i8*, i8** %23
%29 = tail call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %128, label %31
31: ; preds = %27
%32 = load i8*, i8** %23
%33 = tail call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %128, label %35
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %23
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %17
%41 = load i8*, i8** %13
%42 = tail call i64 @strncmp(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %56
44: ; preds = %40
%45 = icmp eq i8* %8, null
br i1 %45, label %46, label %50
46: ; preds = %44
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0))
%49 = tail call i32 @exit(i32 1)
unreachable
50: ; preds = %44
%51 = add nsw i32 %11, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %1, i64 %52
%54 = load i8*, i8** %53
%55 = tail call i32 @writeIfChanged(i8* %54, i32 %7, i32 %5)
br label %128
56: ; preds = %40
%57 = load i8*, i8** %13
%58 = tail call i64 @strncmp(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 4)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %56
%61 = icmp eq i8* %9, null
br i1 %61, label %128, label %62
62: ; preds = %60
%63 = load i32, i32* @stderr
%64 = tail call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.8, i64 0, i64 0))
%65 = tail call i32 @exit(i32 1)
unreachable
66: ; preds = %56
%67 = load i8*, i8** %13
%68 = tail call i64 @strncmp(i8* %67, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = xor i32 %5, -1
br label %128
72: ; preds = %66
%73 = tail call i32 (...) @usage()
%74 = tail call i32 @exit(i32 1)
unreachable
75: ; preds = %4
%76 = icmp eq i8* %9, null
br i1 %76, label %77, label %117
77: ; preds = %75
%78 = icmp eq i32 %6, 0
br i1 %78, label %91, label %79
79: ; preds = %77
%80 = load i32, i32* @O_WRONLY
%81 = load i32, i32* @O_TRUNC
%82 = or i32 %81, %80
%83 = load i32, i32* @O_CREAT
%84 = or i32 %82, %83
%85 = tail call i32 (i8*, i32, ...) @open(i8* %14, i32 %84, i32 438)
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %128
87: ; preds = %79
%88 = load i32, i32* @stderr
%89 = tail call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %14)
%90 = tail call i32 @exit(i32 1)
unreachable
91: ; preds = %77
%92 = load i32, i32* @O_RDONLY
%93 = tail call i32 (i8*, i32, ...) @open(i8* %14, i32 %92)
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %105
95: ; preds = %91
%96 = load i32, i32* @O_WRONLY
%97 = load i32, i32* @O_CREAT
%98 = or i32 %97, %96
%99 = tail call i32 (i8*, i32, ...) @open(i8* %14, i32 %98, i32 438)
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %128
101: ; preds = %95
%102 = load i32, i32* @stderr
%103 = tail call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i8* %14)
%104 = tail call i32 @exit(i32 1)
unreachable
105: ; preds = %91
%106 = tail call i32 @MCReadCat(i32 %93)
%107 = tail call i32 @close(i32 %93)
%108 = load i32, i32* @O_WRONLY
%109 = load i32, i32* @O_TRUNC
%110 = or i32 %109, %108
%111 = tail call i32 (i8*, i32, ...) @open(i8* %14, i32 %110)
%112 = icmp slt i32 %111, 0
br i1 %112, label %113, label %128
113: ; preds = %105
%114 = load i32, i32* @stderr
%115 = tail call i32 (i32, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %14)
%116 = tail call i32 @exit(i32 1)
unreachable
117: ; preds = %75
%118 = load i32, i32* @O_RDONLY
%119 = tail call i32 (i8*, i32, ...) @open(i8* %14, i32 %118)
%120 = icmp slt i32 %119, 0
br i1 %120, label %121, label %125
121: ; preds = %117
%122 = load i32, i32* @stderr
%123 = tail call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i8* %14)
%124 = tail call i32 @exit(i32 1)
unreachable
125: ; preds = %117
%126 = tail call i32 @MCParse(i32 %119)
%127 = tail call i32 @close(i32 %119)
br label %128
128: ; preds = %60, %31, %27, %20, %50, %70, %79, %105, %95, %125
%129 = phi i32 [ %51, %50 ], [ %11, %70 ], [ %11, %125 ], [ %11, %79 ], [ %11, %95 ], [ %11, %105 ], [ %21, %20 ], [ %21, %27 ], [ %21, %31 ], [ %11, %60 ]
%130 = phi i32 [ %10, %50 ], [ %10, %70 ], [ %10, %125 ], [ %85, %79 ], [ %99, %95 ], [ %111, %105 ], [ %10, %20 ], [ %10, %27 ], [ %10, %31 ], [ %10, %60 ]
%131 = phi i8* [ %9, %50 ], [ %9, %70 ], [ %9, %125 ], [ %14, %79 ], [ %14, %95 ], [ %14, %105 ], [ %9, %20 ], [ %9, %27 ], [ %9, %31 ], [ null, %60 ]
%132 = phi i8* [ %8, %50 ], [ %8, %70 ], [ %14, %125 ], [ %8, %79 ], [ %8, %95 ], [ %8, %105 ], [ %8, %20 ], [ %8, %27 ], [ %8, %31 ], [ %8, %60 ]
%133 = phi i32 [ %7, %50 ], [ %7, %70 ], [ %7, %125 ], [ %7, %79 ], [ %7, %95 ], [ %7, %105 ], [ 0, %20 ], [ 1, %27 ], [ 2, %31 ], [ %7, %60 ]
%134 = phi i32 [ %6, %50 ], [ %6, %70 ], [ %6, %125 ], [ -1, %79 ], [ 0, %95 ], [ 0, %105 ], [ %6, %20 ], [ %6, %27 ], [ %6, %31 ], [ -1, %60 ]
%135 = phi i32 [ %5, %50 ], [ %71, %70 ], [ %5, %125 ], [ %5, %79 ], [ %5, %95 ], [ %5, %105 ], [ %5, %20 ], [ %5, %27 ], [ %5, %31 ], [ %5, %60 ]
%136 = add nsw i32 %129, 1
%137 = icmp slt i32 %136, %0
br i1 %137, label %4, label %138
138: ; preds = %128
%139 = icmp eq i8* %131, null
br i1 %139, label %143, label %140
140: ; preds = %138
%141 = tail call i32 @MCWriteCat(i32 %130)
%142 = tail call i32 @exit(i32 0)
unreachable
143: ; preds = %2, %138
%144 = tail call i32 (...) @usage()
%145 = tail call i32 @exit(i32 1)
unreachable
}