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

/* Variables and functions */
void *atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ memset(void **, int /*<<< orphan*/, int);
char *optarg;
int /*<<< orphan*/ printf(char *, ...);
size_t rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc == 1) {
    printf("./genrandms [-m 32[kmg]b] [-M 16[kmg]b] [-c 128] [-p 16] "
           "filename.ms - malloc memory random simulation generator\n");
    return 1;
  }
  size_t min_size = 32;
  size_t max_size = 16 * 1024 * 1024;
  uint32_t allocs = 128;
  uint32_t ptrs = 16;
  int c;
  int sl;
  size_t s;
  while ((c = getopt(argc, argv, "m:M:c:p:")) != -1) {
    switch (c) {
    case 'c':
      allocs = atoi(optarg);
      break;
    case 'p':
      ptrs = atoi(optarg);
      break;
    case 'm':
      sl = strlen(optarg);
      s = atoi(optarg);
      if (optarg[sl - 2] == 'k')
        s *= 1024;
      if (optarg[sl - 2] == 'm')
        s *= 1024 * 1024;
      if (optarg[sl - 2] == 'g')
        s *= 1024 * 1024 * 1024;
      min_size = s;
      break;
    case 'M':
      sl = strlen(optarg);
      s = atoi(optarg);
      if (optarg[sl - 2] == 'k')
        s *= 1024;
      if (optarg[sl - 2] == 'm')
        s *= 1024 * 1024;
      if (optarg[sl - 2] == 'g')
        s *= 1024 * 1024 * 1024;
      max_size = s;
      break;
    default:
      break;
    }
  }
  printf("generating min=%d bytes max=%d bytes %d allocations over %d pointers "
         "into %s\n",
         min_size, max_size, allocs, ptrs, argv[argc - 1]);
  if (min_size < 0 || max_size < 0) {
    printf("min size or max size can't be negative\naborting generation\n");
    return 1;
  }
  if (min_size == 0 || max_size == 0) {
    printf("min size or max size can't be 0\naborting generation\n");
    return 1;
  }
  if (min_size > max_size) {
    printf("min size can't be greater than max size\naborting generation\n");
    return 1;
  }
  srand(time(NULL));
  FILE *f = fopen(argv[argc - 1], "w+");
  void *ptr[4096];
  memset(ptr, 0, 4096 * sizeof(void *));
  for (uint32_t i = 0; i < allocs; ++i) {
    int r = (rand() % (max_size - min_size + 1)) + min_size;
    int ppos = r % ptrs;
    if (ptr[ppos] == 0) {
      fprintf(f, "%d=%d", ppos, r);
      ptr[ppos] = (void *)r;
    } else {
      if (r % 2 == 0) {
        fprintf(f, "%d=%d", ppos, r);
        ptr[ppos] = (void *)r;
      } else {
        fprintf(f, "%d", ppos);
        ptr[ppos] = 0;
      }
    }
    if (i % 8 == 0)
      fprintf(f, "\n");
    else
      fprintf(f, " ");
  }
  for (int i = 0; i < 4096; ++i) {
    if (ptr[i] != 0) {
      fprintf(f, "%d", i);
      if (i % 8 == 0)
        fprintf(f, "\n");
      else
        fprintf(f, " ");
    }
  }
  fprintf(f, "\n");
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8060,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11ed <main+0x3d>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1734 <main+0x584>
movq   $0x20,-0x18(%rbp)
movq   $0x1000000,-0x20(%rbp)
01
movl   $0x80,-0x24(%rbp)
movl   $0x10,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xee9(%rip),%rdx
call   10b0 <getopt@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     13fd <main+0x24d>
mov    -0x2c(%rbp),%eax
add    $0xffffffb3,%eax
mov    %eax,%ecx
mov    %rcx,-0x8058(%rbp)
sub    $0x23,%eax
ja     13f3 <main+0x243>
mov    -0x8058(%rbp),%rax
lea    0xdb0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2d98(%rip),%rax
mov    (%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    13f8 <main+0x248>
mov    0x2d81(%rip),%rax
mov    (%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    13f8 <main+0x248>
mov    0x2d6a(%rip),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    0x2d58(%rip),%rax
mov    (%rax),%rdi
call   10c0 <atoi@plt>
mov    %rax,-0x38(%rbp)
mov    0x2d45(%rip),%rax
mov    (%rax),%rax
mov    -0x30(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6b,%eax
jne    12d8 <main+0x128>
mov    -0x38(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x38(%rbp)
mov    0x2d19(%rip),%rax
mov    (%rax),%rax
mov    -0x30(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6d,%eax
jne    1304 <main+0x154>
mov    -0x38(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x38(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%rax
mov    -0x30(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x67,%eax
jne    1330 <main+0x180>
mov    -0x38(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    13f8 <main+0x248>
mov    0x2cb4(%rip),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    0x2ca2(%rip),%rax
mov    (%rax),%rdi
call   10c0 <atoi@plt>
mov    %rax,-0x38(%rbp)
mov    0x2c8f(%rip),%rax
mov    (%rax),%rax
mov    -0x30(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6b,%eax
jne    138e <main+0x1de>
mov    -0x38(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x38(%rbp)
mov    0x2c63(%rip),%rax
mov    (%rax),%rax
mov    -0x30(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6d,%eax
jne    13ba <main+0x20a>
mov    -0x38(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x38(%rbp)
mov    0x2c37(%rip),%rax
mov    (%rax),%rax
mov    -0x30(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x67,%eax
jne    13e6 <main+0x236>
mov    -0x38(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    13f8 <main+0x248>
jmp    13f8 <main+0x248>
jmp    120b <main+0x5b>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
movslq %edi,%rdi
mov    (%rax,%rdi,8),%r9
lea    0xce7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
jb     1441 <main+0x291>
cmpq   $0x0,-0x20(%rbp)
jae    145b <main+0x2ab>
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1734 <main+0x584>
cmpq   $0x0,-0x18(%rbp)
je     1471 <main+0x2c1>
cmpq   $0x0,-0x20(%rbp)
jne    148b <main+0x2db>
lea    0xd1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1734 <main+0x584>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    14b3 <main+0x303>
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1734 <main+0x584>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd2c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x40(%rbp)
lea    -0x8040(%rbp),%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1060 <memset@plt>
movl   $0x0,-0x8044(%rbp)
mov    -0x8044(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    166c <main+0x4bc>
mov    $0x0,%al
call   10d0 <rand@plt>
mov    -0x20(%rbp),%rcx
sub    -0x18(%rbp),%rcx
add    $0x1,%rcx
xor    %edx,%edx
div    %rcx
add    -0x18(%rbp),%rdx
mov    %edx,%eax
mov    %eax,-0x8048(%rbp)
mov    -0x8048(%rbp),%eax
cltd
idivl  -0x28(%rbp)
mov    %edx,-0x804c(%rbp)
movslq -0x804c(%rbp),%rax
cmpq   $0x0,-0x8040(%rbp,%rax,8)
jne    1593 <main+0x3e3>
mov    -0x40(%rbp),%rdi
mov    -0x804c(%rbp),%edx
mov    -0x8048(%rbp),%ecx
lea    0xc99(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movslq -0x8048(%rbp),%rcx
movslq -0x804c(%rbp),%rax
mov    %rcx,-0x8040(%rbp,%rax,8)
ff
jmp    1613 <main+0x463>
mov    -0x8048(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    15e3 <main+0x433>
mov    -0x40(%rbp),%rdi
mov    -0x804c(%rbp),%edx
mov    -0x8048(%rbp),%ecx
lea    0xc49(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movslq -0x8048(%rbp),%rcx
movslq -0x804c(%rbp),%rax
mov    %rcx,-0x8040(%rbp,%rax,8)
ff
jmp    160e <main+0x45e>
mov    -0x40(%rbp),%rdi
mov    -0x804c(%rbp),%edx
lea    0xc19(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movslq -0x804c(%rbp),%rax
movq   $0x0,-0x8040(%rbp,%rax,8)
jmp    1613 <main+0x463>
mov    -0x8044(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1641 <main+0x491>
mov    -0x40(%rbp),%rdi
lea    0xb93(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1653 <main+0x4a3>
mov    -0x40(%rbp),%rdi
lea    0xbc4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1658 <main+0x4a8>
mov    -0x8044(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8044(%rbp)
jmp    1501 <main+0x351>
movl   $0x0,-0x8050(%rbp)
cmpl   $0x1000,-0x8050(%rbp)
jge    1712 <main+0x562>
movslq -0x8050(%rbp),%rax
cmpq   $0x0,-0x8040(%rbp,%rax,8)
je     16f9 <main+0x549>
mov    -0x40(%rbp),%rdi
mov    -0x8050(%rbp),%edx
lea    0xb60(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x8050(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    16e2 <main+0x532>
mov    -0x40(%rbp),%rdi
lea    0xaf2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    16f4 <main+0x544>
mov    -0x40(%rbp),%rdi
lea    0xb23(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    16f9 <main+0x549>
jmp    16fe <main+0x54e>
mov    -0x8050(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8050(%rbp)
jmp    1676 <main+0x4c6>
mov    -0x40(%rbp),%rdi
lea    0xaab(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8028,%rsp
cmp    $0x1,%edi
jne    11f2 <main+0x22>
lea    0xf73(%rip),%rdi
jmp    138c <main+0x1bc>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x20,%r15d
mov    $0x1000000,%eax
mov    %rax,0x10(%rsp)
mov    $0x80,%eax
mov    %rax,(%rsp)
mov    $0x10,%eax
mov    %rax,0x8(%rsp)
lea    0xe6f(%rip),%r14
lea    0xdd8(%rip),%r12
jmp    1239 <main+0x69>
nopw   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     1343 <main+0x173>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10d0 <getopt@plt>
lea    -0x4d(%rax),%ecx
cmp    $0x23,%ecx
ja     1230 <main+0x60>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
mov    0x2d9a(%rip),%r13
mov    0x0(%r13),%rdi
call   1050 <strlen@plt>
mov    %r15,0x18(%rsp)
mov    %eax,%r15d
mov    0x0(%r13),%r13
mov    %r13,%rdi
call   10e0 <atoi@plt>
movslq %r15d,%rcx
mov    0x18(%rsp),%r15
movzbl -0x2(%rcx,%r13,1),%ecx
mov    %rax,%rdx
shl    $0xa,%rdx
cmp    $0x6b,%cl
cmovne %rax,%rdx
mov    %rdx,%rax
shl    $0x14,%rax
cmp    $0x6d,%cl
cmovne %rdx,%rax
mov    %rax,%rdx
shl    $0x1e,%rdx
cmp    $0x67,%cl
cmovne %rax,%rdx
mov    %rdx,0x10(%rsp)
jmp    1239 <main+0x69>
mov    0x2d34(%rip),%rax
mov    (%rax),%rdi
call   10e0 <atoi@plt>
mov    %rax,(%rsp)
jmp    1239 <main+0x69>
mov    0x2d1c(%rip),%r15
mov    (%r15),%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    (%r15),%r15
mov    %r15,%rdi
call   10e0 <atoi@plt>
movslq %r13d,%rcx
movzbl -0x2(%rcx,%r15,1),%ecx
mov    %rax,%rdx
shl    $0xa,%rdx
cmp    $0x6b,%cl
cmovne %rax,%rdx
mov    %rdx,%rax
shl    $0x14,%rax
cmp    $0x6d,%cl
cmovne %rdx,%rax
mov    %rax,%r15
shl    $0x1e,%r15
cmp    $0x67,%cl
cmovne %rax,%r15
jmp    1239 <main+0x69>
mov    0x2cc7(%rip),%rax
mov    (%rax),%rdi
call   10e0 <atoi@plt>
mov    %rax,0x8(%rsp)
jmp    1239 <main+0x69>
movslq %ebp,%rbp
mov    -0x8(%rbx,%rbp,8),%r9
lea    0xd47(%rip),%rdi
mov    %r15,%rsi
mov    0x10(%rsp),%r14
mov    %r14,%rdx
mov    (%rsp),%rcx
mov    0x8(%rsp),%r8
xor    %eax,%eax
call   1060 <printf@plt>
test   %r15,%r15
je     1385 <main+0x1b5>
test   %r14,%r14
je     1385 <main+0x1b5>
sub    %r15,%r14
jae    13a8 <main+0x1d8>
lea    0xd6d(%rip),%rdi
jmp    138c <main+0x1bc>
lea    0xda0(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xffffffffffffffff,%rbp
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
mov    (%rbx,%rbp,8),%rdi
lea    0xd22(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r13
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1070 <memset@plt>
cmpl   $0x0,(%rsp)
jle    14a0 <main+0x2d0>
add    $0x1,%r14
xor    %ebp,%ebp
mov    %r14,%r12
jmp    1440 <main+0x270>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
lea    0xce0(%rip),%rsi
mov    %r14d,%ecx
xor    %eax,%eax
call   10a0 <fprintf@plt>
movslq %r14d,%rax
mov    %r12,%r14
mov    %rax,0x20(%rsp,%rbx,8)
test   $0x7,%bpl
mov    $0x20,%edi
mov    $0xa,%eax
cmove  %eax,%edi
mov    %r13,%rsi
call   1080 <fputc@plt>
add    $0x1,%ebp
cmp    %ebp,(%rsp)
je     14a0 <main+0x2d0>
xor    %eax,%eax
call   10f0 <rand@plt>
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
je     1460 <main+0x290>
xor    %edx,%edx
div    %r14
mov    %rdx,%r14
jmp    1468 <main+0x298>
nopl   (%rax)
xor    %edx,%edx
div    %r14d
mov    %edx,%r14d
add    %r15,%r14
mov    %r14d,%eax
cltd
idivl  0x8(%rsp)
movslq %edx,%rbx
cmpq   $0x0,0x20(%rsp,%rbx,8)
je     1400 <main+0x230>
test   $0x1,%r14b
je     1400 <main+0x230>
mov    %r13,%rdi
lea    0xc5b(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
xor    %eax,%eax
jmp    1417 <main+0x247>
lea    0xc46(%rip),%r14
mov    $0xa,%ebx
xor    %ebp,%ebp
jmp    14bd <main+0x2ed>
add    $0x1,%rbp
cmp    $0x1000,%rbp
je     14ea <main+0x31a>
cmpq   $0x0,0x20(%rsp,%rbp,8)
je     14b0 <main+0x2e0>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
test   $0x7,%bpl
mov    $0x20,%edi
cmove  %ebx,%edi
mov    %r13,%rsi
call   1080 <fputc@plt>
jmp    14b0 <main+0x2e0>
mov    $0xa,%edi
mov    %r13,%rsi
call   1080 <fputc@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1396 <main+0x1c6>

LLVM IR (-O0):
@.str = [114 x i8] c"./genrandms [-m 32[kmg]b] [-M 16[kmg]b] [-c 128] [-p 16] filename.ms - malloc memory random simulation generator\0A\00"
@.str.1 = [9 x i8] c"m:M:c:p:\00"
@optarg = global i8* null
@.str.2 = [78 x i8] c"generating min=%d bytes max=%d bytes %d allocations over %d pointers into %s\0A\00"
@.str.3 = [60 x i8] c"min size or max size can't be negative\0Aaborting generation\0A\00"
@.str.4 = [53 x i8] c"min size or max size can't be 0\0Aaborting generation\0A\00"
@.str.5 = [61 x i8] c"min size can't be greater than max size\0Aaborting generation\0A\00"
@.str.6 = [3 x i8] c"w+\00"
@.str.7 = [6 x i8] c"%d=%d\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i32*
%14 = alloca [4096 x i8*]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %275
23: ; preds = %2
store i64 32, i64* %6
store i64 16777216, i64* %7
store i32 128, i32* %8
store i32 16, i32* %9
br label %24
24: ; preds = %126, %23
%25 = load i32, i32* %4
%26 = load i8**, i8*** %5
%27 = call i32 @getopt(i32 %25, i8** %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 %27, i32* %10
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %127
29: ; preds = %24
%30 = load i32, i32* %10
switch i32 %30, label %125 [
i32 99, label %31
i32 112, label %35
i32 109, label %39
i32 77, label %82
]
31: ; preds = %29
%32 = load i8*, i8** @optarg
%33 = call i8* @atoi(i8* %32)
%34 = ptrtoint i8* %33 to i32
store i32 %34, i32* %8
br label %126
35: ; preds = %29
%36 = load i8*, i8** @optarg
%37 = call i8* @atoi(i8* %36)
%38 = ptrtoint i8* %37 to i32
store i32 %38, i32* %9
br label %126
39: ; preds = %29
%40 = load i8*, i8** @optarg
%41 = call i32 @strlen(i8* %40)
store i32 %41, i32* %11
%42 = load i8*, i8** @optarg
%43 = call i8* @atoi(i8* %42)
%44 = ptrtoint i8* %43 to i64
store i64 %44, i64* %12
%45 = load i8*, i8** @optarg
%46 = load i32, i32* %11
%47 = sub nsw i32 %46, 2
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 107
br i1 %52, label %53, label %56
53: ; preds = %39
%54 = load i64, i64* %12
%55 = mul i64 %54, 1024
store i64 %55, i64* %12
br label %56
56: ; preds = %53, %39
%57 = load i8*, i8** @optarg
%58 = load i32, i32* %11
%59 = sub nsw i32 %58, 2
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 109
br i1 %64, label %65, label %68
65: ; preds = %56
%66 = load i64, i64* %12
%67 = mul i64 %66, 1048576
store i64 %67, i64* %12
br label %68
68: ; preds = %65, %56
%69 = load i8*, i8** @optarg
%70 = load i32, i32* %11
%71 = sub nsw i32 %70, 2
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 103
br i1 %76, label %77, label %80
77: ; preds = %68
%78 = load i64, i64* %12
%79 = mul i64 %78, 1073741824
store i64 %79, i64* %12
br label %80
80: ; preds = %77, %68
%81 = load i64, i64* %12
store i64 %81, i64* %6
br label %126
82: ; preds = %29
%83 = load i8*, i8** @optarg
%84 = call i32 @strlen(i8* %83)
store i32 %84, i32* %11
%85 = load i8*, i8** @optarg
%86 = call i8* @atoi(i8* %85)
%87 = ptrtoint i8* %86 to i64
store i64 %87, i64* %12
%88 = load i8*, i8** @optarg
%89 = load i32, i32* %11
%90 = sub nsw i32 %89, 2
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %88, i64 %91
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = icmp eq i32 %94, 107
br i1 %95, label %96, label %99
96: ; preds = %82
%97 = load i64, i64* %12
%98 = mul i64 %97, 1024
store i64 %98, i64* %12
br label %99
99: ; preds = %96, %82
%100 = load i8*, i8** @optarg
%101 = load i32, i32* %11
%102 = sub nsw i32 %101, 2
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %100, i64 %103
%105 = load i8, i8* %104
%106 = sext i8 %105 to i32
%107 = icmp eq i32 %106, 109
br i1 %107, label %108, label %111
108: ; preds = %99
%109 = load i64, i64* %12
%110 = mul i64 %109, 1048576
store i64 %110, i64* %12
br label %111
111: ; preds = %108, %99
%112 = load i8*, i8** @optarg
%113 = load i32, i32* %11
%114 = sub nsw i32 %113, 2
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i8, i8* %112, i64 %115
%117 = load i8, i8* %116
%118 = sext i8 %117 to i32
%119 = icmp eq i32 %118, 103
br i1 %119, label %120, label %123
120: ; preds = %111
%121 = load i64, i64* %12
%122 = mul i64 %121, 1073741824
store i64 %122, i64* %12
br label %123
123: ; preds = %120, %111
%124 = load i64, i64* %12
store i64 %124, i64* %7
br label %126
125: ; preds = %29
br label %126
126: ; preds = %125, %123, %80, %35, %31
br label %24
127: ; preds = %24
%128 = load i64, i64* %6
%129 = load i64, i64* %7
%130 = load i32, i32* %8
%131 = load i32, i32* %9
%132 = load i8**, i8*** %5
%133 = load i32, i32* %4
%134 = sub nsw i32 %133, 1
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds i8*, i8** %132, i64 %135
%137 = load i8*, i8** %136
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0), i64 %128, i64 %129, i32 %130, i32 %131, i8* %137)
%139 = load i64, i64* %6
%140 = icmp ult i64 %139, 0
br i1 %140, label %144, label %141
141: ; preds = %127
%142 = load i64, i64* %7
%143 = icmp ult i64 %142, 0
br i1 %143, label %144, label %146
144: ; preds = %141, %127
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %275
146: ; preds = %141
%147 = load i64, i64* %6
%148 = icmp eq i64 %147, 0
br i1 %148, label %152, label %149
149: ; preds = %146
%150 = load i64, i64* %7
%151 = icmp eq i64 %150, 0
br i1 %151, label %152, label %154
152: ; preds = %149, %146
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %275
154: ; preds = %149
%155 = load i64, i64* %6
%156 = load i64, i64* %7
%157 = icmp ugt i64 %155, %156
br i1 %157, label %158, label %160
158: ; preds = %154
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %275
160: ; preds = %154
%161 = call i32 @time(i32* null)
%162 = call i32 @srand(i32 %161)
%163 = load i8**, i8*** %5
%164 = load i32, i32* %4
%165 = sub nsw i32 %164, 1
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds i8*, i8** %163, i64 %166
%168 = load i8*, i8** %167
%169 = call i32* @fopen(i8* %168, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %169, i32** %13
%170 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %14, i64 0, i64 0
%171 = call i32 @memset(i8** %170, i32 0, i32 32768)
store i32 0, i32* %15
br label %172
172: ; preds = %239, %160
%173 = load i32, i32* %15
%174 = load i32, i32* %8
%175 = icmp slt i32 %173, %174
br i1 %175, label %176, label %242
176: ; preds = %172
%177 = call i64 (...) @rand()
%178 = load i64, i64* %7
%179 = load i64, i64* %6
%180 = sub i64 %178, %179
%181 = add i64 %180, 1
%182 = urem i64 %177, %181
%183 = load i64, i64* %6
%184 = add i64 %182, %183
%185 = trunc i64 %184 to i32
store i32 %185, i32* %16
%186 = load i32, i32* %16
%187 = load i32, i32* %9
%188 = srem i32 %186, %187
store i32 %188, i32* %17
%189 = load i32, i32* %17
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %14, i64 0, i64 %190
%192 = load i8*, i8** %191
%193 = icmp eq i8* %192, null
br i1 %193, label %194, label %205
194: ; preds = %176
%195 = load i32*, i32** %13
%196 = load i32, i32* %17
%197 = load i32, i32* %16
%198 = call i32 (i32*, i8*, ...) @fprintf(i32* %195, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %196, i32 %197)
%199 = load i32, i32* %16
%200 = sext i32 %199 to i64
%201 = inttoptr i64 %200 to i8*
%202 = load i32, i32* %17
%203 = sext i32 %202 to i64
%204 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %14, i64 0, i64 %203
store i8* %201, i8** %204
br label %228
205: ; preds = %176
%206 = load i32, i32* %16
%207 = srem i32 %206, 2
%208 = icmp eq i32 %207, 0
br i1 %208, label %209, label %220
209: ; preds = %205
%210 = load i32*, i32** %13
%211 = load i32, i32* %17
%212 = load i32, i32* %16
%213 = call i32 (i32*, i8*, ...) @fprintf(i32* %210, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %211, i32 %212)
%214 = load i32, i32* %16
%215 = sext i32 %214 to i64
%216 = inttoptr i64 %215 to i8*
%217 = load i32, i32* %17
%218 = sext i32 %217 to i64
%219 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %14, i64 0, i64 %218
store i8* %216, i8** %219
br label %227
220: ; preds = %205
%221 = load i32*, i32** %13
%222 = load i32, i32* %17
%223 = call i32 (i32*, i8*, ...) @fprintf(i32* %221, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %222)
%224 = load i32, i32* %17
%225 = sext i32 %224 to i64
%226 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %14, i64 0, i64 %225
store i8* null, i8** %226
br label %227
227: ; preds = %220, %209
br label %228
228: ; preds = %227, %194
%229 = load i32, i32* %15
%230 = srem i32 %229, 8
%231 = icmp eq i32 %230, 0
br i1 %231, label %232, label %235
232: ; preds = %228
%233 = load i32*, i32** %13
%234 = call i32 (i32*, i8*, ...) @fprintf(i32* %233, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %238
235: ; preds = %228
%236 = load i32*, i32** %13
%237 = call i32 (i32*, i8*, ...) @fprintf(i32* %236, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %238
238: ; preds = %235, %232
br label %239
239: ; preds = %238
%240 = load i32, i32* %15
%241 = add nsw i32 %240, 1
store i32 %241, i32* %15
br label %172
242: ; preds = %172
store i32 0, i32* %18
br label %243
243: ; preds = %267, %242
%244 = load i32, i32* %18
%245 = icmp slt i32 %244, 4096
br i1 %245, label %246, label %270
246: ; preds = %243
%247 = load i32, i32* %18
%248 = sext i32 %247 to i64
%249 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %14, i64 0, i64 %248
%250 = load i8*, i8** %249
%251 = icmp ne i8* %250, null
br i1 %251, label %252, label %266
252: ; preds = %246
%253 = load i32*, i32** %13
%254 = load i32, i32* %18
%255 = call i32 (i32*, i8*, ...) @fprintf(i32* %253, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %254)
%256 = load i32, i32* %18
%257 = srem i32 %256, 8
%258 = icmp eq i32 %257, 0
br i1 %258, label %259, label %262
259: ; preds = %252
%260 = load i32*, i32** %13
%261 = call i32 (i32*, i8*, ...) @fprintf(i32* %260, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %265
262: ; preds = %252
%263 = load i32*, i32** %13
%264 = call i32 (i32*, i8*, ...) @fprintf(i32* %263, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %265
265: ; preds = %262, %259
br label %266
266: ; preds = %265, %246
br label %267
267: ; preds = %266
%268 = load i32, i32* %18
%269 = add nsw i32 %268, 1
store i32 %269, i32* %18
br label %243
270: ; preds = %243
%271 = load i32*, i32** %13
%272 = call i32 (i32*, i8*, ...) @fprintf(i32* %271, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%273 = load i32*, i32** %13
%274 = call i32 @fclose(i32* %273)
store i32 0, i32* %3
br label %275
275: ; preds = %270, %158, %152, %144, %21
%276 = load i32, i32* %3
ret i32 %276
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"m:M:c:p:\00"
@optarg = global i8* null
@.str.2 = [78 x i8] c"generating min=%d bytes max=%d bytes %d allocations over %d pointers into %s\0A\00"
@.str.6 = [3 x i8] c"w+\00"
@.str.7 = [6 x i8] c"%d=%d\00"
@.str.8 = [3 x i8] c"%d\00"
@str = [60 x i8] c"min size can't be greater than max size\0Aaborting generation\00"
@str.11 = [52 x i8] c"min size or max size can't be 0\0Aaborting generation\00"
@str.12 = [113 x i8] c"./genrandms [-m 32[kmg]b] [-M 16[kmg]b] [-c 128] [-p 16] filename.ms - malloc memory random simulation generator\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [4096 x i8*]
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %19
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([113 x i8], [113 x i8]* @str.12, i64 0, i64 0))
br label %151
7: ; preds = %31, %7
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
switch i32 %8, label %7 [
i32 -1, label %71
i32 99, label %9
i32 112, label %14
i32 109, label %33
i32 77, label %52
]
9: ; preds = %7
%10 = load i8*, i8** @optarg
%11 = tail call i8* @atoi(i8* %10)
%12 = ptrtoint i8* %11 to i64
%13 = trunc i64 %12 to i32
br label %24
14: ; preds = %7
%15 = load i8*, i8** @optarg
%16 = tail call i8* @atoi(i8* %15)
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i32
br label %19
19: ; preds = %2, %14
%20 = phi i32 [ %18, %14 ], [ 16, %2 ]
%21 = phi i32 [ %25, %14 ], [ 128, %2 ]
%22 = phi i64 [ %29, %14 ], [ 16777216, %2 ]
%23 = phi i64 [ %32, %14 ], [ 32, %2 ]
br label %24
24: ; preds = %19, %9
%25 = phi i32 [ %21, %19 ], [ %13, %9 ]
%26 = phi i64 [ %22, %19 ], [ %29, %9 ]
%27 = phi i64 [ %23, %19 ], [ %32, %9 ]
br label %28
28: ; preds = %24, %52
%29 = phi i64 [ %26, %24 ], [ %70, %52 ]
%30 = phi i64 [ %27, %24 ], [ %32, %52 ]
br label %31
31: ; preds = %28, %33
%32 = phi i64 [ %30, %28 ], [ %51, %33 ]
br label %7
33: ; preds = %7
%34 = load i8*, i8** @optarg
%35 = tail call i32 @strlen(i8* %34)
%36 = load i8*, i8** @optarg
%37 = tail call i8* @atoi(i8* %36)
%38 = ptrtoint i8* %37 to i64
%39 = add nsw i32 %35, -2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %36, i64 %40
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 107
%44 = shl i64 %38, 10
%45 = select i1 %43, i64 %44, i64 %38
%46 = icmp eq i8 %42, 109
%47 = shl i64 %45, 20
%48 = select i1 %46, i64 %47, i64 %45
%49 = icmp eq i8 %42, 103
%50 = shl i64 %48, 30
%51 = select i1 %49, i64 %50, i64 %48
br label %31
52: ; preds = %7
%53 = load i8*, i8** @optarg
%54 = tail call i32 @strlen(i8* %53)
%55 = load i8*, i8** @optarg
%56 = tail call i8* @atoi(i8* %55)
%57 = ptrtoint i8* %56 to i64
%58 = add nsw i32 %54, -2
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %55, i64 %59
%61 = load i8, i8* %60
%62 = icmp eq i8 %61, 107
%63 = shl i64 %57, 10
%64 = select i1 %62, i64 %63, i64 %57
%65 = icmp eq i8 %61, 109
%66 = shl i64 %64, 20
%67 = select i1 %65, i64 %66, i64 %64
%68 = icmp eq i8 %61, 103
%69 = shl i64 %67, 30
%70 = select i1 %68, i64 %69, i64 %67
br label %28
71: ; preds = %7
%72 = add nsw i32 %0, -1
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %1, i64 %73
%75 = load i8*, i8** %74
%76 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0), i64 %32, i64 %29, i32 %25, i32 %20, i8* %75)
%77 = icmp eq i64 %32, 0
%78 = icmp eq i64 %29, 0
%79 = select i1 %77, i1 true, i1 %78
br i1 %79, label %80, label %82
80: ; preds = %71
%81 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.11, i64 0, i64 0))
br label %151
82: ; preds = %71
%83 = icmp ult i64 %29, %32
br i1 %83, label %84, label %86
84: ; preds = %82
%85 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str, i64 0, i64 0))
br label %151
86: ; preds = %82
%87 = tail call i32 @time(i32* null)
%88 = tail call i32 @srand(i32 %87)
%89 = load i8*, i8** %74
%90 = tail call i32* @fopen(i8* %89, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%91 = bitcast [4096 x i8*]* %3 to i8*
%92 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %3, i64 0, i64 0
%93 = call i32 @memset(i8** %92, i32 0, i32 32768)
%94 = icmp sgt i32 %25, 0
br i1 %94, label %96, label %95
95: ; preds = %125, %86
br label %136
96: ; preds = %86
%97 = add i64 %29, 1
%98 = sub i64 %97, %32
br label %99
99: ; preds = %96, %125
%100 = phi i32 [ 0, %96 ], [ %131, %125 ]
%101 = call i64 (...) @rand()
%102 = urem i64 %101, %98
%103 = add i64 %102, %32
%104 = trunc i64 %103 to i32
%105 = srem i32 %104, %20
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %3, i64 0, i64 %106
%108 = load i8*, i8** %107
%109 = icmp eq i8* %108, null
br i1 %109, label %110, label %115
110: ; preds = %99
%111 = call i32 (i32*, i8*, ...) @fprintf(i32* %90, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %105, i32 %104)
%112 = shl i64 %103, 32
%113 = ashr exact i64 %112, 32
%114 = inttoptr i64 %113 to i8*
br label %125
115: ; preds = %99
%116 = and i32 %104, 1
%117 = icmp eq i32 %116, 0
br i1 %117, label %118, label %123
118: ; preds = %115
%119 = call i32 (i32*, i8*, ...) @fprintf(i32* %90, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %105, i32 %104)
%120 = shl i64 %103, 32
%121 = ashr exact i64 %120, 32
%122 = inttoptr i64 %121 to i8*
br label %125
123: ; preds = %115
%124 = call i32 (i32*, i8*, ...) @fprintf(i32* %90, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %105)
br label %125
125: ; preds = %118, %123, %110
%126 = phi i8* [ %122, %118 ], [ null, %123 ], [ %114, %110 ]
store i8* %126, i8** %107
%127 = and i32 %100, 7
%128 = icmp eq i32 %127, 0
%129 = select i1 %128, i32 10, i32 32
%130 = call i32 @fputc(i32 %129, i32* %90)
%131 = add nuw nsw i32 %100, 1
%132 = icmp eq i32 %131, %25
br i1 %132, label %95, label %99
133: ; preds = %148
%134 = call i32 @fputc(i32 10, i32* %90)
%135 = call i32 @fclose(i32* %90)
br label %151
136: ; preds = %95, %148
%137 = phi i64 [ %149, %148 ], [ 0, %95 ]
%138 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %3, i64 0, i64 %137
%139 = load i8*, i8** %138
%140 = icmp eq i8* %139, null
br i1 %140, label %148, label %141
141: ; preds = %136
%142 = trunc i64 %137 to i32
%143 = call i32 (i32*, i8*, ...) @fprintf(i32* %90, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %142)
%144 = and i32 %142, 7
%145 = icmp eq i32 %144, 0
%146 = select i1 %145, i32 10, i32 32
%147 = call i32 @fputc(i32 %146, i32* %90)
br label %148
148: ; preds = %141, %136
%149 = add nuw nsw i64 %137, 1
%150 = icmp eq i64 %149, 4096
br i1 %150, label %133, label %136
151: ; preds = %80, %84, %133, %5
%152 = phi i32 [ 1, %5 ], [ 1, %80 ], [ 1, %84 ], [ 0, %133 ]
ret i32 %152
}