#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 */

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int mb_query();
int mb_query_server();
int mb_query_total();
scalar_t__ mb_register(int /*<<< orphan*/);
int mb_request_pages(int);
int mb_reserve_pages(int);
int /*<<< orphan*/ mb_return_pages(int);
int /*<<< orphan*/ mb_status();
int /*<<< orphan*/ mb_terminate();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printHelp();
int /*<<< orphan*/ printUsage(char const *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int /*<<< orphan*/, char *, int);
int sscanf(char *, char *, char *, int *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int main(int argc, const char **argv) {
  char buf[500];
  char command[500];
  int pages;
  if (argc > 1) {
    printUsage(argv[0]);
    return 0;
  }
  int my_pages = 0;
  if (mb_register(0) < 0) {
    printf("Failed to register\n");
    return -1;
  }
  do {
    int conv = 0;
    memset(command, 0, 500);
    memset(buf, 0, 500);
    pages = 0;
    printf("Enter Command, '?' for help:\n> ");
    fflush(stdout);
    do {
      conv += read(fileno(stdin), &buf[conv], sizeof(char));
      if (conv == 0 && errno == 0)
        break;
    } while (buf[conv - 1] != '\n');
    buf[conv] = '\0';
    conv = sscanf(buf, "%s %d", command, &pages);
    if (conv == 2 && 0 == strcmp(command, "request")) {
      int reaped = 0;
      printf("Requesting %d pages\n", pages);
      reaped = mb_request_pages(pages);
      if (reaped > 0) {
        my_pages += reaped;
        printf("Got %d pages.  Total: %d\n", reaped, my_pages);
      } else {
        printf("request pages returns %d\n", reaped);
      }
    } else if (conv == 2 && 0 == strcmp(command, "reserve")) {
      int reaped = 0;
      printf("Requesting %d pages\n", pages);
      reaped = mb_reserve_pages(pages);
      if (reaped > 0) {
        my_pages += reaped;
        printf("Got %d pages.  Total: %d\n", reaped, my_pages);
      } else {
        printf("request pages returns %d\n", reaped);
      }
    } else if (conv == 1 && 0 == strcmp(command, "reserve-all")) {
      int total_reaped = 0;
      int incremetal_reaped = 0;
      int attempt = mb_query_total();
      while (attempt > 0) {
        incremetal_reaped = mb_reserve_pages(attempt);
        total_reaped += incremetal_reaped;
        if (incremetal_reaped == 0) {
          attempt /= 2;
        }
      }
      if (total_reaped > 0) {
        my_pages += total_reaped;
        printf("Got %d pages.  Total: %d\n", total_reaped, my_pages);
      } else {
        printf("request pages returns %d\n", total_reaped);
      }
    } else if (conv == 2 && 0 == strcmp(command, "return")) {
      int ret_pages = my_pages < pages ? my_pages : pages;
      printf("Returning %d pages\n", ret_pages);
      if (!mb_return_pages(ret_pages))
        my_pages -= ret_pages;
      printf("Total Pages: %d\n", my_pages);
    } else if (conv == 1 && 0 == strcmp(command, "query")) {
      int mb_pages = mb_query();
      if (mb_pages >= 0)
        printf("membroker pages: %d.  My Pages: %d\n", mb_pages, my_pages);
    } else if (conv == 1 && 0 == strcmp(command, "query-server")) {
      int mb_pages = mb_query_server();
      if (mb_pages >= 0)
        printf("membroker server available pages: %d.\n", mb_pages);
    } else if (conv == 1 && 0 == strcmp(command, "query-total")) {
      int mb_pages = mb_query_total();
      if (mb_pages >= 0)
        printf("membroker server theoretical total pages: %d.\n", mb_pages);
    } else if (conv == 1 && 0 == strcmp(command, "status")) {
      mb_status();
    } else if (conv == 1 && 0 == strcmp(command, "?")) {
      printHelp();
    } else if (conv == 1 && 0 != strcmp(command, "end")) {
      printf("Unknown command\n");
      printHelp();
    }
    printf("\n");
  } while (0 != strcmp(command, "end"));
  if (my_pages > 0) {
    mb_return_pages(my_pages);
  }
  mb_terminate();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    125b <main+0x3b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1120 <printUsage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1927 <main+0x707>
movl   $0x0,-0x418(%rbp)
xor    %edi,%edi
call   1140 <mb_register@plt>
cmp    $0x0,%rax
jge    1290 <main+0x70>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1927 <main+0x707>
jmp    1295 <main+0x75>
movl   $0x0,-0x41c(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x1f4,%edx
call   1060 <memset@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x1f4,%edx
call   1060 <memset@plt>
movl   $0x0,-0x414(%rbp)
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
call   10f0 <fflush@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   10c0 <fileno@plt>
mov    %eax,%edi
movslq -0x41c(%rbp),%rax
lea    -0x210(%rbp),%rsi
add    %rax,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
mov    %rax,%rcx
movslq -0x41c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x41c(%rbp)
cmpl   $0x0,-0x41c(%rbp)
jne    134c <main+0x12c>
mov    0x2c9b(%rip),%rax
cmpq   $0x0,(%rax)
jne    134c <main+0x12c>
jmp    136d <main+0x14d>
jmp    1351 <main+0x131>
mov    -0x41c(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x210(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12eb <main+0xcb>
movslq -0x41c(%rbp),%rax
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    0xca3(%rip),%rsi
lea    -0x414(%rbp),%rcx
call   1100 <sscanf@plt>
mov    %eax,-0x41c(%rbp)
cmpl   $0x2,-0x41c(%rbp)
jne    1457 <main+0x237>
lea    -0x410(%rbp),%rdi
lea    0xc7c(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1457 <main+0x237>
movl   $0x0,-0x420(%rbp)
mov    -0x414(%rbp),%esi
lea    0xc5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x414(%rbp),%edi
call   1110 <mb_request_pages@plt>
mov    %eax,-0x420(%rbp)
cmpl   $0x0,-0x420(%rbp)
jle    143e <main+0x21e>
mov    -0x420(%rbp),%eax
add    -0x418(%rbp),%eax
mov    %eax,-0x418(%rbp)
mov    -0x420(%rbp),%esi
mov    -0x418(%rbp),%edx
lea    0xc25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1452 <main+0x232>
mov    -0x420(%rbp),%esi
lea    0xc26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    18d2 <main+0x6b2>
cmpl   $0x2,-0x41c(%rbp)
jne    150b <main+0x2eb>
lea    -0x410(%rbp),%rdi
lea    0xc19(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    150b <main+0x2eb>
movl   $0x0,-0x424(%rbp)
mov    -0x414(%rbp),%esi
lea    0xba6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x414(%rbp),%edi
call   1070 <mb_reserve_pages@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jle    14f2 <main+0x2d2>
mov    -0x424(%rbp),%eax
add    -0x418(%rbp),%eax
mov    %eax,-0x418(%rbp)
mov    -0x424(%rbp),%esi
mov    -0x418(%rbp),%edx
lea    0xb71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1506 <main+0x2e6>
mov    -0x424(%rbp),%esi
lea    0xb72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    18cd <main+0x6ad>
cmpl   $0x1,-0x41c(%rbp)
jne    1607 <main+0x3e7>
lea    -0x410(%rbp),%rdi
lea    0xb6d(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1607 <main+0x3e7>
movl   $0x0,-0x428(%rbp)
movl   $0x0,-0x42c(%rbp)
mov    $0x0,%al
call   1080 <mb_query_total@plt>
mov    %eax,-0x430(%rbp)
cmpl   $0x0,-0x430(%rbp)
jle    15b0 <main+0x390>
mov    -0x430(%rbp),%edi
call   1070 <mb_reserve_pages@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
add    -0x428(%rbp),%eax
mov    %eax,-0x428(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jne    15ab <main+0x38b>
mov    -0x430(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x430(%rbp)
jmp    155a <main+0x33a>
cmpl   $0x0,-0x428(%rbp)
jle    15ee <main+0x3ce>
mov    -0x428(%rbp),%eax
add    -0x418(%rbp),%eax
mov    %eax,-0x418(%rbp)
mov    -0x428(%rbp),%esi
mov    -0x418(%rbp),%edx
lea    0xa75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1602 <main+0x3e2>
mov    -0x428(%rbp),%esi
lea    0xa76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    18c8 <main+0x6a8>
cmpl   $0x2,-0x41c(%rbp)
jne    16c5 <main+0x4a5>
lea    -0x410(%rbp),%rdi
lea    0xa7d(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    16c5 <main+0x4a5>
mov    -0x418(%rbp),%eax
cmp    -0x414(%rbp),%eax
jge    1658 <main+0x438>
mov    -0x418(%rbp),%eax
mov    %eax,-0x444(%rbp)
jmp    1664 <main+0x444>
mov    -0x414(%rbp),%eax
mov    %eax,-0x444(%rbp)
mov    -0x444(%rbp),%eax
mov    %eax,-0x434(%rbp)
mov    -0x434(%rbp),%esi
lea    0xa29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x434(%rbp),%edi
call   10d0 <mb_return_pages@plt>
cmp    $0x0,%eax
jne    16ac <main+0x48c>
mov    -0x434(%rbp),%ecx
mov    -0x418(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%esi
lea    0xa01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    18c3 <main+0x6a3>
cmpl   $0x1,-0x41c(%rbp)
jne    172c <main+0x50c>
lea    -0x410(%rbp),%rdi
lea    0x9eb(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    172c <main+0x50c>
mov    $0x0,%al
call   1130 <mb_query@plt>
mov    %eax,-0x438(%rbp)
cmpl   $0x0,-0x438(%rbp)
jl     1727 <main+0x507>
mov    -0x438(%rbp),%esi
mov    -0x418(%rbp),%edx
lea    0x9b1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    18be <main+0x69e>
cmpl   $0x1,-0x41c(%rbp)
jne    178d <main+0x56d>
lea    -0x410(%rbp),%rdi
lea    0x9ae(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    178d <main+0x56d>
mov    $0x0,%al
call   10b0 <mb_query_server@plt>
mov    %eax,-0x43c(%rbp)
cmpl   $0x0,-0x43c(%rbp)
jl     1788 <main+0x568>
mov    -0x43c(%rbp),%esi
lea    0x981(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    18b9 <main+0x699>
cmpl   $0x1,-0x41c(%rbp)
jne    17ee <main+0x5ce>
lea    -0x410(%rbp),%rdi
lea    0x981(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    17ee <main+0x5ce>
mov    $0x0,%al
call   1080 <mb_query_total@plt>
mov    %eax,-0x440(%rbp)
cmpl   $0x0,-0x440(%rbp)
jl     17e9 <main+0x5c9>
mov    -0x440(%rbp),%esi
lea    0x953(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    18b4 <main+0x694>
cmpl   $0x1,-0x41c(%rbp)
jne    1828 <main+0x608>
lea    -0x410(%rbp),%rdi
lea    0x95b(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1828 <main+0x608>
mov    $0x0,%al
call   1040 <mb_status@plt>
jmp    18af <main+0x68f>
cmpl   $0x1,-0x41c(%rbp)
jne    1862 <main+0x642>
lea    -0x410(%rbp),%rdi
lea    0x928(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1862 <main+0x642>
mov    $0x0,%al
call   1030 <printHelp@plt>
jmp    18aa <main+0x68a>
cmpl   $0x1,-0x41c(%rbp)
jne    18a5 <main+0x685>
lea    -0x410(%rbp),%rdi
lea    0x8f0(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     18a5 <main+0x685>
lea    0x8da(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <printHelp@plt>
jmp    18aa <main+0x68a>
jmp    18af <main+0x68f>
jmp    18b4 <main+0x694>
jmp    18b9 <main+0x699>
jmp    18be <main+0x69e>
jmp    18c3 <main+0x6a3>
jmp    18c8 <main+0x6a8>
jmp    18cd <main+0x6ad>
jmp    18d2 <main+0x6b2>
lea    0x84e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
lea    0x87f(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1295 <main+0x75>
cmpl   $0x0,-0x418(%rbp)
jle    1919 <main+0x6f9>
mov    -0x418(%rbp),%edi
call   10d0 <mb_return_pages@plt>
mov    $0x0,%al
call   10e0 <mb_terminate@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
cmp    $0x2,%edi
jl     1265 <main+0x25>
mov    (%rsi),%rdi
call   1140 <printUsage@plt>
xor    %ebx,%ebx
jmp    164f <main+0x40f>
xor    %edi,%edi
call   1160 <mb_register@plt>
test   %rax,%rax
js     163e <main+0x3fe>
lea    0x210(%rsp),%r12
mov    0x2d64(%rip),%r13
mov    0x2d4d(%rip),%r15
movabs $0xffffffff00000000,%r14
ff ff ff
movl   $0x0,0x8(%rsp)
jmp    1302 <main+0xc2>
mov    0xc(%rsp),%esi
lea    0xd84(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%rsp),%edi
call   1130 <mb_request_pages@plt>
test   %eax,%eax
jle    159b <main+0x35b>
mov    0x8(%rsp),%edx
add    %eax,%edx
lea    0xd74(%rip),%rdi
mov    %eax,%esi
mov    %edx,0x8(%rsp)
xor    %eax,%eax
call   1070 <printf@plt>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r12,%rdi
lea    0xe65(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1626 <main+0x3e6>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x1f4,%edx
call   1080 <memset@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x1f4,%edx
call   1080 <memset@plt>
movl   $0x0,0xc(%rsp)
lea    0xccf(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
call   1110 <fflush@plt>
xor    %ebp,%ebp
jmp    135f <main+0x11f>
nopw   0x0(%rax,%rax,1)
lea    (%rax,%r14,1),%rcx
sar    $0x20,%rcx
cmpb   $0xa,0x10(%rsp,%rcx,1)
je     1396 <main+0x156>
mov    0x0(%r13),%edi
call   10e0 <fileno@plt>
movslq %ebp,%rbx
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   10b0 <read@plt>
mov    %rax,%rbp
add    %rbx,%rbp
mov    %rbp,%rax
shl    $0x20,%rax
test   %ebp,%ebp
jne    1350 <main+0x110>
cmpq   $0x0,(%r15)
jne    1350 <main+0x110>
sar    $0x20,%rax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x10(%rsp),%rdi
lea    0xc75(%rip),%rsi
mov    %r12,%rdx
lea    0xc(%rsp),%rcx
call   1120 <sscanf@plt>
cmp    $0x1,%eax
je     1460 <main+0x220>
cmp    $0x2,%eax
jne    12e0 <main+0xa0>
mov    %r12,%rdi
lea    0xc52(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     129f <main+0x5f>
mov    %r12,%rdi
lea    0xc8b(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1578 <main+0x338>
mov    %r12,%rdi
lea    0xc87(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
jne    12e0 <main+0xa0>
mov    0xc(%rsp),%ebp
mov    0x8(%rsp),%ebx
cmp    %ebp,%ebx
cmovl  %ebx,%ebp
lea    0xc6c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
call   10f0 <mb_return_pages@plt>
test   %eax,%eax
mov    $0x0,%eax
cmovne %eax,%ebp
sub    %ebp,%ebx
lea    0xc5d(%rip),%rdi
mov    %ebx,0x8(%rsp)
mov    %ebx,%esi
jmp    160e <main+0x3ce>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
lea    0xc15(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     151c <main+0x2dc>
mov    %r12,%rdi
lea    0xc35(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     15a4 <main+0x364>
mov    %r12,%rdi
lea    0xc47(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     15de <main+0x39e>
mov    %r12,%rdi
lea    0xc63(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     15f6 <main+0x3b6>
mov    %r12,%rdi
lea    0xc86(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     161a <main+0x3da>
mov    %r12,%rdi
lea    0xc75(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1510 <main+0x2d0>
mov    %r12,%rdi
lea    0xc63(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     12e0 <main+0xa0>
lea    0xc52(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1030 <printHelp@plt>
jmp    12e0 <main+0xa0>
mov    %r12,%rbx
xor    %r12d,%r12d
xor    %eax,%eax
call   10a0 <mb_query_total@plt>
test   %eax,%eax
jle    15c5 <main+0x385>
mov    %eax,%ebp
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1090 <mb_reserve_pages@plt>
add    %eax,%r12d
test   %eax,%eax
sete   %cl
shr    %cl,%ebp
test   %ebp,%ebp
jne    1540 <main+0x300>
test   %r12d,%r12d
jle    15c5 <main+0x385>
mov    0x8(%rsp),%edx
add    %r12d,%edx
lea    0xadb(%rip),%rdi
mov    %r12d,%esi
mov    %edx,0x8(%rsp)
xor    %eax,%eax
call   1070 <printf@plt>
jmp    15d6 <main+0x396>
mov    0xc(%rsp),%esi
lea    0xaab(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%rsp),%edi
call   1090 <mb_reserve_pages@plt>
test   %eax,%eax
jg     12c2 <main+0x82>
lea    0xabb(%rip),%rdi
jmp    160c <main+0x3cc>
xor    %eax,%eax
call   1150 <mb_query@plt>
test   %eax,%eax
js     12e0 <main+0xa0>
lea    0xb03(%rip),%rdi
mov    %eax,%esi
mov    0x8(%rsp),%edx
jmp    12d5 <main+0x95>
lea    0xa91(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%r12
jmp    12e0 <main+0xa0>
xor    %eax,%eax
call   10d0 <mb_query_server@plt>
test   %eax,%eax
js     12e0 <main+0xa0>
lea    0xafa(%rip),%rdi
jmp    160c <main+0x3cc>
xor    %eax,%eax
call   10a0 <mb_query_total@plt>
test   %eax,%eax
js     12e0 <main+0xa0>
lea    0xb15(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12e0 <main+0xa0>
xor    %eax,%eax
call   1060 <mb_status@plt>
jmp    12e0 <main+0xa0>
mov    0x8(%rsp),%edi
test   %edi,%edi
jle    1633 <main+0x3f3>
call   10f0 <mb_return_pages@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1100 <mb_terminate@plt>
jmp    164f <main+0x40f>
lea    0xb28(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Failed to register\0A\00"
@.str.1 = [32 x i8] c"Enter Command, '?' for help:\0A> \00"
@stdout = global i32 0
@stdin = global i32 0
@errno = global i64 0
@.str.2 = [6 x i8] c"%s %d\00"
@.str.3 = [8 x i8] c"request\00"
@.str.4 = [21 x i8] c"Requesting %d pages\0A\00"
@.str.5 = [26 x i8] c"Got %d pages. Total: %d\0A\00"
@.str.6 = [26 x i8] c"request pages returns %d\0A\00"
@.str.7 = [8 x i8] c"reserve\00"
@.str.8 = [12 x i8] c"reserve-all\00"
@.str.9 = [7 x i8] c"return\00"
@.str.10 = [20 x i8] c"Returning %d pages\0A\00"
@.str.11 = [17 x i8] c"Total Pages: %d\0A\00"
@.str.12 = [6 x i8] c"query\00"
@.str.13 = [36 x i8] c"membroker pages: %d. My Pages: %d\0A\00"
@.str.14 = [13 x i8] c"query-server\00"
@.str.15 = [39 x i8] c"membroker server available pages: %d.\0A\00"
@.str.16 = [12 x i8] c"query-total\00"
@.str.17 = [47 x i8] c"membroker server theoretical total pages: %d.\0A\00"
@.str.18 = [7 x i8] c"status\00"
@.str.19 = [2 x i8] c"?\00"
@.str.20 = [4 x i8] c"end\00"
@.str.21 = [17 x i8] c"Unknown command\0A\00"
@.str.22 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [500 x i8]
%7 = alloca [500 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @printUsage(i8* %25)
store i32 0, i32* %3
br label %287
27: ; preds = %2
store i32 0, i32* %9
%28 = call i64 @mb_register(i32 0)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %287
32: ; preds = %27
br label %33
33: ; preds = %275, %32
store i32 0, i32* %10
%34 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%35 = call i32 @memset(i8* %34, i32 0, i32 500)
%36 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%37 = call i32 @memset(i8* %36, i32 0, i32 500)
store i32 0, i32* %8
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* @stdout
%40 = call i32 @fflush(i32 %39)
br label %41
41: ; preds = %59, %33
%42 = load i32, i32* @stdin
%43 = call i32 @fileno(i32 %42)
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 %45
%47 = call i64 @read(i32 %43, i8* %46, i32 1)
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = add nsw i64 %49, %47
%51 = trunc i64 %50 to i32
store i32 %51, i32* %10
%52 = load i32, i32* %10
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %41
%55 = load i64, i64* @errno
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %54
br label %67
58: ; preds = %54, %41
br label %59
59: ; preds = %58
%60 = load i32, i32* %10
%61 = sub nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 10
br i1 %66, label %41, label %67
67: ; preds = %59, %57
%68 = load i32, i32* %10
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 %69
store i8 0, i8* %70
%71 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%72 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%73 = call i32 @sscanf(i8* %71, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %72, i32* %8)
store i32 %73, i32* %10
%74 = load i32, i32* %10
%75 = icmp eq i32 %74, 2
br i1 %75, label %76, label %98
76: ; preds = %67
%77 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%78 = call i64 @strcmp(i8* %77, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%79 = icmp eq i64 0, %78
br i1 %79, label %80, label %98
80: ; preds = %76
store i32 0, i32* %11
%81 = load i32, i32* %8
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %8
%84 = call i32 @mb_request_pages(i32 %83)
store i32 %84, i32* %11
%85 = load i32, i32* %11
%86 = icmp sgt i32 %85, 0
br i1 %86, label %87, label %94
87: ; preds = %80
%88 = load i32, i32* %11
%89 = load i32, i32* %9
%90 = add nsw i32 %89, %88
store i32 %90, i32* %9
%91 = load i32, i32* %11
%92 = load i32, i32* %9
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %91, i32 %92)
br label %97
94: ; preds = %80
%95 = load i32, i32* %11
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %95)
br label %97
97: ; preds = %94, %87
br label %273
98: ; preds = %76, %67
%99 = load i32, i32* %10
%100 = icmp eq i32 %99, 2
br i1 %100, label %101, label %123
101: ; preds = %98
%102 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%103 = call i64 @strcmp(i8* %102, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%104 = icmp eq i64 0, %103
br i1 %104, label %105, label %123
105: ; preds = %101
store i32 0, i32* %12
%106 = load i32, i32* %8
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %106)
%108 = load i32, i32* %8
%109 = call i32 @mb_reserve_pages(i32 %108)
store i32 %109, i32* %12
%110 = load i32, i32* %12
%111 = icmp sgt i32 %110, 0
br i1 %111, label %112, label %119
112: ; preds = %105
%113 = load i32, i32* %12
%114 = load i32, i32* %9
%115 = add nsw i32 %114, %113
store i32 %115, i32* %9
%116 = load i32, i32* %12
%117 = load i32, i32* %9
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %116, i32 %117)
br label %122
119: ; preds = %105
%120 = load i32, i32* %12
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %120)
br label %122
122: ; preds = %119, %112
br label %272
123: ; preds = %101, %98
%124 = load i32, i32* %10
%125 = icmp eq i32 %124, 1
br i1 %125, label %126, label %161
126: ; preds = %123
%127 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%128 = call i64 @strcmp(i8* %127, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%129 = icmp eq i64 0, %128
br i1 %129, label %130, label %161
130: ; preds = %126
store i32 0, i32* %13
store i32 0, i32* %14
%131 = call i32 (...) @mb_query_total()
store i32 %131, i32* %15
br label %132
132: ; preds = %146, %130
%133 = load i32, i32* %15
%134 = icmp sgt i32 %133, 0
br i1 %134, label %135, label %147
135: ; preds = %132
%136 = load i32, i32* %15
%137 = call i32 @mb_reserve_pages(i32 %136)
store i32 %137, i32* %14
%138 = load i32, i32* %14
%139 = load i32, i32* %13
%140 = add nsw i32 %139, %138
store i32 %140, i32* %13
%141 = load i32, i32* %14
%142 = icmp eq i32 %141, 0
br i1 %142, label %143, label %146
143: ; preds = %135
%144 = load i32, i32* %15
%145 = sdiv i32 %144, 2
store i32 %145, i32* %15
br label %146
146: ; preds = %143, %135
br label %132
147: ; preds = %132
%148 = load i32, i32* %13
%149 = icmp sgt i32 %148, 0
br i1 %149, label %150, label %157
150: ; preds = %147
%151 = load i32, i32* %13
%152 = load i32, i32* %9
%153 = add nsw i32 %152, %151
store i32 %153, i32* %9
%154 = load i32, i32* %13
%155 = load i32, i32* %9
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %154, i32 %155)
br label %160
157: ; preds = %147
%158 = load i32, i32* %13
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %158)
br label %160
160: ; preds = %157, %150
br label %271
161: ; preds = %126, %123
%162 = load i32, i32* %10
%163 = icmp eq i32 %162, 2
br i1 %163, label %164, label %190
164: ; preds = %161
%165 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%166 = call i64 @strcmp(i8* %165, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%167 = icmp eq i64 0, %166
br i1 %167, label %168, label %190
168: ; preds = %164
%169 = load i32, i32* %9
%170 = load i32, i32* %8
%171 = icmp slt i32 %169, %170
br i1 %171, label %172, label %174
172: ; preds = %168
%173 = load i32, i32* %9
br label %176
174: ; preds = %168
%175 = load i32, i32* %8
br label %176
176: ; preds = %174, %172
%177 = phi i32 [ %173, %172 ], [ %175, %174 ]
store i32 %177, i32* %16
%178 = load i32, i32* %16
%179 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %178)
%180 = load i32, i32* %16
%181 = call i32 @mb_return_pages(i32 %180)
%182 = icmp ne i32 %181, 0
br i1 %182, label %187, label %183
183: ; preds = %176
%184 = load i32, i32* %16
%185 = load i32, i32* %9
%186 = sub nsw i32 %185, %184
store i32 %186, i32* %9
br label %187
187: ; preds = %183, %176
%188 = load i32, i32* %9
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i32 %188)
br label %270
190: ; preds = %164, %161
%191 = load i32, i32* %10
%192 = icmp eq i32 %191, 1
br i1 %192, label %193, label %206
193: ; preds = %190
%194 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%195 = call i64 @strcmp(i8* %194, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0))
%196 = icmp eq i64 0, %195
br i1 %196, label %197, label %206
197: ; preds = %193
%198 = call i32 (...) @mb_query()
store i32 %198, i32* %17
%199 = load i32, i32* %17
%200 = icmp sge i32 %199, 0
br i1 %200, label %201, label %205
201: ; preds = %197
%202 = load i32, i32* %17
%203 = load i32, i32* %9
%204 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.13, i64 0, i64 0), i32 %202, i32 %203)
br label %205
205: ; preds = %201, %197
br label %269
206: ; preds = %193, %190
%207 = load i32, i32* %10
%208 = icmp eq i32 %207, 1
br i1 %208, label %209, label %221
209: ; preds = %206
%210 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%211 = call i64 @strcmp(i8* %210, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0))
%212 = icmp eq i64 0, %211
br i1 %212, label %213, label %221
213: ; preds = %209
%214 = call i32 (...) @mb_query_server()
store i32 %214, i32* %18
%215 = load i32, i32* %18
%216 = icmp sge i32 %215, 0
br i1 %216, label %217, label %220
217: ; preds = %213
%218 = load i32, i32* %18
%219 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.15, i64 0, i64 0), i32 %218)
br label %220
220: ; preds = %217, %213
br label %268
221: ; preds = %209, %206
%222 = load i32, i32* %10
%223 = icmp eq i32 %222, 1
br i1 %223, label %224, label %236
224: ; preds = %221
%225 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%226 = call i64 @strcmp(i8* %225, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0))
%227 = icmp eq i64 0, %226
br i1 %227, label %228, label %236
228: ; preds = %224
%229 = call i32 (...) @mb_query_total()
store i32 %229, i32* %19
%230 = load i32, i32* %19
%231 = icmp sge i32 %230, 0
br i1 %231, label %232, label %235
232: ; preds = %228
%233 = load i32, i32* %19
%234 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.17, i64 0, i64 0), i32 %233)
br label %235
235: ; preds = %232, %228
br label %267
236: ; preds = %224, %221
%237 = load i32, i32* %10
%238 = icmp eq i32 %237, 1
br i1 %238, label %239, label %245
239: ; preds = %236
%240 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%241 = call i64 @strcmp(i8* %240, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.18, i64 0, i64 0))
%242 = icmp eq i64 0, %241
br i1 %242, label %243, label %245
243: ; preds = %239
%244 = call i32 (...) @mb_status()
br label %266
245: ; preds = %239, %236
%246 = load i32, i32* %10
%247 = icmp eq i32 %246, 1
br i1 %247, label %248, label %254
248: ; preds = %245
%249 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%250 = call i64 @strcmp(i8* %249, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i64 0, i64 0))
%251 = icmp eq i64 0, %250
br i1 %251, label %252, label %254
252: ; preds = %248
%253 = call i32 (...) @printHelp()
br label %265
254: ; preds = %248, %245
%255 = load i32, i32* %10
%256 = icmp eq i32 %255, 1
br i1 %256, label %257, label %264
257: ; preds = %254
%258 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%259 = call i64 @strcmp(i8* %258, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.20, i64 0, i64 0))
%260 = icmp ne i64 0, %259
br i1 %260, label %261, label %264
261: ; preds = %257
%262 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.21, i64 0, i64 0))
%263 = call i32 (...) @printHelp()
br label %264
264: ; preds = %261, %257, %254
br label %265
265: ; preds = %264, %252
br label %266
266: ; preds = %265, %243
br label %267
267: ; preds = %266, %235
br label %268
268: ; preds = %267, %220
br label %269
269: ; preds = %268, %205
br label %270
270: ; preds = %269, %187
br label %271
271: ; preds = %270, %160
br label %272
272: ; preds = %271, %122
br label %273
273: ; preds = %272, %97
%274 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.22, i64 0, i64 0))
br label %275
275: ; preds = %273
%276 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%277 = call i64 @strcmp(i8* %276, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.20, i64 0, i64 0))
%278 = icmp ne i64 0, %277
br i1 %278, label %33, label %279
279: ; preds = %275
%280 = load i32, i32* %9
%281 = icmp sgt i32 %280, 0
br i1 %281, label %282, label %285
282: ; preds = %279
%283 = load i32, i32* %9
%284 = call i32 @mb_return_pages(i32 %283)
br label %285
285: ; preds = %282, %279
%286 = call i32 (...) @mb_terminate()
store i32 0, i32* %3
br label %287
287: ; preds = %285, %30, %22
%288 = load i32, i32* %3
ret i32 %288
}

LLVM IR (-O2):
@.str.1 = [32 x i8] c"Enter Command, '?' for help:\0A> \00"
@stdout = global i32 0
@stdin = global i32 0
@errno = global i64 0
@.str.2 = [6 x i8] c"%s %d\00"
@.str.3 = [8 x i8] c"request\00"
@.str.4 = [21 x i8] c"Requesting %d pages\0A\00"
@.str.5 = [26 x i8] c"Got %d pages. Total: %d\0A\00"
@.str.6 = [26 x i8] c"request pages returns %d\0A\00"
@.str.7 = [8 x i8] c"reserve\00"
@.str.8 = [12 x i8] c"reserve-all\00"
@.str.9 = [7 x i8] c"return\00"
@.str.10 = [20 x i8] c"Returning %d pages\0A\00"
@.str.11 = [17 x i8] c"Total Pages: %d\0A\00"
@.str.12 = [6 x i8] c"query\00"
@.str.13 = [36 x i8] c"membroker pages: %d. My Pages: %d\0A\00"
@.str.14 = [13 x i8] c"query-server\00"
@.str.15 = [39 x i8] c"membroker server available pages: %d.\0A\00"
@.str.16 = [12 x i8] c"query-total\00"
@.str.17 = [47 x i8] c"membroker server theoretical total pages: %d.\0A\00"
@.str.18 = [7 x i8] c"status\00"
@.str.19 = [2 x i8] c"?\00"
@.str.20 = [4 x i8] c"end\00"
@str = [16 x i8] c"Unknown command\00"
@str.23 = [19 x i8] c"Failed to register\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [500 x i8]
%4 = alloca [500 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 @printUsage(i8* %11)
br label %165
13: ; preds = %2
%14 = tail call i64 @mb_register(i32 0)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.23, i64 0, i64 0))
br label %165
18: ; preds = %13, %154
%19 = phi i32 [ %155, %154 ], [ 0, %13 ]
%20 = call i32 @memset(i8* %7, i32 0, i32 500)
%21 = call i32 @memset(i8* %6, i32 0, i32 500)
store i32 0, i32* %5
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
br label %25
25: ; preds = %40, %18
%26 = phi i64 [ 0, %18 ], [ %33, %40 ]
%27 = load i32, i32* @stdin
%28 = call i32 @fileno(i32 %27)
%29 = shl i64 %26, 32
%30 = ashr exact i64 %29, 32
%31 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 %30
%32 = call i64 @read(i32 %28, i8* %31, i32 1)
%33 = add nsw i64 %32, %30
%34 = trunc i64 %33 to i32
%35 = icmp eq i32 %34, 0
%36 = load i64, i64* @errno
%37 = icmp eq i64 %36, 0
%38 = select i1 %35, i1 %37, i1 false
%39 = shl i64 %33, 32
br i1 %38, label %46, label %40
40: ; preds = %25
%41 = add i64 %39, -4294967296
%42 = ashr exact i64 %41, 32
%43 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 10
br i1 %45, label %46, label %25
46: ; preds = %40, %25
%47 = ashr exact i64 %39, 32
%48 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 %47
store i8 0, i8* %48
%49 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %7, i32* %5)
switch i32 %49, label %154 [
i32 2, label %50
i32 1, label %78
]
50: ; preds = %46
%51 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %64
53: ; preds = %50
%54 = load i32, i32* %5
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %5
%57 = call i32 @mb_request_pages(i32 %56)
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = add nsw i32 %57, %19
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %57, i32 %60)
br label %154
62: ; preds = %53
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %57)
br label %154
64: ; preds = %50
%65 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %101
67: ; preds = %64
%68 = load i32, i32* %5
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %68)
%70 = load i32, i32* %5
%71 = call i32 @mb_reserve_pages(i32 %70)
%72 = icmp sgt i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %67
%74 = add nsw i32 %71, %19
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %71, i32 %74)
br label %154
76: ; preds = %67
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %71)
br label %154
78: ; preds = %46
%79 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %114
81: ; preds = %78
%82 = call i32 (...) @mb_query_total()
%83 = icmp sgt i32 %82, 0
br i1 %83, label %84, label %98
84: ; preds = %81, %84
%85 = phi i32 [ %91, %84 ], [ %82, %81 ]
%86 = phi i32 [ %88, %84 ], [ 0, %81 ]
%87 = call i32 @mb_reserve_pages(i32 %85)
%88 = add nsw i32 %87, %86
%89 = icmp eq i32 %87, 0
%90 = zext i1 %89 to i32
%91 = lshr i32 %85, %90
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %84
93: ; preds = %84
%94 = icmp sgt i32 %88, 0
br i1 %94, label %95, label %98
95: ; preds = %93
%96 = add nsw i32 %88, %19
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %88, i32 %96)
br label %154
98: ; preds = %81, %93
%99 = phi i32 [ %88, %93 ], [ 0, %81 ]
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %99)
br label %154
101: ; preds = %64
%102 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%103 = icmp eq i64 %102, 0
br i1 %103, label %104, label %154
104: ; preds = %101
%105 = load i32, i32* %5
%106 = icmp slt i32 %19, %105
%107 = select i1 %106, i32 %19, i32 %105
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %107)
%109 = call i32 @mb_return_pages(i32 %107)
%110 = icmp eq i32 %109, 0
%111 = select i1 %110, i32 %107, i32 0
%112 = sub nsw i32 %19, %111
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i32 %112)
br label %154
114: ; preds = %78
%115 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0))
%116 = icmp eq i64 %115, 0
br i1 %116, label %117, label %122
117: ; preds = %114
%118 = call i32 (...) @mb_query()
%119 = icmp sgt i32 %118, -1
br i1 %119, label %120, label %154
120: ; preds = %117
%121 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.13, i64 0, i64 0), i32 %118, i32 %19)
br label %154
122: ; preds = %114
%123 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0))
%124 = icmp eq i64 %123, 0
br i1 %124, label %125, label %130
125: ; preds = %122
%126 = call i32 (...) @mb_query_server()
%127 = icmp sgt i32 %126, -1
br i1 %127, label %128, label %154
128: ; preds = %125
%129 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.15, i64 0, i64 0), i32 %126)
br label %154
130: ; preds = %122
%131 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0))
%132 = icmp eq i64 %131, 0
br i1 %132, label %133, label %138
133: ; preds = %130
%134 = call i32 (...) @mb_query_total()
%135 = icmp sgt i32 %134, -1
br i1 %135, label %136, label %154
136: ; preds = %133
%137 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.17, i64 0, i64 0), i32 %134)
br label %154
138: ; preds = %130
%139 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.18, i64 0, i64 0))
%140 = icmp eq i64 %139, 0
br i1 %140, label %141, label %143
141: ; preds = %138
%142 = call i32 (...) @mb_status()
br label %154
143: ; preds = %138
%144 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i64 0, i64 0))
%145 = icmp eq i64 %144, 0
br i1 %145, label %146, label %148
146: ; preds = %143
%147 = call i32 (...) @printHelp()
br label %154
148: ; preds = %143
%149 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.20, i64 0, i64 0))
%150 = icmp eq i64 %149, 0
br i1 %150, label %154, label %151
151: ; preds = %148
%152 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%153 = call i32 (...) @printHelp()
br label %154
154: ; preds = %101, %46, %133, %136, %125, %128, %117, %120, %95, %98, %73, %76, %59, %62, %104, %141, %148, %151, %146
%155 = phi i32 [ %112, %104 ], [ %19, %141 ], [ %19, %146 ], [ %19, %151 ], [ %19, %148 ], [ %60, %59 ], [ %19, %62 ], [ %74, %73 ], [ %19, %76 ], [ %96, %95 ], [ %19, %98 ], [ %19, %120 ], [ %19, %117 ], [ %19, %128 ], [ %19, %125 ], [ %19, %136 ], [ %19, %133 ], [ %19, %46 ], [ %19, %101 ]
%156 = call i32 @putchar(i32 10)
%157 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.20, i64 0, i64 0))
%158 = icmp eq i64 %157, 0
br i1 %158, label %159, label %18
159: ; preds = %154
%160 = icmp sgt i32 %155, 0
br i1 %160, label %161, label %163
161: ; preds = %159
%162 = call i32 @mb_return_pages(i32 %155)
br label %163
163: ; preds = %161, %159
%164 = call i32 (...) @mb_terminate()
br label %165
165: ; preds = %16, %163, %10
%166 = phi i32 [ 0, %10 ], [ -1, %16 ], [ 0, %163 ]
ret i32 %166
}