#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 */
struct toml_node {
  int dummy;
};
struct stat {
  int st_size;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int MAP_FILE;
int MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ STDIN_FILENO;
char *basename(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fstat(int, struct stat *);
int getopt(int, char **, char *);
void *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int, int,
           int /*<<< orphan*/);
int munmap(void *, int);
int open(char *, int /*<<< orphan*/);
char *optarg;
int read(int /*<<< orphan*/, void *, int const);
void *realloc(void *, int const);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ toml_dump(struct toml_node *, int /*<<< orphan*/);
int /*<<< orphan*/ toml_free(struct toml_node *);
struct toml_node *toml_get(struct toml_node *, char *);
int toml_init(struct toml_node **);
int toml_parse(struct toml_node *, void *, int);
int /*<<< orphan*/ toml_tojson(struct toml_node *, int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *, int, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int fd, ret, toml_content_size = 0;
  struct toml_node *toml_root;
  void *toml_content = NULL;
  struct stat st;
  int ch, dump = 0, json = 0;
  char *file = NULL, *get = NULL;
  int exit_code = EXIT_SUCCESS;
  char *bname;
  bname = basename(argv[0]);
  if (strcmp(bname, "parser_test") == 0) {
    dump = 1;
    json = 1;
  }
  while ((ch = getopt(argc, argv, "t:dg:hj")) != -1) {
    switch (ch) {
    case 't':
      file = optarg;
      break;
    case 'd':
      dump = 1;
      break;
    case 'g':
      get = optarg;
      break;
    case 'h':
      usage(argv[0], 1, NULL);
      break;
    case 'j':
      json = 1;
      break;
    default:
      usage(argv[0], 1, NULL);
      break;
    }
  }
  if (file) {
    fd = open(file, O_RDONLY);
    if (fd == -1) {
      fprintf(stderr, "open: %s\n", strerror(errno));
      exit(1);
    }
    ret = fstat(fd, &st);
    if (ret == -1) {
      fprintf(stderr, "stat: %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
    toml_content =
        mmap(NULL, st.st_size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0);
    if (!toml_content) {
      fprintf(stderr, "mmap: %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
    toml_content_size = st.st_size;
  } else {
    const int size = 1024 * 1024;
    int i, bytes_read;
    for (i = 0; 1; i++) {
      toml_content = realloc(toml_content, size * (i + 1));
      if (!toml_content) {
        fprintf(stderr, "realloc: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
      }
      bytes_read = read(STDIN_FILENO, &toml_content[size * i], size);
      toml_content_size += bytes_read;
      if (bytes_read < size)
        break;
    }
  }
  ret = toml_init(&toml_root);
  if (ret == -1) {
    fprintf(stderr, "toml_init: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  ret = toml_parse(toml_root, toml_content, toml_content_size);
  if (ret) {
    exit_code = EXIT_FAILURE;
    goto bail;
  }
  if (file) {
    ret = munmap(toml_content, toml_content_size);
    if (ret) {
      fprintf(stderr, "munmap: %s\n", strerror(errno));
      exit_code = EXIT_FAILURE;
      goto bail;
    }
    close(fd);
  }
  if (dump) {
    if (json)
      toml_tojson(toml_root, stdout);
    else
      toml_dump(toml_root, stdout);
  } else if (get) {
    struct toml_node *node = toml_get(toml_root, get);
    if (!node) {
      fprintf(stderr, "no node '%s'\n", get);
      exit_code = EXIT_FAILURE;
      goto bail;
    }
    if (json)
      toml_tojson(node, stdout);
    else
      toml_dump(node, stdout);
  }
bail:
  toml_free(toml_root);
  exit(exit_code);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <basename@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
lea    0xd97(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12ca <main+0x8a>
movl   $0x1,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    12cf <main+0x8f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd73(%rip),%rdx
call   1130 <getopt@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
je     138f <main+0x14f>
mov    -0x3c(%rbp),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x88(%rbp)
sub    $0x10,%eax
ja     1375 <main+0x135>
mov    -0x88(%rbp),%rax
lea    0xcec(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2cd4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    138a <main+0x14a>
movl   $0x1,-0x40(%rbp)
jmp    138a <main+0x14a>
mov    0x2cb5(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    138a <main+0x14a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1100 <usage@plt>
jmp    138a <main+0x14a>
movl   $0x1,-0x44(%rbp)
jmp    138a <main+0x14a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1100 <usage@plt>
jmp    12cf <main+0x8f>
cmpq   $0x0,-0x50(%rbp)
je     14d6 <main+0x296>
mov    -0x50(%rbp),%rdi
mov    0x2c33(%rip),%rax
mov    (%rax),%esi
call   1120 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    13f5 <main+0x1b5>
mov    0x2c00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    0x2be9(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
lea    0xc72(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1160 <fstat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    144e <main+0x20e>
mov    0x2bab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x90(%rbp)
mov    0x2b94(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x90(%rbp),%edi
mov    %rax,%rdx
lea    0xc27(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2b69(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    -0x38(%rbp),%esi
mov    0x2b98(%rip),%rax
mov    (%rax),%edx
mov    0x2b6f(%rip),%rax
mov    (%rax),%ecx
mov    0x2b2e(%rip),%rax
or     (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    14cb <main+0x28b>
mov    0x2b2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    0x2b17(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rdx
lea    0xbb4(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2aec(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    15ac <main+0x36c>
movl   $0x100000,-0x6c(%rbp)
movl   $0x0,-0x70(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    14f3 <main+0x2b3>
jmp    15a7 <main+0x367>
mov    -0x30(%rbp),%rdi
mov    -0x70(%rbp),%esi
add    $0x1,%esi
shl    $0x14,%esi
call   10e0 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1554 <main+0x314>
mov    0x2aa5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    0x2a8e(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x98(%rbp),%edi
mov    %rax,%rdx
lea    0xb35(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2a63(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    0x2a35(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rsi
mov    -0x70(%rbp),%eax
shl    $0x14,%eax
cltq
add    %rax,%rsi
mov    $0x100000,%edx
call   1080 <read@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x100000,-0x74(%rbp)
jge    1594 <main+0x354>
jmp    15a7 <main+0x367>
jmp    1599 <main+0x359>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    14e4 <main+0x2a4>
jmp    15ac <main+0x36c>
lea    -0x28(%rbp),%rdi
call   1030 <toml_init@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1602 <main+0x3c2>
mov    0x29f7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    0x29e0(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x9c(%rbp),%edi
mov    %rax,%rdx
lea    0xa94(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x29b5(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10c0 <toml_parse@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1630 <main+0x3f0>
mov    0x298a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    1774 <main+0x534>
cmpq   $0x0,-0x50(%rbp)
je     169f <main+0x45f>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10f0 <munmap@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1697 <main+0x457>
mov    0x2965(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa0(%rbp)
mov    0x294e(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0xa0(%rbp),%edi
mov    %rax,%rdx
lea    0xa11(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2923(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    1774 <main+0x534>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x40(%rbp)
je     16e1 <main+0x4a1>
cmpl   $0x0,-0x44(%rbp)
je     16ca <main+0x48a>
mov    -0x28(%rbp),%rdi
mov    0x28ea(%rip),%rax
mov    (%rax),%esi
call   1060 <toml_tojson@plt>
jmp    16dc <main+0x49c>
mov    -0x28(%rbp),%rdi
mov    0x28d3(%rip),%rax
mov    (%rax),%esi
call   1110 <toml_dump@plt>
jmp    176f <main+0x52f>
cmpq   $0x0,-0x58(%rbp)
je     176a <main+0x52a>
mov    -0x28(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   10d0 <toml_get@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
jne    1732 <main+0x4f2>
mov    0x28b1(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
lea    0x982(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2888(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    1774 <main+0x534>
cmpl   $0x0,-0x44(%rbp)
je     1753 <main+0x513>
mov    -0x80(%rbp),%rdi
mov    0x2861(%rip),%rax
mov    (%rax),%esi
call   1060 <toml_tojson@plt>
jmp    1765 <main+0x525>
mov    -0x80(%rbp),%rdi
mov    0x284a(%rip),%rax
mov    (%rax),%esi
call   1110 <toml_dump@plt>
jmp    176a <main+0x52a>
jmp    176f <main+0x52f>
jmp    1774 <main+0x534>
mov    -0x28(%rbp),%rdi
call   1040 <toml_free@plt>
mov    -0x5c(%rbp),%edi
call   1140 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    (%rsi),%rdi
call   10b0 <basename@plt>
lea    0xdd5(%rip),%rsi
mov    %rax,%rdi
call   1090 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
xor    %r12d,%r12d
lea    0xdc7(%rip),%r13
lea    0xd70(%rip),%r15
mov    0x2d61(%rip),%r14
mov    %ecx,0xc(%rsp)
mov    %ecx,0x8(%rsp)
xor    %eax,%eax
mov    %rax,0x20(%rsp)
jmp    12c4 <main+0x84>
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     1305 <main+0xc5>
mov    (%rbx),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1100 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1130 <getopt@plt>
lea    -0x64(%rax),%ecx
cmp    $0x10,%ecx
ja     12b0 <main+0x70>
movslq (%r15,%rcx,4),%rax
add    %r15,%rax
jmp    *%rax
movl   $0x1,0xc(%rsp)
jmp    12c4 <main+0x84>
movl   $0x1,0x8(%rsp)
jmp    12c4 <main+0x84>
mov    (%r14),%rax
mov    %rax,0x20(%rsp)
jmp    12c4 <main+0x84>
mov    (%r14),%r12
jmp    12c4 <main+0x84>
test   %r12,%r12
jne    1399 <main+0x159>
xor    %ebx,%ebx
mov    0x2c79(%rip),%r15
xor    %ebp,%ebp
xor    %r14d,%r14d
nopl   0x0(%rax)
lea    0x100000(%rbx),%esi
mov    %rbp,%rdi
call   10e0 <realloc@plt>
test   %rax,%rax
je     13e1 <main+0x1a1>
mov    %rax,%rbp
mov    (%r15),%edi
mov    %ebx,%esi
and    $0xfff00000,%esi
add    %rax,%rsi
mov    $0x100000,%edx
call   1080 <read@plt>
add    %eax,%r14d
add    $0x100000,%rbx
cmp    $0xfffff,%eax
jg     1320 <main+0xe0>
lea    0x10(%rsp),%rdi
call   1030 <toml_init@plt>
cmp    $0xffffffff,%eax
jne    143b <main+0x1fb>
mov    0x2c43(%rip),%rax
mov    (%rax),%ebx
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
lea    0xcef(%rip),%rsi
jmp    14ef <main+0x2af>
mov    0x2c38(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1120 <open@plt>
cmp    $0xffffffff,%eax
jne    1404 <main+0x1c4>
mov    0x2c0a(%rip),%rax
mov    (%rax),%ebx
mov    0x2bf9(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
lea    0xc8b(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    0x2bd8(%rip),%rax
mov    (%rax),%ebx
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
lea    0xc77(%rip),%rsi
jmp    14ef <main+0x2af>
mov    %eax,%r13d
lea    0x18(%rsp),%rsi
mov    %eax,%edi
call   1160 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1495 <main+0x255>
mov    0x2ba1(%rip),%rax
mov    (%rax),%ebx
mov    0x2b90(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
lea    0xc2c(%rip),%rsi
jmp    14ef <main+0x2af>
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   10c0 <toml_parse@plt>
test   %eax,%eax
jne    1576 <main+0x336>
test   %r12,%r12
je     1473 <main+0x233>
mov    %rbp,%rdi
mov    %r14d,%esi
call   10f0 <munmap@plt>
test   %eax,%eax
jne    1527 <main+0x2e7>
mov    %r13d,%edi
call   1070 <close@plt>
cmpl   $0x0,0xc(%rsp)
jne    1507 <main+0x2c7>
mov    0x20(%rsp),%rbx
test   %rbx,%rbx
jne    154c <main+0x30c>
mov    0x4(%rsp),%ebx
jmp    157f <main+0x33f>
mov    0x18(%rsp),%r14d
mov    0x2b4f(%rip),%rax
mov    (%rax),%edx
mov    0x2b26(%rip),%rax
mov    0x2ae7(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %r13d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1363 <main+0x123>
mov    0x2ae8(%rip),%rax
mov    (%rax),%ebx
mov    0x2ad7(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
lea    0xb7d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    0x2ab0(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
mov    0x10(%rsp),%rdi
mov    0x2a95(%rip),%rax
mov    (%rax),%esi
cmpl   $0x0,0x8(%rsp)
jne    1590 <main+0x350>
call   1110 <toml_dump@plt>
mov    0x4(%rsp),%ebx
jmp    157f <main+0x33f>
mov    0x2a92(%rip),%rax
mov    (%rax),%ebx
mov    0x2a81(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
lea    0xb4d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
jmp    1571 <main+0x331>
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   10d0 <toml_get@plt>
test   %rax,%rax
jne    159b <main+0x35b>
mov    0x2a5b(%rip),%rax
mov    (%rax),%edi
lea    0xb30(%rip),%rsi
mov    %rbx,%rdx
call   10a0 <fprintf@plt>
mov    0x2a33(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%rdi
call   1040 <toml_free@plt>
mov    %ebx,%edi
call   1140 <exit@plt>
call   1060 <toml_tojson@plt>
mov    0x4(%rsp),%ebx
jmp    157f <main+0x33f>
mov    0x2a06(%rip),%rcx
mov    (%rcx),%esi
cmpl   $0x0,0x8(%rsp)
mov    0x4(%rsp),%ebx
mov    %rax,%rdi
jne    15b9 <main+0x379>
call   1110 <toml_dump@plt>
jmp    157f <main+0x33f>
call   1060 <toml_tojson@plt>
jmp    157f <main+0x33f>

LLVM IR (-O0):
%struct.toml_node = type { i32 }
%struct.stat = type { i32 }
@EXIT_SUCCESS = global i32 0
@.str = [12 x i8] c"parser_test\00"
@.str.1 = [8 x i8] c"t:dg:hj\00"
@optarg = global i8* null
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [10 x i8] c"open: %s\0A\00"
@errno = global i32 0
@.str.3 = [10 x i8] c"stat: %s\0A\00"
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@MAP_FILE = global i32 0
@MAP_PRIVATE = global i32 0
@.str.4 = [10 x i8] c"mmap: %s\0A\00"
@.str.5 = [13 x i8] c"realloc: %s\0A\00"
@STDIN_FILENO = global i32 0
@.str.6 = [15 x i8] c"toml_init: %s\0A\00"
@.str.7 = [12 x i8] c"munmap: %s\0A\00"
@stdout = global i32 0
@.str.8 = [14 x i8] c"no node '%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 %struct.toml_node*
%10 = alloca i8*
%11 = alloca %struct.stat
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca %struct.toml_node*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i8* null, i8** %10
store i32 0, i32* %13
store i32 0, i32* %14
store i8* null, i8** %15
store i8* null, i8** %16
%23 = load i32, i32* @EXIT_SUCCESS
store i32 %23, i32* %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i8* @basename(i8* %26)
store i8* %27, i8** %18
%28 = load i8*, i8** %18
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %2
store i32 1, i32* %13
store i32 1, i32* %14
br label %32
32: ; preds = %31, %2
br label %33
33: ; preds = %56, %32
%34 = load i32, i32* %4
%35 = load i8**, i8*** %5
%36 = call i32 @getopt(i32 %34, i8** %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 %36, i32* %12
%37 = icmp ne i32 %36, -1
br i1 %37, label %38, label %57
38: ; preds = %33
%39 = load i32, i32* %12
switch i32 %39, label %51 [
i32 116, label %40
i32 100, label %42
i32 103, label %43
i32 104, label %45
i32 106, label %50
]
40: ; preds = %38
%41 = load i8*, i8** @optarg
store i8* %41, i8** %15
br label %56
42: ; preds = %38
store i32 1, i32* %13
br label %56
43: ; preds = %38
%44 = load i8*, i8** @optarg
store i8* %44, i8** %16
br label %56
45: ; preds = %38
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 0
%48 = load i8*, i8** %47
%49 = call i32 @usage(i8* %48, i32 1, i32* null)
br label %56
50: ; preds = %38
store i32 1, i32* %14
br label %56
51: ; preds = %38
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = call i32 @usage(i8* %54, i32 1, i32* null)
br label %56
56: ; preds = %51, %50, %45, %43, %42, %40
br label %33
57: ; preds = %33
%58 = load i8*, i8** %15
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %105
60: ; preds = %57
%61 = load i8*, i8** %15
%62 = load i32, i32* @O_RDONLY
%63 = call i32 @open(i8* %61, i32 %62)
store i32 %63, i32* %6
%64 = load i32, i32* %6
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %72
66: ; preds = %60
%67 = load i32, i32* @stderr
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 @fprintf(i32 %67, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %69)
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %60
%73 = load i32, i32* %6
%74 = call i32 @fstat(i32 %73, %struct.stat* %11)
store i32 %74, i32* %7
%75 = load i32, i32* %7
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %84
77: ; preds = %72
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %80)
%82 = load i32, i32* @EXIT_FAILURE
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %72
%85 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%86 = load i32, i32* %85
%87 = load i32, i32* @PROT_READ
%88 = load i32, i32* @MAP_FILE
%89 = load i32, i32* @MAP_PRIVATE
%90 = or i32 %88, %89
%91 = load i32, i32* %6
%92 = call i8* @mmap(i32* null, i32 %86, i32 %87, i32 %90, i32 %91, i32 0)
store i8* %92, i8** %10
%93 = load i8*, i8** %10
%94 = icmp ne i8* %93, null
br i1 %94, label %102, label %95
95: ; preds = %84
%96 = load i32, i32* @stderr
%97 = load i32, i32* @errno
%98 = call i8* @strerror(i32 %97)
%99 = call i32 @fprintf(i32 %96, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %98)
%100 = load i32, i32* @EXIT_FAILURE
%101 = call i32 @exit(i32 %100)
unreachable
102: ; preds = %84
%103 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%104 = load i32, i32* %103
store i32 %104, i32* %8
br label %141
105: ; preds = %57
store i32 1048576, i32* %19
store i32 0, i32* %20
br label %106
106: ; preds = %137, %105
br i1 true, label %107, label %140
107: ; preds = %106
%108 = load i8*, i8** %10
%109 = load i32, i32* %20
%110 = add nsw i32 %109, 1
%111 = mul nsw i32 1048576, %110
%112 = call i8* @realloc(i8* %108, i32 %111)
store i8* %112, i8** %10
%113 = load i8*, i8** %10
%114 = icmp ne i8* %113, null
br i1 %114, label %122, label %115
115: ; preds = %107
%116 = load i32, i32* @stderr
%117 = load i32, i32* @errno
%118 = call i8* @strerror(i32 %117)
%119 = call i32 @fprintf(i32 %116, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %118)
%120 = load i32, i32* @EXIT_FAILURE
%121 = call i32 @exit(i32 %120)
unreachable
122: ; preds = %107
%123 = load i32, i32* @STDIN_FILENO
%124 = load i8*, i8** %10
%125 = load i32, i32* %20
%126 = mul nsw i32 1048576, %125
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i8, i8* %124, i64 %127
%129 = call i32 @read(i32 %123, i8* %128, i32 1048576)
store i32 %129, i32* %21
%130 = load i32, i32* %21
%131 = load i32, i32* %8
%132 = add nsw i32 %131, %130
store i32 %132, i32* %8
%133 = load i32, i32* %21
%134 = icmp slt i32 %133, 1048576
br i1 %134, label %135, label %136
135: ; preds = %122
br label %140
136: ; preds = %122
br label %137
137: ; preds = %136
%138 = load i32, i32* %20
%139 = add nsw i32 %138, 1
store i32 %139, i32* %20
br label %106
140: ; preds = %135, %106
br label %141
141: ; preds = %140, %102
%142 = call i32 @toml_init(%struct.toml_node** %9)
store i32 %142, i32* %7
%143 = load i32, i32* %7
%144 = icmp eq i32 %143, -1
br i1 %144, label %145, label %152
145: ; preds = %141
%146 = load i32, i32* @stderr
%147 = load i32, i32* @errno
%148 = call i8* @strerror(i32 %147)
%149 = call i32 @fprintf(i32 %146, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %148)
%150 = load i32, i32* @EXIT_FAILURE
%151 = call i32 @exit(i32 %150)
unreachable
152: ; preds = %141
%153 = load %struct.toml_node*, %struct.toml_node** %9
%154 = load i8*, i8** %10
%155 = load i32, i32* %8
%156 = call i32 @toml_parse(%struct.toml_node* %153, i8* %154, i32 %155)
store i32 %156, i32* %7
%157 = load i32, i32* %7
%158 = icmp ne i32 %157, 0
br i1 %158, label %159, label %161
159: ; preds = %152
%160 = load i32, i32* @EXIT_FAILURE
store i32 %160, i32* %17
br label %222
161: ; preds = %152
%162 = load i8*, i8** %15
%163 = icmp ne i8* %162, null
br i1 %163, label %164, label %179
164: ; preds = %161
%165 = load i8*, i8** %10
%166 = load i32, i32* %8
%167 = call i32 @munmap(i8* %165, i32 %166)
store i32 %167, i32* %7
%168 = load i32, i32* %7
%169 = icmp ne i32 %168, 0
br i1 %169, label %170, label %176
170: ; preds = %164
%171 = load i32, i32* @stderr
%172 = load i32, i32* @errno
%173 = call i8* @strerror(i32 %172)
%174 = call i32 @fprintf(i32 %171, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %173)
%175 = load i32, i32* @EXIT_FAILURE
store i32 %175, i32* %17
br label %222
176: ; preds = %164
%177 = load i32, i32* %6
%178 = call i32 @close(i32 %177)
br label %179
179: ; preds = %176, %161
%180 = load i32, i32* %13
%181 = icmp ne i32 %180, 0
br i1 %181, label %182, label %194
182: ; preds = %179
%183 = load i32, i32* %14
%184 = icmp ne i32 %183, 0
br i1 %184, label %185, label %189
185: ; preds = %182
%186 = load %struct.toml_node*, %struct.toml_node** %9
%187 = load i32, i32* @stdout
%188 = call i32 @toml_tojson(%struct.toml_node* %186, i32 %187)
br label %193
189: ; preds = %182
%190 = load %struct.toml_node*, %struct.toml_node** %9
%191 = load i32, i32* @stdout
%192 = call i32 @toml_dump(%struct.toml_node* %190, i32 %191)
br label %193
193: ; preds = %189, %185
br label %221
194: ; preds = %179
%195 = load i8*, i8** %16
%196 = icmp ne i8* %195, null
br i1 %196, label %197, label %220
197: ; preds = %194
%198 = load %struct.toml_node*, %struct.toml_node** %9
%199 = load i8*, i8** %16
%200 = call %struct.toml_node* @toml_get(%struct.toml_node* %198, i8* %199)
store %struct.toml_node* %200, %struct.toml_node** %22
%201 = load %struct.toml_node*, %struct.toml_node** %22
%202 = icmp ne %struct.toml_node* %201, null
br i1 %202, label %208, label %203
203: ; preds = %197
%204 = load i32, i32* @stderr
%205 = load i8*, i8** %16
%206 = call i32 @fprintf(i32 %204, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %205)
%207 = load i32, i32* @EXIT_FAILURE
store i32 %207, i32* %17
br label %222
208: ; preds = %197
%209 = load i32, i32* %14
%210 = icmp ne i32 %209, 0
br i1 %210, label %211, label %215
211: ; preds = %208
%212 = load %struct.toml_node*, %struct.toml_node** %22
%213 = load i32, i32* @stdout
%214 = call i32 @toml_tojson(%struct.toml_node* %212, i32 %213)
br label %219
215: ; preds = %208
%216 = load %struct.toml_node*, %struct.toml_node** %22
%217 = load i32, i32* @stdout
%218 = call i32 @toml_dump(%struct.toml_node* %216, i32 %217)
br label %219
219: ; preds = %215, %211
br label %220
220: ; preds = %219, %194
br label %221
221: ; preds = %220, %193
br label %222
222: ; preds = %221, %203, %170, %159
%223 = load %struct.toml_node*, %struct.toml_node** %9
%224 = call i32 @toml_free(%struct.toml_node* %223)
%225 = load i32, i32* %17
%226 = call i32 @exit(i32 %225)
unreachable
}

LLVM IR (-O2):
%struct.toml_node = type { i32 }
%struct.stat = type { i32 }
@EXIT_SUCCESS = global i32 0
@.str = [12 x i8] c"parser_test\00"
@.str.1 = [8 x i8] c"t:dg:hj\00"
@optarg = global i8* null
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [10 x i8] c"open: %s\0A\00"
@errno = global i32 0
@.str.3 = [10 x i8] c"stat: %s\0A\00"
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@MAP_FILE = global i32 0
@MAP_PRIVATE = global i32 0
@.str.4 = [10 x i8] c"mmap: %s\0A\00"
@.str.5 = [13 x i8] c"realloc: %s\0A\00"
@STDIN_FILENO = global i32 0
@.str.6 = [15 x i8] c"toml_init: %s\0A\00"
@.str.7 = [12 x i8] c"munmap: %s\0A\00"
@stdout = global i32 0
@.str.8 = [14 x i8] c"no node '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.toml_node*
%4 = alloca %struct.stat
%5 = bitcast %struct.toml_node** %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = load i32, i32* @EXIT_SUCCESS
%8 = load i8*, i8** %1
%9 = tail call i8* @basename(i8* %8)
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %27, %2
%14 = phi i32 [ %12, %2 ], [ 1, %27 ]
%15 = phi i32 [ %12, %2 ], [ %19, %27 ]
%16 = phi i8* [ null, %2 ], [ %23, %27 ]
%17 = phi i8* [ null, %2 ], [ %26, %27 ]
br label %18
18: ; preds = %27, %13
%19 = phi i32 [ %15, %13 ], [ 1, %27 ]
%20 = phi i8* [ %16, %13 ], [ %23, %27 ]
%21 = phi i8* [ %17, %13 ], [ %26, %27 ]
br label %22
22: ; preds = %18, %29
%23 = phi i8* [ %20, %18 ], [ %30, %29 ]
%24 = phi i8* [ %21, %18 ], [ %26, %29 ]
br label %25
25: ; preds = %22, %31
%26 = phi i8* [ %24, %22 ], [ %32, %31 ]
br label %27
27: ; preds = %39, %25
%28 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
switch i32 %28, label %36 [
i32 -1, label %40
i32 116, label %29
i32 100, label %13
i32 103, label %31
i32 104, label %33
i32 106, label %18
]
29: ; preds = %27
%30 = load i8*, i8** @optarg
br label %22
31: ; preds = %27
%32 = load i8*, i8** @optarg
br label %25
33: ; preds = %27
%34 = load i8*, i8** %1
%35 = tail call i32 @usage(i8* %34, i32 1, i32* null)
br label %39
36: ; preds = %27
%37 = load i8*, i8** %1
%38 = tail call i32 @usage(i8* %37, i32 1, i32* null)
br label %39
39: ; preds = %36, %33
br label %27
40: ; preds = %27
%41 = icmp eq i8* %23, null
br i1 %41, label %78, label %42
42: ; preds = %40
%43 = load i32, i32* @O_RDONLY
%44 = tail call i32 @open(i8* %23, i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = tail call i8* @strerror(i32 %48)
%50 = tail call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%51 = tail call i32 @exit(i32 1)
unreachable
52: ; preds = %42
%53 = call i32 @fstat(i32 %44, %struct.stat* %4)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %62
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = tail call i8* @strerror(i32 %57)
%59 = tail call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = tail call i32 @exit(i32 %60)
unreachable
62: ; preds = %52
%63 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%64 = load i32, i32* %63
%65 = load i32, i32* @PROT_READ
%66 = load i32, i32* @MAP_FILE
%67 = load i32, i32* @MAP_PRIVATE
%68 = or i32 %67, %66
%69 = tail call i8* @mmap(i32* null, i32 %64, i32 %65, i32 %68, i32 %44, i32 0)
%70 = icmp eq i8* %69, null
br i1 %70, label %71, label %102
71: ; preds = %62
%72 = load i32, i32* @stderr
%73 = load i32, i32* @errno
%74 = tail call i8* @strerror(i32 %73)
%75 = tail call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %74)
%76 = load i32, i32* @EXIT_FAILURE
%77 = tail call i32 @exit(i32 %76)
unreachable
78: ; preds = %40, %94
%79 = phi i64 [ %82, %94 ], [ 0, %40 ]
%80 = phi i8* [ %85, %94 ], [ null, %40 ]
%81 = phi i32 [ %100, %94 ], [ 0, %40 ]
%82 = add nuw i64 %79, 1
%83 = trunc i64 %82 to i32
%84 = shl i32 %83, 20
%85 = tail call i8* @realloc(i8* %80, i32 %84)
%86 = icmp eq i8* %85, null
br i1 %86, label %87, label %94
87: ; preds = %78
%88 = load i32, i32* @stderr
%89 = load i32, i32* @errno
%90 = tail call i8* @strerror(i32 %89)
%91 = tail call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %90)
%92 = load i32, i32* @EXIT_FAILURE
%93 = tail call i32 @exit(i32 %92)
unreachable
94: ; preds = %78
%95 = load i32, i32* @STDIN_FILENO
%96 = shl i64 %79, 20
%97 = and i64 %96, 4293918720
%98 = getelementptr inbounds i8, i8* %85, i64 %97
%99 = tail call i32 @read(i32 %95, i8* %98, i32 1048576)
%100 = add nsw i32 %99, %81
%101 = icmp slt i32 %99, 1048576
br i1 %101, label %102, label %78
102: ; preds = %94, %62
%103 = phi i8* [ %69, %62 ], [ %85, %94 ]
%104 = phi i32 [ %64, %62 ], [ %100, %94 ]
%105 = phi i32 [ %44, %62 ], [ undef, %94 ]
%106 = call i32 @toml_init(%struct.toml_node** %3)
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %115
108: ; preds = %102
%109 = load i32, i32* @stderr
%110 = load i32, i32* @errno
%111 = call i8* @strerror(i32 %110)
%112 = call i32 @fprintf(i32 %109, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %111)
%113 = load i32, i32* @EXIT_FAILURE
%114 = call i32 @exit(i32 %113)
unreachable
115: ; preds = %102
%116 = load %struct.toml_node*, %struct.toml_node** %3
%117 = call i32 @toml_parse(%struct.toml_node* %116, i8* %103, i32 %104)
%118 = icmp eq i32 %117, 0
br i1 %118, label %121, label %119
119: ; preds = %115
%120 = load i32, i32* @EXIT_FAILURE
br label %160
121: ; preds = %115
br i1 %41, label %133, label %122
122: ; preds = %121
%123 = call i32 @munmap(i8* %103, i32 %104)
%124 = icmp eq i32 %123, 0
br i1 %124, label %131, label %125
125: ; preds = %122
%126 = load i32, i32* @stderr
%127 = load i32, i32* @errno
%128 = call i8* @strerror(i32 %127)
%129 = call i32 @fprintf(i32 %126, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %128)
%130 = load i32, i32* @EXIT_FAILURE
br label %160
131: ; preds = %122
%132 = call i32 @close(i32 %105)
br label %133
133: ; preds = %131, %121
%134 = icmp eq i32 %14, 0
br i1 %134, label %143, label %135
135: ; preds = %133
%136 = icmp eq i32 %19, 0
%137 = load %struct.toml_node*, %struct.toml_node** %3
%138 = load i32, i32* @stdout
br i1 %136, label %141, label %139
139: ; preds = %135
%140 = call i32 @toml_tojson(%struct.toml_node* %137, i32 %138)
br label %160
141: ; preds = %135
%142 = call i32 @toml_dump(%struct.toml_node* %137, i32 %138)
br label %160
143: ; preds = %133
%144 = icmp eq i8* %26, null
br i1 %144, label %160, label %145
145: ; preds = %143
%146 = load %struct.toml_node*, %struct.toml_node** %3
%147 = call %struct.toml_node* @toml_get(%struct.toml_node* %146, i8* %26)
%148 = icmp eq %struct.toml_node* %147, null
br i1 %148, label %149, label %153
149: ; preds = %145
%150 = load i32, i32* @stderr
%151 = call i32 @fprintf(i32 %150, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %26)
%152 = load i32, i32* @EXIT_FAILURE
br label %160
153: ; preds = %145
%154 = icmp eq i32 %19, 0
%155 = load i32, i32* @stdout
br i1 %154, label %158, label %156
156: ; preds = %153
%157 = call i32 @toml_tojson(%struct.toml_node* %147, i32 %155)
br label %160
158: ; preds = %153
%159 = call i32 @toml_dump(%struct.toml_node* %147, i32 %155)
br label %160
160: ; preds = %149, %158, %156, %141, %139, %143, %125, %119
%161 = phi i32 [ %120, %119 ], [ %130, %125 ], [ %7, %139 ], [ %7, %141 ], [ %7, %143 ], [ %152, %149 ], [ %7, %158 ], [ %7, %156 ]
%162 = load %struct.toml_node*, %struct.toml_node** %3
%163 = call i32 @toml_free(%struct.toml_node* %162)
%164 = call i32 @exit(i32 %161)
unreachable
}