#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 pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ define_extension(char *, char *);
scalar_t__ execlp(char const *, char const *, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char *get_extension_command(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_configuration();
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strrchr(char *, char);
char *strtok(char *, char *);
int wait(int *);
int main(int argc, char *argv[]) {
  char *exten;
  char *command;
  char *line = NULL;
  size_t len = 0;
  pid_t pid;
  FILE *config;
  size_t i;
  size_t children_launched = 0;
  if (argc < 2) {
    fputs("Usage: anyopen <filename>\n", stderr);
    fputs("       anyopen --print-config\n", stderr);
    return 1;
  }
  config = fopen("extensions.conf", "r");
  if (config == NULL) {
    perror("fopen");
    fputs("Unable to open config file 'extensions.conf'\n", stderr);
    return 1;
  }
  i = 0;
  while (getline(&line, &len, config) != -1) {
    i++;
    if ((line[0] == '\n') || (line[0] == '#')) {
      continue;
    }
    exten = strtok(line, " ");
    if (exten == NULL) {
      fprintf(stderr, "WARNING: Config syntax error on line %d\n", i);
      continue;
    }
    command = strtok(NULL, "\n");
    if (command == NULL) {
      fprintf(stderr, "WARNING: Config syntax error on line %d\n", i);
      continue;
    }
    define_extension(exten, command);
  }
  fclose(config);
  if ((argc >= 2) && (strcmp("--print-config", argv[1]) == 0)) {
    print_configuration();
    return 0;
  }
  for (i = 1; i < argc; i++) {
    const char *command;
    exten = strrchr(argv[i], '.');
    if (!exten) {
      fputs("Unable to determine file extension. Skipping.\n", stderr);
      continue;
    }
    exten += 1;
    command = get_extension_command(exten);
    pid = fork();
    if (pid == 0) {
      if (command == NULL) {
        fputs("Unrecognized extension. Skipping.\n", stderr);
        continue;
      }
      if (execlp(command, command, argv[i], (char *)NULL) < 0) {
        perror("exec");
        continue;
      }
    } else {
      children_launched++;
      fprintf(stderr, "Launched command '%s' for file '%s' with pid %d\n",
              command, argv[i], pid);
    }
  }
  fprintf(stderr, "Waiting for children to return...\n");
  i = 0;
  while (i < children_launched) {
    int status;
    if ((pid = wait(&status)) > 0) {
      if (WIFEXITED(status)) {
        fprintf(stderr, "Child with pid %d exited with status %d\n", pid,
                WEXITSTATUS(status));
      }
      if (WIFSIGNALED(status)) {
        fprintf(stderr, "Child with pid %d terminated by signal %d\n", pid,
                WTERMSIG(status));
      }
      i++;
    } else {
      fputs("wait() return -1. Interesting...\n", stderr);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x50(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    129e <main+0x6e>
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
lea    0xd88(%rip),%rdi
call   1060 <fputs@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
lea    0xd8e(%rip),%rdi
call   1060 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    1639 <main+0x409>
lea    0xd95(%rip),%rdi
lea    0xd9e(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12ed <main+0xbd>
lea    0xd85(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
lea    0xd76(%rip),%rdi
call   1060 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    1639 <main+0x409>
movq   $0x0,-0x48(%rbp)
mov    -0x40(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1110 <getline@plt>
cmp    $0xffffffff,%eax
je     13d0 <main+0x1a0>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     133b <main+0x10b>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1340 <main+0x110>
jmp    12f5 <main+0xc5>
mov    -0x28(%rbp),%rdi
lea    0xd35(%rip),%rsi
call   10f0 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    137f <main+0x14f>
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
lea    0xd0f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    12f5 <main+0xc5>
xor    %eax,%eax
mov    %eax,%edi
lea    0xcf4(%rip),%rsi
call   10f0 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    13be <main+0x18e>
mov    0x2c3b(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
lea    0xcd0(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    12f5 <main+0xc5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1100 <define_extension@plt>
jmp    12f5 <main+0xc5>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x2,-0x8(%rbp)
jl     1414 <main+0x1e4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xcb9(%rip),%rdi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1414 <main+0x1e4>
mov    $0x0,%al
call   10b0 <print_configuration@plt>
movl   $0x0,-0x4(%rbp)
jmp    1639 <main+0x409>
movq   $0x1,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
jae    1548 <main+0x318>
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    146c <main+0x23c>
mov    0x2b87(%rip),%rax
mov    (%rax),%esi
lea    0xc58(%rip),%rdi
call   1060 <fputs@plt>
jmp    1537 <main+0x307>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <get_extension_command@plt>
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1150 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    14fb <main+0x2cb>
cmpq   $0x0,-0x58(%rbp)
jne    14be <main+0x28e>
mov    0x2b35(%rip),%rax
mov    (%rax),%esi
lea    0xc35(%rip),%rdi
call   1060 <fputs@plt>
jmp    1537 <main+0x307>
mov    -0x58(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1130 <execlp@plt>
cmp    $0x0,%rax
jge    14f6 <main+0x2c6>
lea    0xc20(%rip),%rdi
call   10e0 <perror@plt>
jmp    1537 <main+0x307>
jmp    1532 <main+0x302>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    0x2ad2(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x34(%rbp),%r8d
lea    0xbe6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1537 <main+0x307>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    141c <main+0x1ec>
mov    0x2a91(%rip),%rax
mov    (%rax),%edi
lea    0xbea(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x50(%rbp),%rax
jae    1639 <main+0x409>
lea    -0x5c(%rbp),%rdi
call   1140 <wait@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jle    161f <main+0x3ef>
mov    -0x5c(%rbp),%edi
call   1120 <WIFEXITED@plt>
cmp    $0x0,%rax
je     15cc <main+0x39c>
mov    0x2a3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x5c(%rbp),%edi
call   10c0 <WEXITSTATUS@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%edx
mov    %eax,%ecx
lea    0xba0(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x5c(%rbp),%edi
call   1070 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     160e <main+0x3de>
mov    0x29fb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x5c(%rbp),%edi
call   10a0 <WTERMSIG@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%edx
mov    %eax,%ecx
lea    0xb87(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1634 <main+0x404>
mov    0x29ba(%rip),%rax
mov    (%rax),%esi
lea    0xb8a(%rip),%rdi
call   1060 <fputs@plt>
jmp    1567 <main+0x337>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
cmp    $0x1,%edi
jg     1282 <main+0x52>
mov    0x2d84(%rip),%rbx
mov    (%rbx),%esi
lea    0xd9b(%rip),%rdi
call   1060 <fputs@plt>
mov    (%rbx),%esi
lea    0xda8(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x1,%ebx
jmp    1539 <main+0x309>
mov    %rsi,%r13
mov    %edi,%ebx
lea    0xdac(%rip),%rdi
lea    0xdb5(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     154a <main+0x31a>
mov    %rax,%rbp
mov    %ebx,0x1c(%rsp)
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    %rax,%rdx
call   1110 <getline@plt>
cmp    $0xffffffff,%eax
je     1355 <main+0x125>
mov    $0x1,%ebx
lea    0x10(%rsp),%r15
lea    0x20(%rsp),%r12
jmp    1311 <main+0xe1>
cs nopw 0x0(%rax,%rax,1)
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1110 <getline@plt>
add    $0x1,%rbx
cmp    $0xffffffff,%eax
je     1355 <main+0x125>
mov    0x10(%rsp),%rdi
movzbl (%rdi),%eax
cmp    $0x23,%al
je     12fa <main+0xca>
cmp    $0xa,%al
je     12fa <main+0xca>
lea    0xd58(%rip),%rsi
call   10f0 <strtok@plt>
test   %rax,%rax
je     12e0 <main+0xb0>
mov    %rax,%r14
xor    %edi,%edi
lea    0xd40(%rip),%rsi
call   10f0 <strtok@plt>
test   %rax,%rax
je     12e0 <main+0xb0>
mov    %r14,%rdi
mov    %rax,%rsi
call   1100 <define_extension@plt>
jmp    12fa <main+0xca>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    0x8(%r13),%rsi
lea    0xd43(%rip),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1450 <main+0x220>
mov    0x1c(%rsp),%eax
cmp    $0x2,%eax
jb     145e <main+0x22e>
movslq %eax,%r12
mov    $0x1,%ebp
mov    0x2c4e(%rip),%r15
xor    %r14d,%r14d
jmp    13cd <main+0x19d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
mov    (%r15),%edi
mov    0x0(%r13,%rbp,8),%rcx
lea    0xd5e(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%r8d
xor    %eax,%eax
call   1090 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
je     147c <main+0x24c>
mov    0x0(%r13,%rbp,8),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1430 <main+0x200>
add    $0x1,%rax
mov    %rax,%rdi
call   1040 <get_extension_command@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1150 <fork@plt>
test   %eax,%eax
jne    13a0 <main+0x170>
test   %rbx,%rbx
je     1444 <main+0x214>
mov    0x0(%r13,%rbp,8),%rdx
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1130 <execlp@plt>
test   %rax,%rax
jns    13c0 <main+0x190>
lea    0xcee(%rip),%rdi
call   10e0 <perror@plt>
jmp    13c0 <main+0x190>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%esi
lea    0xc80(%rip),%rdi
call   1060 <fputs@plt>
jmp    13c0 <main+0x190>
mov    (%r15),%esi
lea    0xc9b(%rip),%rdi
jmp    143a <main+0x20a>
xor    %ebx,%ebx
xor    %eax,%eax
call   10b0 <print_configuration@plt>
jmp    1539 <main+0x309>
mov    0x2b7b(%rip),%rax
mov    (%rax),%edi
lea    0xcd4(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1539 <main+0x309>
mov    (%r15),%edi
lea    0xcbc(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <fprintf@plt>
test   %r14,%r14
je     1539 <main+0x309>
lea    0xc(%rsp),%r13
xor    %r12d,%r12d
jmp    14c4 <main+0x294>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%esi
lea    0xcff(%rip),%rdi
call   1060 <fputs@plt>
cmp    %r14,%r12
jae    1537 <main+0x307>
mov    %r13,%rdi
call   1140 <wait@plt>
test   %eax,%eax
jle    14b0 <main+0x280>
mov    %eax,%ebp
mov    0xc(%rsp),%edi
call   1120 <WIFEXITED@plt>
test   %rax,%rax
je     1500 <main+0x2d0>
mov    (%r15),%ebx
mov    0xc(%rsp),%edi
call   10c0 <WEXITSTATUS@plt>
mov    %ebx,%edi
lea    0xc70(%rip),%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0xc(%rsp),%edi
call   1070 <WIFSIGNALED@plt>
test   %rax,%rax
je     152e <main+0x2fe>
mov    (%r15),%ebx
mov    0xc(%rsp),%edi
call   10a0 <WTERMSIG@plt>
mov    %ebx,%edi
lea    0xc6b(%rip),%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
add    $0x1,%r12
cmp    %r14,%r12
jb     14c4 <main+0x294>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xafb(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2a83(%rip),%rax
mov    (%rax),%esi
lea    0xaec(%rip),%rdi
jmp    1273 <main+0x43>

LLVM IR (-O0):
@.str = [27 x i8] c"Usage: anyopen <filename>\0A\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c" anyopen --print-config\0A\00"
@.str.2 = [16 x i8] c"extensions.conf\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [6 x i8] c"fopen\00"
@.str.5 = [46 x i8] c"Unable to open config file 'extensions.conf'\0A\00"
@.str.6 = [2 x i8] c" \00"
@.str.7 = [41 x i8] c"WARNING: Config syntax error on line %d\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [15 x i8] c"--print-config\00"
@.str.10 = [47 x i8] c"Unable to determine file extension. Skipping.\0A\00"
@.str.11 = [35 x i8] c"Unrecognized extension. Skipping.\0A\00"
@.str.12 = [5 x i8] c"exec\00"
@.str.13 = [49 x i8] c"Launched command '%s' for file '%s' with pid %d\0A\00"
@.str.14 = [35 x i8] c"Waiting for children to return...\0A\00"
@.str.15 = [41 x i8] c"Child with pid %d exited with status %d\0A\00"
@.str.16 = [43 x i8] c"Child with pid %d terminated by signal %d\0A\00"
@.str.17 = [34 x i8] c"wait() return -1. Interesting...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
store i64 0, i64* %9
store i64 0, i64* %13
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @stderr
%22 = call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i32 1, i32* %3
br label %180
23: ; preds = %2
%24 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %24, i32** %11
%25 = load i32*, i32** %11
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%29 = load i32, i32* @stderr
%30 = call i32 @fputs(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i32 %29)
store i32 1, i32* %3
br label %180
31: ; preds = %23
store i64 0, i64* %12
br label %32
32: ; preds = %68, %64, %56, %50, %31
%33 = load i32*, i32** %11
%34 = call i32 @getline(i8** %8, i64* %9, i32* %33)
%35 = icmp ne i32 %34, -1
br i1 %35, label %36, label %72
36: ; preds = %32
%37 = load i64, i64* %12
%38 = add i64 %37, 1
store i64 %38, i64* %12
%39 = load i8*, i8** %8
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 10
br i1 %43, label %50, label %44
44: ; preds = %36
%45 = load i8*, i8** %8
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 35
br i1 %49, label %50, label %51
50: ; preds = %44, %36
br label %32
51: ; preds = %44
%52 = load i8*, i8** %8
%53 = call i8* @strtok(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %53, i8** %6
%54 = load i8*, i8** %6
%55 = icmp eq i8* %54, null
br i1 %55, label %56, label %60
56: ; preds = %51
%57 = load i32, i32* @stderr
%58 = load i64, i64* %12
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i64 %58)
br label %32
60: ; preds = %51
%61 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i8* %61, i8** %7
%62 = load i8*, i8** %7
%63 = icmp eq i8* %62, null
br i1 %63, label %64, label %68
64: ; preds = %60
%65 = load i32, i32* @stderr
%66 = load i64, i64* %12
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i64 %66)
br label %32
68: ; preds = %60
%69 = load i8*, i8** %6
%70 = load i8*, i8** %7
%71 = call i32 @define_extension(i8* %69, i8* %70)
br label %32
72: ; preds = %32
%73 = load i32*, i32** %11
%74 = call i32 @fclose(i32* %73)
%75 = load i32, i32* %4
%76 = icmp sge i32 %75, 2
br i1 %76, label %77, label %85
77: ; preds = %72
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 1
%80 = load i8*, i8** %79
%81 = call i64 @strcmp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %80)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %77
%84 = call i32 (...) @print_configuration()
store i32 0, i32* %3
br label %180
85: ; preds = %77, %72
store i64 1, i64* %12
br label %86
86: ; preds = %140, %85
%87 = load i64, i64* %12
%88 = load i32, i32* %4
%89 = sext i32 %88 to i64
%90 = icmp ult i64 %87, %89
br i1 %90, label %91, label %143
91: ; preds = %86
%92 = load i8**, i8*** %5
%93 = load i64, i64* %12
%94 = getelementptr inbounds i8*, i8** %92, i64 %93
%95 = load i8*, i8** %94
%96 = call i8* @strrchr(i8* %95, i8 signext 46)
store i8* %96, i8** %6
%97 = load i8*, i8** %6
%98 = icmp ne i8* %97, null
br i1 %98, label %102, label %99
99: ; preds = %91
%100 = load i32, i32* @stderr
%101 = call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0), i32 %100)
br label %140
102: ; preds = %91
%103 = load i8*, i8** %6
%104 = getelementptr inbounds i8, i8* %103, i64 1
store i8* %104, i8** %6
%105 = load i8*, i8** %6
%106 = call i8* @get_extension_command(i8* %105)
store i8* %106, i8** %14
%107 = call i32 (...) @fork()
store i32 %107, i32* %10
%108 = load i32, i32* %10
%109 = icmp eq i32 %108, 0
br i1 %109, label %110, label %128
110: ; preds = %102
%111 = load i8*, i8** %14
%112 = icmp eq i8* %111, null
br i1 %112, label %113, label %116
113: ; preds = %110
%114 = load i32, i32* @stderr
%115 = call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i32 %114)
br label %140
116: ; preds = %110
%117 = load i8*, i8** %14
%118 = load i8*, i8** %14
%119 = load i8**, i8*** %5
%120 = load i64, i64* %12
%121 = getelementptr inbounds i8*, i8** %119, i64 %120
%122 = load i8*, i8** %121
%123 = call i64 @execlp(i8* %117, i8* %118, i8* %122, i8* null)
%124 = icmp slt i64 %123, 0
br i1 %124, label %125, label %127
125: ; preds = %116
%126 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %140
127: ; preds = %116
br label %139
128: ; preds = %102
%129 = load i64, i64* %13
%130 = add i64 %129, 1
store i64 %130, i64* %13
%131 = load i32, i32* @stderr
%132 = load i8*, i8** %14
%133 = load i8**, i8*** %5
%134 = load i64, i64* %12
%135 = getelementptr inbounds i8*, i8** %133, i64 %134
%136 = load i8*, i8** %135
%137 = load i32, i32* %10
%138 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.13, i64 0, i64 0), i8* %132, i8* %136, i32 %137)
br label %139
139: ; preds = %128, %127
br label %140
140: ; preds = %139, %125, %113, %99
%141 = load i64, i64* %12
%142 = add i64 %141, 1
store i64 %142, i64* %12
br label %86
143: ; preds = %86
%144 = load i32, i32* @stderr
%145 = call i32 (i32, i8*, ...) @fprintf(i32 %144, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0))
store i64 0, i64* %12
br label %146
146: ; preds = %179, %143
%147 = load i64, i64* %12
%148 = load i64, i64* %13
%149 = icmp ult i64 %147, %148
br i1 %149, label %150, label %180
150: ; preds = %146
%151 = call i32 @wait(i32* %15)
store i32 %151, i32* %10
%152 = icmp sgt i32 %151, 0
br i1 %152, label %153, label %176
153: ; preds = %150
%154 = load i32, i32* %15
%155 = call i64 @WIFEXITED(i32 %154)
%156 = icmp ne i64 %155, 0
br i1 %156, label %157, label %163
157: ; preds = %153
%158 = load i32, i32* @stderr
%159 = load i32, i32* %10
%160 = load i32, i32* %15
%161 = call i32 @WEXITSTATUS(i32 %160)
%162 = call i32 (i32, i8*, ...) @fprintf(i32 %158, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.15, i64 0, i64 0), i32 %159, i32 %161)
br label %163
163: ; preds = %157, %153
%164 = load i32, i32* %15
%165 = call i64 @WIFSIGNALED(i32 %164)
%166 = icmp ne i64 %165, 0
br i1 %166, label %167, label %173
167: ; preds = %163
%168 = load i32, i32* @stderr
%169 = load i32, i32* %10
%170 = load i32, i32* %15
%171 = call i32 @WTERMSIG(i32 %170)
%172 = call i32 (i32, i8*, ...) @fprintf(i32 %168, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.16, i64 0, i64 0), i32 %169, i32 %171)
br label %173
173: ; preds = %167, %163
%174 = load i64, i64* %12
%175 = add i64 %174, 1
store i64 %175, i64* %12
br label %179
176: ; preds = %150
%177 = load i32, i32* @stderr
%178 = call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.17, i64 0, i64 0), i32 %177)
br label %179
179: ; preds = %176, %173
br label %146
180: ; preds = %18, %27, %83, %146
%181 = load i32, i32* %3
ret i32 %181
}

LLVM IR (-O2):
@.str = [27 x i8] c"Usage: anyopen <filename>\0A\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c" anyopen --print-config\0A\00"
@.str.2 = [16 x i8] c"extensions.conf\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [6 x i8] c"fopen\00"
@.str.5 = [46 x i8] c"Unable to open config file 'extensions.conf'\0A\00"
@.str.6 = [2 x i8] c" \00"
@.str.7 = [41 x i8] c"WARNING: Config syntax error on line %d\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [15 x i8] c"--print-config\00"
@.str.10 = [47 x i8] c"Unable to determine file extension. Skipping.\0A\00"
@.str.11 = [35 x i8] c"Unrecognized extension. Skipping.\0A\00"
@.str.12 = [5 x i8] c"exec\00"
@.str.13 = [49 x i8] c"Launched command '%s' for file '%s' with pid %d\0A\00"
@.str.14 = [35 x i8] c"Waiting for children to return...\0A\00"
@.str.15 = [41 x i8] c"Child with pid %d exited with status %d\0A\00"
@.str.16 = [43 x i8] c"Child with pid %d terminated by signal %d\0A\00"
@.str.17 = [34 x i8] c"wait() return -1. Interesting...\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%8 = icmp slt i32 %0, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fputs(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @stderr
%13 = tail call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %131
14: ; preds = %2
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = call i32 @getline(i8** %3, i64* %4, i32* %15)
%19 = icmp eq i32 %18, -1
br i1 %19, label %46, label %24
20: ; preds = %14
%21 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%22 = load i32, i32* @stderr
%23 = tail call i32 @fputs(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i32 %22)
br label %131
24: ; preds = %17, %29
%25 = phi i64 [ %26, %29 ], [ 0, %17 ]
%26 = add i64 %25, 1
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
switch i8 %28, label %32 [
i8 10, label %29
i8 35, label %29
]
29: ; preds = %24, %24, %35, %41, %44
%30 = call i32 @getline(i8** %3, i64* %4, i32* %15)
%31 = icmp eq i32 %30, -1
br i1 %31, label %46, label %24
32: ; preds = %24
%33 = call i8* @strtok(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i64 %26)
br label %29
38: ; preds = %32
%39 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i64 %26)
br label %29
44: ; preds = %38
%45 = call i32 @define_extension(i8* %33, i8* %39)
br label %29
46: ; preds = %29, %17
%47 = call i32 @fclose(i32* %15)
%48 = getelementptr inbounds i8*, i8** %1, i64 1
%49 = load i8*, i8** %48
%50 = call i64 @strcmp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %58, label %52
52: ; preds = %46
%53 = sext i32 %0 to i64
%54 = icmp ugt i32 %0, 1
br i1 %54, label %60, label %55
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0))
br label %131
58: ; preds = %46
%59 = call i32 (...) @print_configuration()
br label %131
60: ; preds = %52, %91
%61 = phi i64 [ %92, %91 ], [ 0, %52 ]
%62 = phi i64 [ %93, %91 ], [ 1, %52 ]
%63 = getelementptr inbounds i8*, i8** %1, i64 %62
%64 = load i8*, i8** %63
%65 = call i8* @strrchr(i8* dereferenceable(1) %64, i8 signext 46)
%66 = icmp eq i8* %65, null
br i1 %66, label %67, label %70
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0), i32 %68)
br label %91
70: ; preds = %60
%71 = getelementptr inbounds i8, i8* %65, i64 1
%72 = call i8* @get_extension_command(i8* %71)
%73 = call i32 (...) @fork()
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %86
75: ; preds = %70
%76 = icmp eq i8* %72, null
br i1 %76, label %77, label %80
77: ; preds = %75
%78 = load i32, i32* @stderr
%79 = call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i32 %78)
br label %91
80: ; preds = %75
%81 = load i8*, i8** %63
%82 = call i64 @execlp(i8* %72, i8* %72, i8* %81, i8* null)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %91
84: ; preds = %80
%85 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %91
86: ; preds = %70
%87 = add i64 %61, 1
%88 = load i32, i32* @stderr
%89 = load i8*, i8** %63
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.13, i64 0, i64 0), i8* %72, i8* %89, i32 %73)
br label %91
91: ; preds = %86, %80, %84, %77, %67
%92 = phi i64 [ %61, %77 ], [ %61, %84 ], [ %61, %67 ], [ %61, %80 ], [ %87, %86 ]
%93 = add nuw i64 %62, 1
%94 = icmp eq i64 %93, %53
br i1 %94, label %95, label %60
95: ; preds = %91
%96 = load i32, i32* @stderr
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0))
%98 = icmp eq i64 %92, 0
br i1 %98, label %131, label %99
99: ; preds = %95
%100 = bitcast i32* %5 to i8*
br label %101
101: ; preds = %99, %128
%102 = phi i64 [ 0, %99 ], [ %129, %128 ]
%103 = call i32 @wait(i32* %5)
%104 = icmp sgt i32 %103, 0
br i1 %104, label %105, label %125
105: ; preds = %101
%106 = load i32, i32* %5
%107 = call i64 @WIFEXITED(i32 %106)
%108 = icmp eq i64 %107, 0
br i1 %108, label %114, label %109
109: ; preds = %105
%110 = load i32, i32* @stderr
%111 = load i32, i32* %5
%112 = call i32 @WEXITSTATUS(i32 %111)
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.15, i64 0, i64 0), i32 %103, i32 %112)
br label %114
114: ; preds = %109, %105
%115 = load i32, i32* %5
%116 = call i64 @WIFSIGNALED(i32 %115)
%117 = icmp eq i64 %116, 0
br i1 %117, label %123, label %118
118: ; preds = %114
%119 = load i32, i32* @stderr
%120 = load i32, i32* %5
%121 = call i32 @WTERMSIG(i32 %120)
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.16, i64 0, i64 0), i32 %103, i32 %121)
br label %123
123: ; preds = %118, %114
%124 = add nuw i64 %102, 1
br label %128
125: ; preds = %101
%126 = load i32, i32* @stderr
%127 = call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.17, i64 0, i64 0), i32 %126)
br label %128
128: ; preds = %125, %123
%129 = phi i64 [ %124, %123 ], [ %102, %125 ]
%130 = icmp ult i64 %129, %92
br i1 %130, label %101, label %131
131: ; preds = %128, %55, %95, %58, %20, %9
%132 = phi i32 [ 1, %9 ], [ 1, %20 ], [ 0, %58 ], [ 0, %95 ], [ 0, %55 ], [ 0, %128 ]
ret i32 %132
}