#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 scalar_t__ uint64_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
void **alloca(int);
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(void *);
scalar_t__ get_time();
void *malloc(int);
int /*<<< orphan*/ memset(void **, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
void *realloc(void *, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
scalar_t__ strlen(char *);
void run_memsim(char *filename, int silent, void (*stats_fun)(), int debug) {
  int f = open(filename, O_RDONLY);
  char buf[256];
  char ptr_buf[80];
  if (f == -1) {
    fprintf(stderr, "couldn't open %s\n", filename);
    fprintf(stderr, "%s\n", strerror(errno));
    return;
  }
  if (silent)
    debug = 0;
  void **stack = alloca(4096 * sizeof(void *));
  memset(stack, 0, 4096 * sizeof(void *));
  int mem_pos = -1;
  int mem_size = 0;
  uint64_t t_malloc = 0;
  uint64_t t_realloc = 0;
  uint64_t t_free = 0;
  uint64_t t_stats = 0;
  uint32_t c_malloc = 0;
  uint32_t c_realloc = 0;
  uint32_t c_free = 0;
  uint32_t c_stats = 0;
  int rd = 0;
  int i = 0;
  while ((rd = read(f, buf, 256)) > 0) {
    char *c = buf;
    int j = 0;
    while (*c != 0) {
      if (rd == j)
        break;
      if (*c == 'e')
        return;
      if (*c == ' ' || *c == '\n' || *c == '=' || *c == 0) {
        ptr_buf[i] = 0;
        i = 0;
        if (strlen(ptr_buf) == 0) {
        } else if (ptr_buf[0] == 's') {
          if (debug) {
            printf("calling stats function [\n");
          }
          uint64_t t = get_time();
          if (stats_fun != 0)
            stats_fun();
          t = get_time() - t;
          t_stats += t;
          if (debug) {
            printf("stats function called took %ums ]\n", (unsigned int)t);
          }
          ++c_stats;
        } else if (*c == '=') {
          mem_pos = atoi(ptr_buf);
        } else {
          mem_size = atoi(ptr_buf);
          if (mem_pos == -1) {
            mem_pos = mem_size;
            void **ptr = &(stack[mem_pos]);
            if (debug) {
              printf("free memory at %d with ptr %p [\n", mem_pos, *ptr);
            }
            uint64_t t = get_time();
            free(*ptr);
            t = get_time() - t;
            t_free += t;
            if (errno > 0)
              fprintf(stderr, "%s\n", strerror(errno));
            *ptr = 0;
            if (debug) {
              printf("memory freed at %d took %ums ]\n", mem_pos,
                     (unsigned int)t);
            }
            ++c_free;
          } else {
            void **ptr = &(stack[mem_pos]);
            if (*ptr == 0) {
              if (debug) {
                printf("allocating memory at %d with %d size [\n", mem_pos,
                       mem_size);
              }
              uint64_t t = get_time();
              *ptr = malloc(mem_size);
              t = get_time() - t;
              t_malloc += t;
              if (errno > 0)
                fprintf(stderr, "%s\n", strerror(errno));
              if (debug) {
                printf("memory allocated at %d with %d size with ptr %p took "
                       "%ums ]\n",
                       mem_pos, mem_size, *ptr, (unsigned int)t);
              }
              ++c_malloc;
            } else {
              if (debug) {
                printf("reallocating memory at %d with %d size [\n", mem_pos,
                       mem_size);
              }
              uint64_t t = get_time();
              *ptr = realloc(*ptr, mem_size);
              t = get_time() - t;
              t_realloc += t;
              if (errno > 0)
                fprintf(stderr, "%s\n", strerror(errno));
              if (debug) {
                printf("memory reallocated at %d with %d size with ptr %p took "
                       "%ums ]\n",
                       mem_pos, mem_size, *ptr, (unsigned int)t);
              }
              ++c_realloc;
            }
          }
          mem_pos = -1;
          mem_size = 0;
        }
      } else {
        ptr_buf[i] = *c;
        ++i;
      }
      ++c;
      ++j;
    }
  }
  if (!silent) {
    printf("malloc %d calls took %ums\n", c_malloc, (unsigned int)t_malloc);
    printf("realloc %d calls took %ums\n", c_realloc, (unsigned int)t_realloc);
    printf("free %d calls took %ums\n", c_free, (unsigned int)t_free);
    printf("stats %d calls took %ums\n", c_stats, (unsigned int)t_stats);
  }
  close(f);
}


x86 assembly (clang, -O0):
<run_memsim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1269 <run_memsim+0x89>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdd4(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1fc(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    -0x1fc(%rbp),%edi
mov    %rax,%rdx
lea    0xdaf(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1962 <run_memsim+0x782>
cmpl   $0x0,-0xc(%rbp)
je     127a <run_memsim+0x9a>
movl   $0x0,-0x1c(%rbp)
mov    $0x8000,%edi
call   10b0 <alloca@plt>
mov    %rax,-0x178(%rbp)
mov    -0x178(%rbp),%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1060 <memset@plt>
movl   $0xffffffff,-0x17c(%rbp)
ff ff ff
movl   $0x0,-0x180(%rbp)
movq   $0x0,-0x188(%rbp)
movq   $0x0,-0x190(%rbp)
movq   $0x0,-0x198(%rbp)
movq   $0x0,-0x1a0(%rbp)
movl   $0x0,-0x1a4(%rbp)
movl   $0x0,-0x1a8(%rbp)
movl   $0x0,-0x1ac(%rbp)
movl   $0x0,-0x1b0(%rbp)
movl   $0x0,-0x1b4(%rbp)
movl   $0x0,-0x1b8(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
mov    %eax,-0x1b4(%rbp)
cmp    $0x0,%eax
jle    18dc <run_memsim+0x6fc>
lea    -0x120(%rbp),%rax
mov    %rax,-0x1c0(%rbp)
movl   $0x0,-0x1c4(%rbp)
mov    -0x1c0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     18d7 <run_memsim+0x6f7>
mov    -0x1b4(%rbp),%eax
cmp    -0x1c4(%rbp),%eax
jne    137f <run_memsim+0x19f>
jmp    18d7 <run_memsim+0x6f7>
mov    -0x1c0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x65,%eax
jne    1397 <run_memsim+0x1b7>
jmp    1962 <run_memsim+0x782>
mov    -0x1c0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     13e3 <run_memsim+0x203>
mov    -0x1c0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     13e3 <run_memsim+0x203>
mov    -0x1c0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
je     13e3 <run_memsim+0x203>
mov    -0x1c0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    188b <run_memsim+0x6ab>
movslq -0x1b8(%rbp),%rax
movb   $0x0,-0x170(%rbp,%rax,1)
movl   $0x0,-0x1b8(%rbp)
lea    -0x170(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    1417 <run_memsim+0x237>
jmp    1886 <run_memsim+0x6a6>
movsbl -0x170(%rbp),%eax
cmp    $0x73,%eax
jne    14bc <run_memsim+0x2dc>
cmpl   $0x0,-0x1c(%rbp)
je     143f <run_memsim+0x25f>
lea    0xbda(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <get_time@plt>
mov    %rax,-0x1d0(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     145d <run_memsim+0x27d>
mov    $0x0,%al
call   *-0x18(%rbp)
mov    $0x0,%al
call   1090 <get_time@plt>
sub    -0x1d0(%rbp),%rax
mov    %rax,-0x1d0(%rbp)
mov    -0x1d0(%rbp),%rax
add    -0x1a0(%rbp),%rax
mov    %rax,-0x1a0(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     14a8 <run_memsim+0x2c8>
mov    -0x1d0(%rbp),%rax
mov    %eax,%esi
lea    0xb8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1b0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b0(%rbp)
jmp    1881 <run_memsim+0x6a1>
mov    -0x1c0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
jne    14e6 <run_memsim+0x306>
lea    -0x170(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x17c(%rbp)
jmp    187c <run_memsim+0x69c>
lea    -0x170(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x180(%rbp)
cmpl   $0xffffffff,-0x17c(%rbp)
jne    1629 <run_memsim+0x449>
mov    -0x180(%rbp),%eax
mov    %eax,-0x17c(%rbp)
mov    -0x178(%rbp),%rax
movslq -0x17c(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x1d8(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1555 <run_memsim+0x375>
mov    -0x17c(%rbp),%esi
mov    -0x1d8(%rbp),%rax
mov    (%rax),%rdx
lea    0xb01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <get_time@plt>
mov    %rax,-0x1e0(%rbp)
mov    -0x1d8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1090 <get_time@plt>
sub    -0x1e0(%rbp),%rax
mov    %rax,-0x1e0(%rbp)
mov    -0x1e0(%rbp),%rax
add    -0x198(%rbp),%rax
mov    %rax,-0x198(%rbp)
mov    0x2a2d(%rip),%rax
cmpq   $0x0,(%rax)
jle    15e0 <run_memsim+0x400>
mov    0x2a24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x200(%rbp)
mov    0x2a0d(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    -0x200(%rbp),%edi
mov    %rax,%rdx
lea    0xa33(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x1d8(%rbp),%rax
movq   $0x0,(%rax)
cmpl   $0x0,-0x1c(%rbp)
je     1615 <run_memsim+0x435>
mov    -0x17c(%rbp),%esi
mov    -0x1e0(%rbp),%rax
mov    %eax,%edx
lea    0xa62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    1868 <run_memsim+0x688>
mov    -0x178(%rbp),%rax
movslq -0x17c(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x1e8(%rbp)
mov    -0x1e8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    175a <run_memsim+0x57a>
cmpl   $0x0,-0x1c(%rbp)
je     167a <run_memsim+0x49a>
mov    -0x17c(%rbp),%esi
mov    -0x180(%rbp),%edx
lea    0xa5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <get_time@plt>
mov    %rax,-0x1f0(%rbp)
mov    -0x180(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,%rcx
mov    -0x1e8(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1090 <get_time@plt>
sub    -0x1f0(%rbp),%rax
mov    %rax,-0x1f0(%rbp)
mov    -0x1f0(%rbp),%rax
add    -0x188(%rbp),%rax
mov    %rax,-0x188(%rbp)
mov    0x28ff(%rip),%rax
cmpq   $0x0,(%rax)
jle    170e <run_memsim+0x52e>
mov    0x28f6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x204(%rbp)
mov    0x28df(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    -0x204(%rbp),%edi
mov    %rax,%rdx
lea    0x905(%rip),%rsi
call   10a0 <fprintf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1746 <run_memsim+0x566>
mov    -0x17c(%rbp),%esi
mov    -0x180(%rbp),%edx
mov    -0x1e8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x1f0(%rbp),%rax
mov    %eax,%r8d
lea    0x951(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1863 <run_memsim+0x683>
cmpl   $0x0,-0x1c(%rbp)
je     177e <run_memsim+0x59e>
mov    -0x17c(%rbp),%esi
mov    -0x180(%rbp),%edx
lea    0x956(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <get_time@plt>
mov    %rax,-0x1f8(%rbp)
mov    -0x1e8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x180(%rbp),%esi
call   10d0 <realloc@plt>
mov    %rax,%rcx
mov    -0x1e8(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1090 <get_time@plt>
sub    -0x1f8(%rbp),%rax
mov    %rax,-0x1f8(%rbp)
mov    -0x1f8(%rbp),%rax
add    -0x190(%rbp),%rax
mov    %rax,-0x190(%rbp)
mov    0x27f1(%rip),%rax
cmpq   $0x0,(%rax)
jle    181c <run_memsim+0x63c>
mov    0x27e8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x208(%rbp)
mov    0x27d1(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    -0x208(%rbp),%edi
mov    %rax,%rdx
lea    0x7f7(%rip),%rsi
call   10a0 <fprintf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1854 <run_memsim+0x674>
mov    -0x17c(%rbp),%esi
mov    -0x180(%rbp),%edx
mov    -0x1e8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x1f8(%rbp),%rax
mov    %eax,%r8d
lea    0x8aa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    1868 <run_memsim+0x688>
movl   $0xffffffff,-0x17c(%rbp)
ff ff ff
movl   $0x0,-0x180(%rbp)
jmp    1881 <run_memsim+0x6a1>
jmp    1886 <run_memsim+0x6a6>
jmp    18b1 <run_memsim+0x6d1>
mov    -0x1c0(%rbp),%rax
mov    (%rax),%cl
movslq -0x1b8(%rbp),%rax
mov    %cl,-0x170(%rbp,%rax,1)
mov    -0x1b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
mov    -0x1c0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1c0(%rbp)
mov    -0x1c4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c4(%rbp)
jmp    1355 <run_memsim+0x175>
jmp    131a <run_memsim+0x13a>
cmpl   $0x0,-0xc(%rbp)
jne    195a <run_memsim+0x77a>
mov    -0x1a4(%rbp),%esi
mov    -0x188(%rbp),%rax
mov    %eax,%edx
lea    0x83a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1a8(%rbp),%esi
mov    -0x190(%rbp),%rax
mov    %eax,%edx
lea    0x838(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1ac(%rbp),%esi
mov    -0x198(%rbp),%rax
mov    %eax,%edx
lea    0x837(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1b0(%rbp),%esi
mov    -0x1a0(%rbp),%rax
mov    %eax,%edx
lea    0x833(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_memsim>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1c8,%rsp
mov    %ecx,%r14d
mov    %rdx,0x38(%rsp)
mov    %esi,%r15d
mov    %rdi,%rbp
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     165b <run_memsim+0x47b>
mov    %eax,%ebx
mov    $0x8000,%edi
call   10b0 <alloca@plt>
mov    %rax,0x18(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1060 <memset@plt>
lea    0xc0(%rsp),%rsi
mov    %ebx,%edi
mov    $0x100,%edx
call   1080 <read@plt>
test   %eax,%eax
mov    %r15d,0x68(%rsp)
jle    16b8 <run_memsim+0x4d8>
test   %r15d,%r15d
sete   %cl
test   %r14d,%r14d
setne  %dl
and    %cl,%dl
mov    %dl,0xf(%rsp)
movl   $0xffffffff,0x10(%rsp)
ff
movabs $0x2000000100000400,%rbp
xor    %r13d,%r13d
movl   $0x0,0x2c(%rsp)
movl   $0x0,0x24(%rsp)
movl   $0x0,0x28(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x40(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x60(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x50(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x58(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x48(%rsp)
mov    %ebx,0x6c(%rsp)
mov    0x38(%rsp),%r15
jmp    12f0 <run_memsim+0x110>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x6c(%rsp),%ebx
mov    %ebx,%edi
lea    0xc0(%rsp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    16f3 <run_memsim+0x513>
mov    0xc0(%rsp),%bl
test   %bl,%bl
je     12d0 <run_memsim+0xf0>
mov    %eax,%r14d
mov    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x3d,%bl
ja     13a0 <run_memsim+0x1c0>
movzbl %bl,%eax
bt     %rax,%rbp
jae    13a0 <run_memsim+0x1c0>
movslq %r13d,%rax
movb   $0x0,0x70(%rsp,%rax,1)
xor    %r13d,%r13d
movzbl 0x70(%rsp),%eax
test   %al,%al
je     1634 <run_memsim+0x454>
cmp    $0x73,%al
jne    13c0 <run_memsim+0x1e0>
cmpb   $0x0,0xf(%rsp)
je     1359 <run_memsim+0x179>
lea    0xe32(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1090 <get_time@plt>
mov    %rax,%rbx
test   %r15,%r15
je     136d <run_memsim+0x18d>
xor    %eax,%eax
call   *%r15
xor    %eax,%eax
call   1090 <get_time@plt>
mov    %rax,%rbp
sub    %rbx,%rbp
cmpb   $0x0,0xf(%rsp)
je     1391 <run_memsim+0x1b1>
lea    0xc8a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    %rbp,0x60(%rsp)
addl   $0x1,0x2c(%rsp)
jmp    162a <run_memsim+0x44a>
cmp    $0x65,%bl
je     16a6 <run_memsim+0x4c6>
movslq %r13d,%rax
mov    %bl,0x70(%rsp,%rax,1)
add    $0x1,%r13d
jmp    1634 <run_memsim+0x454>
nopl   0x0(%rax)
lea    0x70(%rsp),%rdi
call   10f0 <atoi@plt>
mov    %eax,%r15d
cmp    $0x3d,%bl
jne    13e1 <run_memsim+0x201>
mov    %r15d,0x10(%rsp)
mov    0x38(%rsp),%r15
jmp    1634 <run_memsim+0x454>
mov    0x10(%rsp),%esi
cmp    $0xffffffff,%esi
je     14b4 <run_memsim+0x2d4>
movslq %esi,%rbp
mov    0x18(%rsp),%rax
cmpq   $0x0,(%rax,%rbp,8)
je     156b <run_memsim+0x38b>
cmpb   $0x0,0xf(%rsp)
je     1419 <run_memsim+0x239>
lea    0xca4(%rip),%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1090 <get_time@plt>
mov    %rax,0x30(%rsp)
mov    0x18(%rsp),%rbx
mov    (%rbx,%rbp,8),%rdi
mov    %r15d,%esi
call   10d0 <realloc@plt>
mov    %rax,(%rbx,%rbp,8)
xor    %eax,%eax
call   1090 <get_time@plt>
mov    %rax,%rbx
mov    0x2b85(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
jle    1478 <run_memsim+0x298>
mov    0x2b7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
call   1100 <strerror@plt>
mov    0x20(%rsp),%edi
lea    0xb9e(%rip),%rsi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
sub    0x30(%rsp),%rbx
cmpb   $0x0,0xf(%rsp)
je     14a5 <run_memsim+0x2c5>
mov    0x18(%rsp),%rax
mov    (%rax,%rbp,8),%rcx
lea    0xc49(%rip),%rdi
mov    0x10(%rsp),%esi
mov    %r15d,%edx
mov    %ebx,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
add    %rbx,0x58(%rsp)
addl   $0x1,0x28(%rsp)
jmp    161d <run_memsim+0x43d>
movslq %r15d,%rbp
cmpb   $0x0,0xf(%rsp)
je     14d8 <run_memsim+0x2f8>
mov    0x18(%rsp),%rax
mov    (%rax,%rbp,8),%rdx
lea    0xb67(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1090 <get_time@plt>
mov    %rax,0x10(%rsp)
mov    0x18(%rsp),%rax
mov    (%rax,%rbp,8),%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1090 <get_time@plt>
mov    %rax,%rbx
mov    0x2acd(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
jle    1530 <run_memsim+0x350>
mov    0x2ac6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
call   1100 <strerror@plt>
mov    0x30(%rsp),%edi
lea    0xae6(%rip),%rsi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
sub    0x10(%rsp),%rbx
mov    0x18(%rsp),%rax
movq   $0x0,(%rax,%rbp,8)
cmpb   $0x0,0xf(%rsp)
je     155c <run_memsim+0x37c>
lea    0xb06(%rip),%rdi
mov    %r15d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    %rbx,0x50(%rsp)
addl   $0x1,0x24(%rsp)
jmp    161d <run_memsim+0x43d>
cmpb   $0x0,0xf(%rsp)
je     1583 <run_memsim+0x3a3>
lea    0xb3c(%rip),%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1090 <get_time@plt>
mov    %rax,0x30(%rsp)
mov    %r15d,%edi
call   10c0 <malloc@plt>
mov    0x18(%rsp),%rcx
mov    %rax,(%rcx,%rbp,8)
xor    %eax,%eax
call   1090 <get_time@plt>
mov    %rax,%rbx
mov    0x2a1f(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
jle    15de <run_memsim+0x3fe>
mov    0x2a18(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
call   1100 <strerror@plt>
mov    0x20(%rsp),%edi
lea    0xa38(%rip),%rsi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
sub    0x30(%rsp),%rbx
cmpb   $0x0,0xf(%rsp)
je     160b <run_memsim+0x42b>
mov    0x18(%rsp),%rax
mov    (%rax,%rbp,8),%rcx
lea    0xa7c(%rip),%rdi
mov    0x10(%rsp),%esi
mov    %r15d,%edx
mov    %ebx,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
add    %rbx,0x48(%rsp)
mov    0x40(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x40(%rsp)
movl   $0xffffffff,0x10(%rsp)
ff
mov    0x38(%rsp),%r15
movabs $0x2000000100000400,%rbp
movzbl 0xc0(%rsp,%r12,1),%ebx
test   %bl,%bl
je     12d0 <run_memsim+0xf0>
lea    0x1(%r12),%rax
cmp    %r12d,%r14d
mov    %rax,%r12
jne    1310 <run_memsim+0x130>
jmp    12d0 <run_memsim+0xf0>
mov    0x2976(%rip),%rbx
mov    (%rbx),%edi
lea    0x995(%rip),%rsi
mov    %rbp,%rdx
call   10a0 <fprintf@plt>
mov    (%rbx),%ebx
mov    0x2954(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0x983(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
add    $0x1c8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <fprintf@plt>
add    $0x1c8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
mov    %rax,0x40(%rsp)
xor    %eax,%eax
mov    %rax,0x48(%rsp)
xor    %eax,%eax
mov    %rax,0x58(%rsp)
xor    %eax,%eax
mov    %rax,0x50(%rsp)
xor    %eax,%eax
mov    %rax,0x60(%rsp)
movl   $0x0,0x28(%rsp)
movl   $0x0,0x24(%rsp)
movl   $0x0,0x2c(%rsp)
cmpl   $0x0,0x68(%rsp)
jne    1757 <run_memsim+0x577>
lea    0xa1b(%rip),%rdi
mov    0x40(%rsp),%rsi
mov    0x48(%rsp),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xa1e(%rip),%rdi
mov    0x28(%rsp),%esi
mov    0x58(%rsp),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xa23(%rip),%rdi
mov    0x24(%rsp),%esi
mov    0x50(%rsp),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xa25(%rip),%rdi
mov    0x2c(%rsp),%esi
mov    0x60(%rsp),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
add    $0x1c8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <close@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"couldn't open %s\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@errno = global i64 0
@.str.2 = [26 x i8] c"calling stats function [\0A\00"
@.str.3 = [35 x i8] c"stats function called took %ums ]\0A\00"
@.str.4 = [33 x i8] c"free memory at %d with ptr %p [\0A\00"
@.str.5 = [32 x i8] c"memory freed at %d took %ums ]\0A\00"
@.str.6 = [40 x i8] c"allocating memory at %d with %d size [\0A\00"
@.str.7 = [61 x i8] c"memory allocated at %d with %d size with ptr %p took %ums ]\0A\00"
@.str.8 = [42 x i8] c"reallocating memory at %d with %d size [\0A\00"
@.str.9 = [63 x i8] c"memory reallocated at %d with %d size with ptr %p took %ums ]\0A\00"
@.str.10 = [27 x i8] c"malloc %d calls took %ums\0A\00"
@.str.11 = [28 x i8] c"realloc %d calls took %ums\0A\00"
@.str.12 = [25 x i8] c"free %d calls took %ums\0A\00"
@.str.13 = [26 x i8] c"stats %d calls took %ums\0A\00"
define void @run_memsim(i8* %0, i32 %1, void (...)* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca void (...)*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = alloca [80 x i8]
%12 = alloca i8**
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i8*
%26 = alloca i32
%27 = alloca i64
%28 = alloca i8**
%29 = alloca i64
%30 = alloca i8**
%31 = alloca i64
%32 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store void (...)* %2, void (...)** %7
store i32 %3, i32* %8
%33 = load i8*, i8** %5
%34 = load i32, i32* @O_RDONLY
%35 = call i32 @open(i8* %33, i32 %34)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %46
38: ; preds = %4
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %5
%41 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @stderr
%43 = load i64, i64* @errno
%44 = call i8* @strerror(i64 %43)
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %323
46: ; preds = %4
%47 = load i32, i32* %6
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %46
store i32 0, i32* %8
br label %50
50: ; preds = %49, %46
%51 = call i8** @alloca(i32 32768)
store i8** %51, i8*** %12
%52 = load i8**, i8*** %12
%53 = call i32 @memset(i8** %52, i32 0, i32 32768)
store i32 -1, i32* %13
store i32 0, i32* %14
store i64 0, i64* %15
store i64 0, i64* %16
store i64 0, i64* %17
store i64 0, i64* %18
store i32 0, i32* %19
store i32 0, i32* %20
store i32 0, i32* %21
store i32 0, i32* %22
store i32 0, i32* %23
store i32 0, i32* %24
br label %54
54: ; preds = %299, %50
%55 = load i32, i32* %9
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%57 = call i32 @read(i32 %55, i8* %56, i32 256)
store i32 %57, i32* %23
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %300
59: ; preds = %54
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
store i8* %60, i8** %25
store i32 0, i32* %26
br label %61
61: ; preds = %294, %59
%62 = load i8*, i8** %25
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %299
66: ; preds = %61
%67 = load i32, i32* %23
%68 = load i32, i32* %26
%69 = icmp eq i32 %67, %68
br i1 %69, label %70, label %71
70: ; preds = %66
br label %299
71: ; preds = %66
%72 = load i8*, i8** %25
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 101
br i1 %75, label %76, label %77
76: ; preds = %71
br label %323
77: ; preds = %71
%78 = load i8*, i8** %25
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 32
br i1 %81, label %97, label %82
82: ; preds = %77
%83 = load i8*, i8** %25
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = icmp eq i32 %85, 10
br i1 %86, label %97, label %87
87: ; preds = %82
%88 = load i8*, i8** %25
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 61
br i1 %91, label %97, label %92
92: ; preds = %87
%93 = load i8*, i8** %25
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %286
97: ; preds = %92, %87, %82, %77
%98 = load i32, i32* %24
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 %99
store i8 0, i8* %100
store i32 0, i32* %24
%101 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%102 = call i64 @strlen(i8* %101)
%103 = icmp eq i64 %102, 0
br i1 %103, label %104, label %105
104: ; preds = %97
br label %285
105: ; preds = %97
%106 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%107 = load i8, i8* %106
%108 = sext i8 %107 to i32
%109 = icmp eq i32 %108, 115
br i1 %109, label %110, label %137
110: ; preds = %105
%111 = load i32, i32* %8
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %110
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %115
115: ; preds = %113, %110
%116 = call i64 (...) @get_time()
store i64 %116, i64* %27
%117 = load void (...)*, void (...)** %7
%118 = icmp ne void (...)* %117, null
br i1 %118, label %119, label %121
119: ; preds = %115
%120 = load void (...)*, void (...)** %7
br label %121
121: ; preds = %119, %115
%122 = call i64 (...) @get_time()
%123 = load i64, i64* %27
%124 = sub nsw i64 %122, %123
store i64 %124, i64* %27
%125 = load i64, i64* %27
%126 = load i64, i64* %18
%127 = add nsw i64 %126, %125
store i64 %127, i64* %18
%128 = load i32, i32* %8
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %134
130: ; preds = %121
%131 = load i64, i64* %27
%132 = trunc i64 %131 to i32
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %132)
br label %134
134: ; preds = %130, %121
%135 = load i32, i32* %22
%136 = add nsw i32 %135, 1
store i32 %136, i32* %22
br label %284
137: ; preds = %105
%138 = load i8*, i8** %25
%139 = load i8, i8* %138
%140 = sext i8 %139 to i32
%141 = icmp eq i32 %140, 61
br i1 %141, label %142, label %145
142: ; preds = %137
%143 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%144 = call i32 @atoi(i8* %143)
store i32 %144, i32* %13
br label %283
145: ; preds = %137
%146 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%147 = call i32 @atoi(i8* %146)
store i32 %147, i32* %14
%148 = load i32, i32* %13
%149 = icmp eq i32 %148, -1
br i1 %149, label %150, label %193
150: ; preds = %145
%151 = load i32, i32* %14
store i32 %151, i32* %13
%152 = load i8**, i8*** %12
%153 = load i32, i32* %13
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds i8*, i8** %152, i64 %154
store i8** %155, i8*** %28
%156 = load i32, i32* %8
%157 = icmp ne i32 %156, 0
br i1 %157, label %158, label %163
158: ; preds = %150
%159 = load i32, i32* %13
%160 = load i8**, i8*** %28
%161 = load i8*, i8** %160
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %159, i8* %161)
br label %163
163: ; preds = %158, %150
%164 = call i64 (...) @get_time()
store i64 %164, i64* %29
%165 = load i8**, i8*** %28
%166 = load i8*, i8** %165
%167 = call i32 @free(i8* %166)
%168 = call i64 (...) @get_time()
%169 = load i64, i64* %29
%170 = sub nsw i64 %168, %169
store i64 %170, i64* %29
%171 = load i64, i64* %29
%172 = load i64, i64* %17
%173 = add nsw i64 %172, %171
store i64 %173, i64* %17
%174 = load i64, i64* @errno
%175 = icmp sgt i64 %174, 0
br i1 %175, label %176, label %181
176: ; preds = %163
%177 = load i32, i32* @stderr
%178 = load i64, i64* @errno
%179 = call i8* @strerror(i64 %178)
%180 = call i32 @fprintf(i32 %177, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %179)
br label %181
181: ; preds = %176, %163
%182 = load i8**, i8*** %28
store i8* null, i8** %182
%183 = load i32, i32* %8
%184 = icmp ne i32 %183, 0
br i1 %184, label %185, label %190
185: ; preds = %181
%186 = load i32, i32* %13
%187 = load i64, i64* %29
%188 = trunc i64 %187 to i32
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %186, i32 %188)
br label %190
190: ; preds = %185, %181
%191 = load i32, i32* %21
%192 = add nsw i32 %191, 1
store i32 %192, i32* %21
br label %282
193: ; preds = %145
%194 = load i8**, i8*** %12
%195 = load i32, i32* %13
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds i8*, i8** %194, i64 %196
store i8** %197, i8*** %30
%198 = load i8**, i8*** %30
%199 = load i8*, i8** %198
%200 = icmp eq i8* %199, null
br i1 %200, label %201, label %240
201: ; preds = %193
%202 = load i32, i32* %8
%203 = icmp ne i32 %202, 0
br i1 %203, label %204, label %208
204: ; preds = %201
%205 = load i32, i32* %13
%206 = load i32, i32* %14
%207 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %205, i32 %206)
br label %208
208: ; preds = %204, %201
%209 = call i64 (...) @get_time()
store i64 %209, i64* %31
%210 = load i32, i32* %14
%211 = call i8* @malloc(i32 %210)
%212 = load i8**, i8*** %30
store i8* %211, i8** %212
%213 = call i64 (...) @get_time()
%214 = load i64, i64* %31
%215 = sub nsw i64 %213, %214
store i64 %215, i64* %31
%216 = load i64, i64* %31
%217 = load i64, i64* %15
%218 = add nsw i64 %217, %216
store i64 %218, i64* %15
%219 = load i64, i64* @errno
%220 = icmp sgt i64 %219, 0
br i1 %220, label %221, label %226
221: ; preds = %208
%222 = load i32, i32* @stderr
%223 = load i64, i64* @errno
%224 = call i8* @strerror(i64 %223)
%225 = call i32 @fprintf(i32 %222, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %224)
br label %226
226: ; preds = %221, %208
%227 = load i32, i32* %8
%228 = icmp ne i32 %227, 0
br i1 %228, label %229, label %237
229: ; preds = %226
%230 = load i32, i32* %13
%231 = load i32, i32* %14
%232 = load i8**, i8*** %30
%233 = load i8*, i8** %232
%234 = load i64, i64* %31
%235 = trunc i64 %234 to i32
%236 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.7, i64 0, i64 0), i32 %230, i32 %231, i8* %233, i32 %235)
br label %237
237: ; preds = %229, %226
%238 = load i32, i32* %19
%239 = add nsw i32 %238, 1
store i32 %239, i32* %19
br label %281
240: ; preds = %193
%241 = load i32, i32* %8
%242 = icmp ne i32 %241, 0
br i1 %242, label %243, label %247
243: ; preds = %240
%244 = load i32, i32* %13
%245 = load i32, i32* %14
%246 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i32 %244, i32 %245)
br label %247
247: ; preds = %243, %240
%248 = call i64 (...) @get_time()
store i64 %248, i64* %32
%249 = load i8**, i8*** %30
%250 = load i8*, i8** %249
%251 = load i32, i32* %14
%252 = call i8* @realloc(i8* %250, i32 %251)
%253 = load i8**, i8*** %30
store i8* %252, i8** %253
%254 = call i64 (...) @get_time()
%255 = load i64, i64* %32
%256 = sub nsw i64 %254, %255
store i64 %256, i64* %32
%257 = load i64, i64* %32
%258 = load i64, i64* %16
%259 = add nsw i64 %258, %257
store i64 %259, i64* %16
%260 = load i64, i64* @errno
%261 = icmp sgt i64 %260, 0
br i1 %261, label %262, label %267
262: ; preds = %247
%263 = load i32, i32* @stderr
%264 = load i64, i64* @errno
%265 = call i8* @strerror(i64 %264)
%266 = call i32 @fprintf(i32 %263, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %265)
br label %267
267: ; preds = %262, %247
%268 = load i32, i32* %8
%269 = icmp ne i32 %268, 0
br i1 %269, label %270, label %278
270: ; preds = %267
%271 = load i32, i32* %13
%272 = load i32, i32* %14
%273 = load i8**, i8*** %30
%274 = load i8*, i8** %273
%275 = load i64, i64* %32
%276 = trunc i64 %275 to i32
%277 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.9, i64 0, i64 0), i32 %271, i32 %272, i8* %274, i32 %276)
br label %278
278: ; preds = %270, %267
%279 = load i32, i32* %20
%280 = add nsw i32 %279, 1
store i32 %280, i32* %20
br label %281
281: ; preds = %278, %237
br label %282
282: ; preds = %281, %190
store i32 -1, i32* %13
store i32 0, i32* %14
br label %283
283: ; preds = %282, %142
br label %284
284: ; preds = %283, %134
br label %285
285: ; preds = %284, %104
br label %294
286: ; preds = %92
%287 = load i8*, i8** %25
%288 = load i8, i8* %287
%289 = load i32, i32* %24
%290 = sext i32 %289 to i64
%291 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 %290
store i8 %288, i8* %291
%292 = load i32, i32* %24
%293 = add nsw i32 %292, 1
store i32 %293, i32* %24
br label %294
294: ; preds = %286, %285
%295 = load i8*, i8** %25
%296 = getelementptr inbounds i8, i8* %295, i32 1
store i8* %296, i8** %25
%297 = load i32, i32* %26
%298 = add nsw i32 %297, 1
store i32 %298, i32* %26
br label %61
299: ; preds = %70, %61
br label %54
300: ; preds = %54
%301 = load i32, i32* %6
%302 = icmp ne i32 %301, 0
br i1 %302, label %320, label %303
303: ; preds = %300
%304 = load i32, i32* %19
%305 = load i64, i64* %15
%306 = trunc i64 %305 to i32
%307 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %304, i32 %306)
%308 = load i32, i32* %20
%309 = load i64, i64* %16
%310 = trunc i64 %309 to i32
%311 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0), i32 %308, i32 %310)
%312 = load i32, i32* %21
%313 = load i64, i64* %17
%314 = trunc i64 %313 to i32
%315 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 %312, i32 %314)
%316 = load i32, i32* %22
%317 = load i64, i64* %18
%318 = trunc i64 %317 to i32
%319 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i32 %316, i32 %318)
br label %320
320: ; preds = %303, %300
%321 = load i32, i32* %9
%322 = call i32 @close(i32 %321)
br label %323
323: ; preds = %320, %76, %38
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"couldn't open %s\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@errno = global i64 0
@.str.3 = [35 x i8] c"stats function called took %ums ]\0A\00"
@.str.4 = [33 x i8] c"free memory at %d with ptr %p [\0A\00"
@.str.5 = [32 x i8] c"memory freed at %d took %ums ]\0A\00"
@.str.6 = [40 x i8] c"allocating memory at %d with %d size [\0A\00"
@.str.7 = [61 x i8] c"memory allocated at %d with %d size with ptr %p took %ums ]\0A\00"
@.str.8 = [42 x i8] c"reallocating memory at %d with %d size [\0A\00"
@.str.9 = [63 x i8] c"memory reallocated at %d with %d size with ptr %p took %ums ]\0A\00"
@.str.10 = [27 x i8] c"malloc %d calls took %ums\0A\00"
@.str.11 = [28 x i8] c"realloc %d calls took %ums\0A\00"
@.str.12 = [25 x i8] c"free %d calls took %ums\0A\00"
@.str.13 = [26 x i8] c"stats %d calls took %ums\0A\00"
@str = [25 x i8] c"calling stats function [\00"
define void @run_memsim(i8* %0, i32 %1, void (...)* %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = alloca [80 x i8]
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %0, i32 %7)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %8, -1
br i1 %11, label %12, label %19
12: ; preds = %4
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
%15 = load i32, i32* @stderr
%16 = load i64, i64* @errno
%17 = tail call i8* @strerror(i64 %16)
%18 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %210
19: ; preds = %4
%20 = icmp eq i32 %1, 0
%21 = tail call i8** @alloca(i32 32768)
%22 = tail call i32 @memset(i8** %21, i32 0, i32 32768)
%23 = call i32 @read(i32 %8, i8* %9, i32 256)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %190
25: ; preds = %19
%26 = icmp ne i32 %3, 0
%27 = and i1 %20, %26
%28 = icmp eq void (...)* %2, null
br label %42
29: ; preds = %173, %42
%30 = phi i32 [ %53, %42 ], [ %174, %173 ]
%31 = phi i64 [ %52, %42 ], [ %175, %173 ]
%32 = phi i64 [ %51, %42 ], [ %176, %173 ]
%33 = phi i64 [ %50, %42 ], [ %177, %173 ]
%34 = phi i64 [ %49, %42 ], [ %178, %173 ]
%35 = phi i32 [ %48, %42 ], [ %179, %173 ]
%36 = phi i32 [ %47, %42 ], [ %180, %173 ]
%37 = phi i32 [ %46, %42 ], [ %181, %173 ]
%38 = phi i32 [ %45, %42 ], [ %182, %173 ]
%39 = phi i32 [ %44, %42 ], [ %183, %173 ]
%40 = call i32 @read(i32 %8, i8* %9, i32 256)
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %190
42: ; preds = %25, %29
%43 = phi i32 [ %23, %25 ], [ %40, %29 ]
%44 = phi i32 [ 0, %25 ], [ %39, %29 ]
%45 = phi i32 [ 0, %25 ], [ %38, %29 ]
%46 = phi i32 [ 0, %25 ], [ %37, %29 ]
%47 = phi i32 [ 0, %25 ], [ %36, %29 ]
%48 = phi i32 [ 0, %25 ], [ %35, %29 ]
%49 = phi i64 [ 0, %25 ], [ %34, %29 ]
%50 = phi i64 [ 0, %25 ], [ %33, %29 ]
%51 = phi i64 [ 0, %25 ], [ %32, %29 ]
%52 = phi i64 [ 0, %25 ], [ %31, %29 ]
%53 = phi i32 [ -1, %25 ], [ %30, %29 ]
%54 = load i8, i8* %9
%55 = icmp eq i8 %54, 0
br i1 %55, label %29, label %56
56: ; preds = %42, %173
%57 = phi i8 [ %186, %173 ], [ %54, %42 ]
%58 = phi i32 [ %185, %173 ], [ 0, %42 ]
%59 = phi i8* [ %184, %173 ], [ %9, %42 ]
%60 = phi i32 [ %183, %173 ], [ %44, %42 ]
%61 = phi i32 [ %182, %173 ], [ %45, %42 ]
%62 = phi i32 [ %181, %173 ], [ %46, %42 ]
%63 = phi i32 [ %180, %173 ], [ %47, %42 ]
%64 = phi i32 [ %179, %173 ], [ %48, %42 ]
%65 = phi i64 [ %178, %173 ], [ %49, %42 ]
%66 = phi i64 [ %177, %173 ], [ %50, %42 ]
%67 = phi i64 [ %176, %173 ], [ %51, %42 ]
%68 = phi i64 [ %175, %173 ], [ %52, %42 ]
%69 = phi i32 [ %174, %173 ], [ %53, %42 ]
switch i8 %57, label %169 [
i8 101, label %210
i8 32, label %70
i8 10, label %70
i8 61, label %70
]
70: ; preds = %56, %56, %56
%71 = sext i32 %60 to i64
%72 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 %71
store i8 0, i8* %72
%73 = load i8, i8* %10
switch i8 %73, label %89 [
i8 0, label %173
i8 115, label %74
]
74: ; preds = %70
br i1 %27, label %75, label %77
75: ; preds = %74
%76 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %77
77: ; preds = %75, %74
%78 = tail call i64 (...) @get_time()
br i1 %28, label %80, label %79
79: ; preds = %77
tail call void (...) %2()
br label %80
80: ; preds = %79, %77
%81 = tail call i64 (...) @get_time()
%82 = sub nsw i64 %81, %78
%83 = add nsw i64 %82, %65
br i1 %27, label %84, label %87
84: ; preds = %80
%85 = trunc i64 %82 to i32
%86 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %85)
br label %87
87: ; preds = %84, %80
%88 = add nsw i32 %61, 1
br label %173
89: ; preds = %70
%90 = icmp eq i8 %57, 61
%91 = call i32 @atoi(i8* %10)
br i1 %90, label %173, label %92
92: ; preds = %89
%93 = icmp eq i32 %69, -1
br i1 %93, label %94, label %119
94: ; preds = %92
%95 = sext i32 %91 to i64
%96 = getelementptr inbounds i8*, i8** %21, i64 %95
br i1 %27, label %97, label %100
97: ; preds = %94
%98 = load i8*, i8** %96
%99 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %91, i8* %98)
br label %100
100: ; preds = %97, %94
%101 = tail call i64 (...) @get_time()
%102 = load i8*, i8** %96
%103 = tail call i32 @free(i8* %102)
%104 = tail call i64 (...) @get_time()
%105 = sub nsw i64 %104, %101
%106 = add nsw i64 %105, %66
%107 = load i64, i64* @errno
%108 = icmp sgt i64 %107, 0
br i1 %108, label %109, label %113
109: ; preds = %100
%110 = load i32, i32* @stderr
%111 = tail call i8* @strerror(i64 %107)
%112 = tail call i32 @fprintf(i32 %110, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %111)
br label %113
113: ; preds = %109, %100
store i8* null, i8** %96
br i1 %27, label %114, label %117
114: ; preds = %113
%115 = trunc i64 %105 to i32
%116 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %91, i32 %115)
br label %117
117: ; preds = %114, %113
%118 = add nsw i32 %62, 1
br label %173
119: ; preds = %92
%120 = sext i32 %69 to i64
%121 = getelementptr inbounds i8*, i8** %21, i64 %120
%122 = load i8*, i8** %121
%123 = icmp eq i8* %122, null
br i1 %123, label %124, label %146
124: ; preds = %119
br i1 %27, label %125, label %127
125: ; preds = %124
%126 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %69, i32 %91)
br label %127
127: ; preds = %125, %124
%128 = tail call i64 (...) @get_time()
%129 = tail call i8* @malloc(i32 %91)
store i8* %129, i8** %121
%130 = tail call i64 (...) @get_time()
%131 = sub nsw i64 %130, %128
%132 = add nsw i64 %131, %68
%133 = load i64, i64* @errno
%134 = icmp sgt i64 %133, 0
br i1 %134, label %135, label %139
135: ; preds = %127
%136 = load i32, i32* @stderr
%137 = tail call i8* @strerror(i64 %133)
%138 = tail call i32 @fprintf(i32 %136, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %137)
br label %139
139: ; preds = %135, %127
br i1 %27, label %140, label %144
140: ; preds = %139
%141 = load i8*, i8** %121
%142 = trunc i64 %131 to i32
%143 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.7, i64 0, i64 0), i32 %69, i32 %91, i8* %141, i32 %142)
br label %144
144: ; preds = %140, %139
%145 = add nsw i32 %64, 1
br label %173
146: ; preds = %119
br i1 %27, label %147, label %149
147: ; preds = %146
%148 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0), i32 %69, i32 %91)
br label %149
149: ; preds = %147, %146
%150 = tail call i64 (...) @get_time()
%151 = load i8*, i8** %121
%152 = tail call i8* @realloc(i8* %151, i32 %91)
store i8* %152, i8** %121
%153 = tail call i64 (...) @get_time()
%154 = sub nsw i64 %153, %150
%155 = add nsw i64 %154, %67
%156 = load i64, i64* @errno
%157 = icmp sgt i64 %156, 0
br i1 %157, label %158, label %162
158: ; preds = %149
%159 = load i32, i32* @stderr
%160 = tail call i8* @strerror(i64 %156)
%161 = tail call i32 @fprintf(i32 %159, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %160)
br label %162
162: ; preds = %158, %149
br i1 %27, label %163, label %167
163: ; preds = %162
%164 = load i8*, i8** %121
%165 = trunc i64 %154 to i32
%166 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.9, i64 0, i64 0), i32 %69, i32 %91, i8* %164, i32 %165)
br label %167
167: ; preds = %163, %162
%168 = add nsw i32 %63, 1
br label %173
169: ; preds = %56
%170 = sext i32 %60 to i64
%171 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 %170
store i8 %57, i8* %171
%172 = add nsw i32 %60, 1
br label %173
173: ; preds = %89, %70, %117, %167, %144, %87, %169
%174 = phi i32 [ %69, %70 ], [ %69, %87 ], [ %69, %169 ], [ -1, %144 ], [ -1, %167 ], [ -1, %117 ], [ %91, %89 ]
%175 = phi i64 [ %68, %70 ], [ %68, %87 ], [ %68, %169 ], [ %132, %144 ], [ %68, %167 ], [ %68, %117 ], [ %68, %89 ]
%176 = phi i64 [ %67, %70 ], [ %67, %87 ], [ %67, %169 ], [ %67, %144 ], [ %155, %167 ], [ %67, %117 ], [ %67, %89 ]
%177 = phi i64 [ %66, %70 ], [ %66, %87 ], [ %66, %169 ], [ %66, %144 ], [ %66, %167 ], [ %106, %117 ], [ %66, %89 ]
%178 = phi i64 [ %65, %70 ], [ %83, %87 ], [ %65, %169 ], [ %65, %144 ], [ %65, %167 ], [ %65, %117 ], [ %65, %89 ]
%179 = phi i32 [ %64, %70 ], [ %64, %87 ], [ %64, %169 ], [ %145, %144 ], [ %64, %167 ], [ %64, %117 ], [ %64, %89 ]
%180 = phi i32 [ %63, %70 ], [ %63, %87 ], [ %63, %169 ], [ %63, %144 ], [ %168, %167 ], [ %63, %117 ], [ %63, %89 ]
%181 = phi i32 [ %62, %70 ], [ %62, %87 ], [ %62, %169 ], [ %62, %144 ], [ %62, %167 ], [ %118, %117 ], [ %62, %89 ]
%182 = phi i32 [ %61, %70 ], [ %88, %87 ], [ %61, %169 ], [ %61, %144 ], [ %61, %167 ], [ %61, %117 ], [ %61, %89 ]
%183 = phi i32 [ 0, %70 ], [ 0, %87 ], [ %172, %169 ], [ 0, %144 ], [ 0, %167 ], [ 0, %117 ], [ 0, %89 ]
%184 = getelementptr inbounds i8, i8* %59, i64 1
%185 = add nuw nsw i32 %58, 1
%186 = load i8, i8* %184
%187 = icmp eq i8 %186, 0
%188 = icmp eq i32 %43, %185
%189 = select i1 %187, i1 true, i1 %188
br i1 %189, label %29, label %56
190: ; preds = %29, %19
%191 = phi i64 [ 0, %19 ], [ %31, %29 ]
%192 = phi i64 [ 0, %19 ], [ %32, %29 ]
%193 = phi i64 [ 0, %19 ], [ %33, %29 ]
%194 = phi i64 [ 0, %19 ], [ %34, %29 ]
%195 = phi i32 [ 0, %19 ], [ %35, %29 ]
%196 = phi i32 [ 0, %19 ], [ %36, %29 ]
%197 = phi i32 [ 0, %19 ], [ %37, %29 ]
%198 = phi i32 [ 0, %19 ], [ %38, %29 ]
br i1 %20, label %199, label %208
199: ; preds = %190
%200 = trunc i64 %191 to i32
%201 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %195, i32 %200)
%202 = trunc i64 %192 to i32
%203 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0), i32 %196, i32 %202)
%204 = trunc i64 %193 to i32
%205 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0), i32 %197, i32 %204)
%206 = trunc i64 %194 to i32
%207 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i32 %198, i32 %206)
br label %208
208: ; preds = %199, %190
%209 = tail call i32 @close(i32 %8)
br label %210
210: ; preds = %56, %208, %12
ret void
}