#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct nbd_request {
  scalar_t__ magic;
  int /*<<< orphan*/ type;
  int /*<<< orphan*/ from;
  int /*<<< orphan*/ len;
  struct nbd_reply *handle;
};
struct nbd_reply {
  scalar_t__ error;
  char *handle;
  scalar_t__ magic;
};
typedef int /*<<< orphan*/ request;
typedef int /*<<< orphan*/ gzFile;
typedef int __u64;
typedef int __u32;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EIO;
int /*<<< orphan*/ EROFS;
int /*<<< orphan*/ NBD_CLEAR_QUE;
int /*<<< orphan*/ NBD_CLEAR_SOCK;
int /*<<< orphan*/ NBD_DO_IT;
int /*<<< orphan*/ NBD_REPLY_MAGIC;
int /*<<< orphan*/ NBD_REQUEST_MAGIC;
int /*<<< orphan*/ NBD_SET_SIZE;
int /*<<< orphan*/ NBD_SET_SOCK;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SOCK_STREAM;
int atol(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ gzclose(int /*<<< orphan*/ *);
char *gzerror(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ *gzopen(char *, char *);
int gzread(int /*<<< orphan*/ *, char *, int);
scalar_t__ gzrewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ gzseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
scalar_t__ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ memcpy(char *, struct nbd_reply *, int);
int ntohl(int /*<<< orphan*/);
int ntohll(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, struct nbd_request *, int);
scalar_t__ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
int main(int argc, char **argv) {
  int pr[2];
  int sk;
  int nbd;
  gzFile *gz;
  int gzerr;
  char chunk[1024 * 20];
  struct nbd_request request;
  struct nbd_reply reply;
  __u64 size;
  __u64 from;
  __u32 len;
  if (argc < 3) {
    printf("Usage: %s nbdevice gzfile [size]\n", argv[0]);
    exit(1);
  }
  gz = gzopen(argv[2], "rb");
  if (gz == NULL) {
    fprintf(stderr, "%s: unable open compressed file %s\n", argv[0], argv[2]);
    exit(1);
  }
  if (argc > 3) {
    size = atol(argv[3]);
    if ((size == 0) || (size % 1024)) {
      fprintf(stderr, "%s: %s does not appear to be a valid size\n", argv[0],
              argv[3]);
      exit(1);
    }
    printf("%s: file=%s, size=%Ld\n", argv[0], argv[2], size);
  } else {
    char buffer[1024];
    int result;
    size = 0;
    printf("%s: file=%s, seeking, ", argv[0], argv[2]);
    fflush(stdout);
    while (1024 == (result = gzread(gz, buffer, 1024))) {
      size += 1024;
    }
    if (result == 0) {
      printf("size=%Ld\n", size);
    } else {
      printf("failed\n");
      if (result < 0) {
        fprintf(stderr, "%s: read failed: %s\n", argv[0], gzerror(gz, &gzerr));
      } else {
        fprintf(stderr,
                "%s: incomplete last read, file has to be a multiple of %d\n",
                argv[0], 1024);
      }
      exit(1);
    }
    if (gzrewind(gz) != 0) {
      fprintf(stderr, "%s: unable to rewind gzfile\n", argv[0]);
      exit(1);
    }
  }
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, pr)) {
    fprintf(stderr, "%s: unable to create socketpair: %s\n", argv[0],
            strerror(errno));
    exit(1);
  }
  switch (fork()) {
  case -1:
    fprintf(stderr, "%s: unable to fork: %s\n", argv[0], strerror(errno));
    exit(1);
    break;
  case 0:
    gzclose(gz);
    close(pr[0]);
    sk = pr[1];
    nbd = open(argv[1], O_RDWR);
    if (nbd < 0) {
      fprintf(stderr, "%s: unable to open %s: %s\n", argv[0], argv[1],
              strerror(errno));
      exit(1);
    }
    if (ioctl(nbd, NBD_SET_SIZE, size) < 0) {
      fprintf(stderr, "%s: failed to set size for %s: %s\n", argv[0], argv[1],
              strerror(errno));
      exit(1);
    }
    ioctl(nbd, NBD_CLEAR_SOCK);
    if (ioctl(nbd, NBD_SET_SOCK, sk) < 0) {
      fprintf(stderr, "%s: failed to set socket for %s: %s\n", argv[0], argv[1],
              strerror(errno));
      exit(1);
    }
    if (ioctl(nbd, NBD_DO_IT) < 0) {
      fprintf(stderr, "%s: block device %s terminated: %s\n", argv[0], argv[1],
              strerror(errno));
    }
    ioctl(nbd, NBD_CLEAR_QUE);
    ioctl(nbd, NBD_CLEAR_SOCK);
    exit(0);
    break;
  }
  close(pr[1]);
  sk = pr[0];
  reply.magic = htonl(NBD_REPLY_MAGIC);
  reply.error = htonl(0);
  while (1) {
    if (read(sk, &request, sizeof(request)) != sizeof(request)) {
      fprintf(stderr, "%s: incomplete request\n", argv[0]);
    }
    memcpy(reply.handle, request.handle, sizeof(reply.handle));
    len = ntohl(request.len);
    from = ntohll(request.from);
    if (request.magic != htonl(NBD_REQUEST_MAGIC)) {
      fprintf(stderr, "%s: bad magic\n", argv[0]);
      reply.error = htonl(EIO);
    }
    if (ntohl(request.type)) {
      fprintf(stderr, "%s: unsupported write request\n", argv[0]);
      reply.error = htonl(EROFS);
    }
    if (len + sizeof(struct nbd_reply) > 1024 * 20) {
      fprintf(stderr, "%s: request too long\n", argv[0]);
      reply.error = htonl(EIO);
    }
    if (len + from > size) {
      fprintf(stderr, "%s: request outside range\n", argv[0]);
      reply.error = htonl(EIO);
    }
    if (reply.error == htonl(0)) {
      gzseek(gz, from, 0);
      if (gzread(gz, chunk + sizeof(struct nbd_reply), len) != len) {
        fprintf(stderr, "%s: unable to read\n", argv[0]);
        reply.error = htonl(EIO);
        len = 0;
      }
    } else {
      len = 0;
    }
    memcpy(chunk, &reply, sizeof(struct nbd_reply));
    if (write(sk, chunk, len + sizeof(struct nbd_reply)) !=
        (len + sizeof(struct nbd_reply))) {
      fprintf(stderr, "%s: write failed: %s\n", argv[0], strerror(errno));
    }
  }
  gzclose(gz);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5540,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    12b2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd61(%rip),%rsi
call   1130 <gzopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1305 <main+0x95>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jle    139e <main+0x12e>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1140 <atol@plt>
mov    %eax,-0x506c(%rbp)
cmpl   $0x0,-0x506c(%rbp)
je     1346 <main+0xd6>
mov    -0x506c(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1376 <main+0x106>
mov    0x2c4b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
lea    0xce4(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x506c(%rbp),%ecx
lea    0xce2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    150e <main+0x29e>
movl   $0x0,-0x506c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xccd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2ba4(%rip),%rax
mov    (%rax),%edi
call   1100 <fflush@plt>
mov    -0x28(%rbp),%rdi
lea    -0x5480(%rbp),%rsi
mov    $0x400,%edx
call   10c0 <gzread@plt>
mov    %eax,%ecx
mov    %ecx,-0x5484(%rbp)
mov    $0x400,%eax
cmp    %ecx,%eax
jne    1413 <main+0x1a3>
mov    -0x506c(%rbp),%eax
add    $0x400,%eax
mov    %eax,-0x506c(%rbp)
jmp    13d3 <main+0x163>
cmpl   $0x0,-0x5484(%rbp)
jne    1439 <main+0x1c9>
mov    -0x506c(%rbp),%esi
lea    0xc54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    14ce <main+0x25e>
lea    0xc62(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x5484(%rbp)
jge    14a1 <main+0x231>
mov    0x2b3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5494(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x5490(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1110 <gzerror@plt>
mov    -0x5494(%rbp),%edi
mov    -0x5490(%rbp),%rdx
mov    %rax,%rcx
lea    0xc15(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
jmp    14c4 <main+0x254>
mov    0x2af0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc07(%rip),%rsi
mov    $0x400,%ecx
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1120 <gzrewind@plt>
cmp    $0x0,%rax
je     1509 <main+0x299>
mov    0x2ab0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc02(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
jmp    150e <main+0x29e>
mov    0x2abb(%rip),%rax
mov    (%rax),%edi
mov    0x2a6a(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rcx
xor    %edx,%edx
call   10f0 <socketpair@plt>
cmp    $0x0,%rax
je     1588 <main+0x318>
mov    0x2a5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54a4(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x54a0(%rbp)
mov    0x2a27(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x54a4(%rbp),%edi
mov    -0x54a0(%rbp),%rdx
mov    %rax,%rcx
lea    0xba0(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
xor    %eax,%eax
call   1190 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x54a8(%rbp)
sub    $0xffffffff,%eax
je     15b8 <main+0x348>
jmp    15a5 <main+0x335>
mov    -0x54a8(%rbp),%eax
test   %eax,%eax
je     160b <main+0x39b>
jmp    187c <main+0x60c>
mov    0x29d9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54b4(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x54b0(%rbp)
mov    0x29a4(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x54b4(%rbp),%edi
mov    -0x54b0(%rbp),%rdx
mov    %rax,%rcx
lea    0xb42(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <gzclose@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x29b7(%rip),%rax
mov    (%rax),%esi
call   1150 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    16ae <main+0x43e>
mov    0x294c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54cc(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x54c8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x54c0(%rbp)
mov    0x2908(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x54cc(%rbp),%edi
mov    -0x54c8(%rbp),%rdx
mov    -0x54c0(%rbp),%rcx
mov    %rax,%r8
lea    0xab7(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x20(%rbp),%edi
mov    0x28f8(%rip),%rax
mov    (%rax),%esi
mov    -0x506c(%rbp),%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
cmp    $0x0,%eax
jge    1739 <main+0x4c9>
mov    0x28c1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54e4(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x54e0(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x54d8(%rbp)
mov    0x287d(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x54e4(%rbp),%edi
mov    -0x54e0(%rbp),%rdx
mov    -0x54d8(%rbp),%rcx
mov    %rax,%r8
lea    0xa47(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x20(%rbp),%edi
mov    0x2895(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    -0x20(%rbp),%edi
mov    0x2872(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
cmp    $0x0,%eax
jge    17d4 <main+0x564>
mov    0x2826(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54fc(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x54f8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x54f0(%rbp)
mov    0x27e2(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x54fc(%rbp),%edi
mov    -0x54f8(%rbp),%rdx
mov    -0x54f0(%rbp),%rcx
mov    %rax,%r8
lea    0x9cf(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x20(%rbp),%edi
mov    0x27b2(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <ioctl@plt>
cmp    $0x0,%eax
jge    184f <main+0x5df>
mov    0x27a1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5514(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x5510(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x5508(%rbp)
mov    0x275d(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x5514(%rbp),%edi
mov    -0x5510(%rbp),%rdx
mov    -0x5508(%rbp),%rcx
mov    %rax,%r8
lea    0x96f(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x20(%rbp),%edi
mov    0x275f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    -0x20(%rbp),%edi
mov    0x276c(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <ioctl@plt>
xor    %edi,%edi
call   1160 <exit@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x26e7(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %rax,-0x5058(%rbp)
xor    %edi,%edi
call   1070 <htonl@plt>
mov    %rax,-0x5068(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x5050(%rbp),%rsi
mov    $0x20,%edx
call   10a0 <read@plt>
cltq
cmp    $0x20,%rax
je     18eb <main+0x67b>
mov    0x26c4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x8f7(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x5060(%rbp),%rdi
mov    -0x5038(%rbp),%rsi
mov    $0x8,%edx
call   10e0 <memcpy@plt>
mov    -0x5040(%rbp),%edi
call   1170 <ntohl@plt>
mov    %eax,-0x5074(%rbp)
mov    -0x5044(%rbp),%edi
call   10b0 <ntohll@plt>
mov    %eax,-0x5070(%rbp)
mov    -0x5050(%rbp),%rax
mov    %rax,-0x5520(%rbp)
mov    0x2686(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %rax,%rcx
mov    -0x5520(%rbp),%rax
cmp    %rcx,%rax
je     1987 <main+0x717>
mov    0x263d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x888(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    0x2627(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %rax,-0x5068(%rbp)
mov    -0x5048(%rbp),%edi
call   1170 <ntohl@plt>
cmp    $0x0,%eax
je     19ce <main+0x75e>
mov    0x25f6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x850(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    0x2620(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %rax,-0x5068(%rbp)
movslq -0x5074(%rbp),%rax
add    $0x18,%rax
cmp    $0x5000,%rax
jbe    1a18 <main+0x7a8>
mov    0x25ac(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x825(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    0x2596(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %rax,-0x5068(%rbp)
mov    -0x5074(%rbp),%eax
add    -0x5070(%rbp),%eax
cmp    -0x506c(%rbp),%eax
jle    1a63 <main+0x7f3>
mov    0x2561(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x7f0(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    0x254b(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %rax,-0x5068(%rbp)
mov    -0x5068(%rbp),%rax
mov    %rax,-0x5528(%rbp)
xor    %edi,%edi
call   1070 <htonl@plt>
mov    %rax,%rcx
mov    -0x5528(%rbp),%rax
cmp    %rcx,%rax
jne    1b04 <main+0x894>
mov    -0x28(%rbp),%rdi
mov    -0x5070(%rbp),%esi
xor    %edx,%edx
call   1050 <gzseek@plt>
mov    -0x28(%rbp),%rdi
lea    -0x5030(%rbp),%rsi
add    $0x18,%rsi
mov    -0x5074(%rbp),%edx
call   10c0 <gzread@plt>
cmp    -0x5074(%rbp),%eax
je     1aff <main+0x88f>
mov    0x24cf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x779(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    0x24b9(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %rax,-0x5068(%rbp)
movl   $0x0,-0x5074(%rbp)
jmp    1b0e <main+0x89e>
movl   $0x0,-0x5074(%rbp)
lea    -0x5030(%rbp),%rdi
lea    -0x5068(%rbp),%rsi
mov    $0x18,%edx
call   10e0 <memcpy@plt>
mov    -0x1c(%rbp),%edi
lea    -0x5030(%rbp),%rsi
movslq -0x5074(%rbp),%rax
add    $0x18,%rax
mov    %eax,%edx
call   1040 <write@plt>
cltq
movslq -0x5074(%rbp),%rcx
add    $0x18,%rcx
cmp    %rcx,%rax
je     1ba1 <main+0x931>
mov    0x2439(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5534(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x5530(%rbp)
mov    0x2404(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x5534(%rbp),%edi
mov    -0x5530(%rbp),%rdx
mov    %rax,%rcx
lea    0x6cc(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
jmp    18ad <main+0x63d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5068,%rsp
cmp    $0x2,%edi
jle    16c6 <main+0x446>
mov    %edi,%ebp
mov    %rsi,0x8(%rsp)
mov    0x10(%rsi),%rdi
lea    0xd76(%rip),%rsi
call   1140 <gzopen@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     16e1 <main+0x461>
cmp    $0x4,%ebp
jb     130d <main+0x8d>
mov    0x8(%rsp),%rax
mov    0x18(%rax),%rbp
mov    %rbp,%rdi
call   1150 <atol@plt>
test   %eax,%eax
je     17c8 <main+0x548>
mov    %eax,%r15d
and    $0x3ff,%eax
jne    17c8 <main+0x548>
mov    0x8(%rsp),%rbx
mov    (%rbx),%rsi
mov    0x10(%rbx),%rdx
lea    0xd76(%rip),%rdi
mov    %r15d,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1395 <main+0x115>
mov    0x8(%rsp),%rax
mov    (%rax),%rsi
mov    0x10(%rax),%rdx
lea    0xd6b(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
call   1110 <fflush@plt>
lea    0x60(%rsp),%r14
nopl   (%rax)
mov    0x10(%rsp),%rdi
mov    %r14,%rsi
mov    $0x400,%edx
call   10d0 <gzread@plt>
cmp    $0x400,%eax
jne    1362 <main+0xe2>
add    $0x400,%r15d
jmp    1340 <main+0xc0>
mov    %eax,%ebp
test   %eax,%eax
jne    1663 <main+0x3e3>
lea    0xd0e(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%rsp),%rdi
call   1130 <gzrewind@plt>
test   %rax,%rax
jne    17e5 <main+0x565>
mov    0x8(%rsp),%rbx
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
mov    0x2be3(%rip),%rax
mov    (%rax),%esi
lea    0x1c(%rsp),%rcx
xor    %edx,%edx
call   1100 <socketpair@plt>
test   %rax,%rax
jne    1702 <main+0x482>
xor    %eax,%eax
call   11a0 <fork@plt>
test   %eax,%eax
je     1728 <main+0x4a8>
cmp    $0xffffffff,%eax
je     1789 <main+0x509>
mov    0x20(%rsp),%edi
call   10a0 <close@plt>
mov    0x1c(%rsp),%ebp
mov    0x2b90(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,0x38(%rsp)
xor    %edi,%edi
call   1080 <htonl@plt>
mov    %rax,0x28(%rsp)
mov    %ebp,0x24(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
lea    0x40(%rsp),%rsi
mov    $0x20,%edx
call   10b0 <read@plt>
cmp    $0x20,%eax
mov    0x8(%rsp),%rbp
je     1446 <main+0x1c6>
mov    0x2b66(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xd94(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    0x30(%rsp),%rdi
mov    0x58(%rsp),%rsi
mov    $0x8,%edx
call   10f0 <memcpy@plt>
mov    0x50(%rsp),%edi
call   1180 <ntohl@plt>
mov    %eax,%r13d
mov    0x4c(%rsp),%edi
call   10c0 <ntohll@plt>
mov    %eax,%r14d
mov    0x40(%rsp),%rbx
mov    0x2b42(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
cmp    %rax,%rbx
je     14b8 <main+0x238>
mov    0x2b07(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xd4d(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    0x2af4(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,0x28(%rsp)
mov    0x48(%rsp),%edi
call   1180 <ntohl@plt>
test   %eax,%eax
je     14f3 <main+0x273>
mov    0x2acc(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xd21(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    0x2af9(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,0x28(%rsp)
movslq %r13d,%rax
add    $0xffffffffffffb017,%rax
cmp    $0xffffffffffffaffe,%rax
ja     1532 <main+0x2b2>
mov    0x2a8d(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xd01(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    0x2a7a(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,0x28(%rsp)
lea    (%r14,%r13,1),%eax
mov    %r15d,%r12d
cmp    %r15d,%eax
jle    1580 <main+0x300>
mov    0x2a53(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xcdd(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    0x2a40(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,%r15
mov    %rax,0x28(%rsp)
jmp    1585 <main+0x305>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x28(%rsp),%r15
xor    %ebx,%ebx
xor    %edi,%edi
call   1080 <htonl@plt>
cmp    %rax,%r15
jne    15ed <main+0x36d>
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %edx,%edx
call   1060 <gzseek@plt>
mov    %rbx,%rdi
lea    0x78(%rsp),%rsi
mov    %r13d,%edx
call   10d0 <gzread@plt>
mov    %r13d,%ebx
cmp    %r13d,%eax
je     15ed <main+0x36d>
mov    0x29d4(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
xor    %ebx,%ebx
lea    0xc77(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    0x29bf(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %rax,0x28(%rsp)
lea    0x60(%rsp),%r14
mov    %r14,%rdi
lea    0x28(%rsp),%rsi
mov    $0x18,%edx
call   10f0 <memcpy@plt>
movslq %ebx,%rbx
add    $0x18,%rbx
mov    0x24(%rsp),%ebp
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <write@plt>
cltq
cmp    %rax,%rbx
mov    %r12d,%r15d
je     1410 <main+0x190>
mov    0x2968(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%rax
mov    (%rax),%r14
mov    0x293f(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
mov    %ebx,%edi
lea    0xc0d(%rip),%rsi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10e0 <fprintf@plt>
jmp    1410 <main+0x190>
lea    0xc0a(%rip),%rdi
call   1040 <puts@plt>
mov    0x2922(%rip),%rax
mov    (%rax),%r14d
mov    0x8(%rsp),%rax
mov    (%rax),%rbx
test   %ebp,%ebp
jns    16a3 <main+0x423>
lea    0x40(%rsp),%rsi
mov    0x10(%rsp),%rdi
call   1120 <gzerror@plt>
lea    0xa07(%rip),%rsi
mov    %r14d,%edi
jmp    17b1 <main+0x531>
lea    0xa0d(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    $0x400,%ecx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    (%rsi),%rsi
lea    0x930(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    0x28b0(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rax
mov    (%rax),%rdx
mov    0x10(%rax),%rcx
lea    0x928(%rip),%rsi
jmp    17b7 <main+0x537>
mov    0x288f(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x286b(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
lea    0x9ec(%rip),%rsi
jmp    17af <main+0x52f>
mov    0x10(%rsp),%rdi
call   1030 <gzclose@plt>
mov    0x1c(%rsp),%edi
call   10a0 <close@plt>
mov    0x20(%rsp),%r14d
mov    0x8(%rbx),%rdi
mov    0x289d(%rip),%rax
mov    (%rax),%esi
call   1160 <open@plt>
test   %eax,%eax
jns    180e <main+0x58e>
mov    0x2837(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rsp),%rax
mov    (%rax),%r14
mov    0x8(%rax),%rbx
mov    0x280a(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
lea    0x9c8(%rip),%rsi
jmp    18ac <main+0x62c>
mov    0x2808(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rsp),%rax
mov    (%rax),%rbx
mov    0x27df(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
lea    0x985(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    0x27c9(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rax
mov    (%rax),%rdx
lea    0x869(%rip),%rsi
mov    %rbp,%rcx
jmp    17b7 <main+0x537>
mov    0x27ac(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rax
mov    (%rax),%rdx
lea    0x8f5(%rip),%rsi
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    %eax,%ebp
mov    0x2799(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r15d,%edx
xor    %eax,%eax
call   1090 <ioctl@plt>
test   %eax,%eax
jns    1855 <main+0x5d5>
mov    0x2768(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rsp),%rax
mov    (%rax),%r14
mov    0x8(%rax),%rbx
mov    0x273b(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
lea    0x914(%rip),%rsi
jmp    18ac <main+0x62c>
mov    0x277c(%rip),%r12
mov    (%r12),%esi
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <ioctl@plt>
mov    0x2758(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14d,%edx
xor    %eax,%eax
call   1090 <ioctl@plt>
test   %eax,%eax
jns    18c8 <main+0x648>
mov    0x270f(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rsp),%rax
mov    (%rax),%r14
mov    0x8(%rax),%rbx
mov    0x26e2(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
lea    0x8de(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    0x26c1(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <ioctl@plt>
test   %eax,%eax
jns    191c <main+0x69c>
mov    0x26b3(%rip),%rax
mov    (%rax),%r14d
mov    0x8(%rsp),%rax
mov    (%rax),%r15
mov    0x8(%rax),%rbx
mov    0x2685(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
lea    0x8a6(%rip),%rsi
mov    %r14d,%edi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   10e0 <fprintf@plt>
mov    0x2695(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <ioctl@plt>
mov    (%r12),%esi
mov    %ebp,%edi
xor    %eax,%eax
call   1090 <ioctl@plt>
xor    %edi,%edi
call   1170 <exit@plt>

LLVM IR (-O0):
%struct.nbd_request = type { i64, i32, i32, i32, %struct.nbd_reply* }
%struct.nbd_reply = type { i64, i8*, i64 }
@.str = [34 x i8] c"Usage: %s nbdevice gzfile [size]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"%s: unable open compressed file %s\0A\00"
@.str.3 = [43 x i8] c"%s: %s does not appear to be a valid size\0A\00"
@.str.4 = [23 x i8] c"%s: file=%s, size=%Ld\0A\00"
@.str.5 = [23 x i8] c"%s: file=%s, seeking, \00"
@stdout = global i32 0
@.str.6 = [10 x i8] c"size=%Ld\0A\00"
@.str.7 = [8 x i8] c"failed\0A\00"
@.str.8 = [21 x i8] c"%s: read failed: %s\0A\00"
@.str.9 = [59 x i8] c"%s: incomplete last read, file has to be a multiple of %d\0A\00"
@.str.10 = [29 x i8] c"%s: unable to rewind gzfile\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.11 = [37 x i8] c"%s: unable to create socketpair: %s\0A\00"
@errno = global i32 0
@.str.12 = [24 x i8] c"%s: unable to fork: %s\0A\00"
@O_RDWR = global i32 0
@.str.13 = [27 x i8] c"%s: unable to open %s: %s\0A\00"
@NBD_SET_SIZE = global i32 0
@.str.14 = [35 x i8] c"%s: failed to set size for %s: %s\0A\00"
@NBD_CLEAR_SOCK = global i32 0
@NBD_SET_SOCK = global i32 0
@.str.15 = [37 x i8] c"%s: failed to set socket for %s: %s\0A\00"
@NBD_DO_IT = global i32 0
@.str.16 = [36 x i8] c"%s: block device %s terminated: %s\0A\00"
@NBD_CLEAR_QUE = global i32 0
@NBD_REPLY_MAGIC = global i32 0
@.str.17 = [24 x i8] c"%s: incomplete request\0A\00"
@NBD_REQUEST_MAGIC = global i32 0
@.str.18 = [15 x i8] c"%s: bad magic\0A\00"
@EIO = global i32 0
@.str.19 = [31 x i8] c"%s: unsupported write request\0A\00"
@EROFS = global i32 0
@.str.20 = [22 x i8] c"%s: request too long\0A\00"
@.str.21 = [27 x i8] c"%s: request outside range\0A\00"
@.str.22 = [20 x i8] c"%s: unable to read\0A\00"
@.str.23 = [22 x i8] c"%s: write failed: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [20480 x i8]
%12 = alloca %struct.nbd_request
%13 = alloca %struct.nbd_reply
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [1024 x i8]
%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 slt i32 %19, 3
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32* @gzopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %9
%32 = load i32*, i32** %9
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %44
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %38, i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %27
%45 = load i32, i32* %4
%46 = icmp sgt i32 %45, 3
br i1 %46, label %47, label %77
47: ; preds = %44
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 3
%50 = load i8*, i8** %49
%51 = call i32 @atol(i8* %50)
store i32 %51, i32* %14
%52 = load i32, i32* %14
%53 = icmp eq i32 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %47
%55 = load i32, i32* %14
%56 = srem i32 %55, 1024
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %68
58: ; preds = %54, %47
%59 = load i32, i32* @stderr
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 0
%62 = load i8*, i8** %61
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 3
%65 = load i8*, i8** %64
%66 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %62, i8* %65)
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %54
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 2
%74 = load i8*, i8** %73
%75 = load i32, i32* %14
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %71, i8* %74, i32 %75)
br label %133
77: ; preds = %44
store i32 0, i32* %14
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 0
%80 = load i8*, i8** %79
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 2
%83 = load i8*, i8** %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %80, i8* %83)
%85 = load i32, i32* @stdout
%86 = call i32 @fflush(i32 %85)
br label %87
87: ; preds = %92, %77
%88 = load i32*, i32** %9
%89 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%90 = call i32 @gzread(i32* %88, i8* %89, i32 1024)
store i32 %90, i32* %18
%91 = icmp eq i32 1024, %90
br i1 %91, label %92, label %95
92: ; preds = %87
%93 = load i32, i32* %14
%94 = add nsw i32 %93, 1024
store i32 %94, i32* %14
br label %87
95: ; preds = %87
%96 = load i32, i32* %18
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = load i32, i32* %14
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %99)
br label %121
101: ; preds = %95
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%103 = load i32, i32* %18
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %113
105: ; preds = %101
%106 = load i32, i32* @stderr
%107 = load i8**, i8*** %5
%108 = getelementptr inbounds i8*, i8** %107, i64 0
%109 = load i8*, i8** %108
%110 = load i32*, i32** %9
%111 = call i8* @gzerror(i32* %110, i32* %10)
%112 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %109, i8* %111)
br label %119
113: ; preds = %101
%114 = load i32, i32* @stderr
%115 = load i8**, i8*** %5
%116 = getelementptr inbounds i8*, i8** %115, i64 0
%117 = load i8*, i8** %116
%118 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.9, i64 0, i64 0), i8* %117, i32 1024)
br label %119
119: ; preds = %113, %105
%120 = call i32 @exit(i32 1)
unreachable
121: ; preds = %98
%122 = load i32*, i32** %9
%123 = call i64 @gzrewind(i32* %122)
%124 = icmp ne i64 %123, 0
br i1 %124, label %125, label %132
125: ; preds = %121
%126 = load i32, i32* @stderr
%127 = load i8**, i8*** %5
%128 = getelementptr inbounds i8*, i8** %127, i64 0
%129 = load i8*, i8** %128
%130 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %129)
%131 = call i32 @exit(i32 1)
unreachable
132: ; preds = %121
br label %133
133: ; preds = %132, %68
%134 = load i32, i32* @AF_UNIX
%135 = load i32, i32* @SOCK_STREAM
%136 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%137 = call i64 @socketpair(i32 %134, i32 %135, i32 0, i32* %136)
%138 = icmp ne i64 %137, 0
br i1 %138, label %139, label %148
139: ; preds = %133
%140 = load i32, i32* @stderr
%141 = load i8**, i8*** %5
%142 = getelementptr inbounds i8*, i8** %141, i64 0
%143 = load i8*, i8** %142
%144 = load i32, i32* @errno
%145 = call i8* @strerror(i32 %144)
%146 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %140, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0), i8* %143, i8* %145)
%147 = call i32 @exit(i32 1)
unreachable
148: ; preds = %133
%149 = call i32 (...) @fork()
switch i32 %149, label %249 [
i32 -1, label %150
i32 0, label %159
]
150: ; preds = %148
%151 = load i32, i32* @stderr
%152 = load i8**, i8*** %5
%153 = getelementptr inbounds i8*, i8** %152, i64 0
%154 = load i8*, i8** %153
%155 = load i32, i32* @errno
%156 = call i8* @strerror(i32 %155)
%157 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %151, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i8* %154, i8* %156)
%158 = call i32 @exit(i32 1)
unreachable
159: ; preds = %148
%160 = load i32*, i32** %9
%161 = call i32 @gzclose(i32* %160)
%162 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%163 = load i32, i32* %162
%164 = call i32 @close(i32 %163)
%165 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%166 = load i32, i32* %165
store i32 %166, i32* %7
%167 = load i8**, i8*** %5
%168 = getelementptr inbounds i8*, i8** %167, i64 1
%169 = load i8*, i8** %168
%170 = load i32, i32* @O_RDWR
%171 = call i32 @open(i8* %169, i32 %170)
store i32 %171, i32* %8
%172 = load i32, i32* %8
%173 = icmp slt i32 %172, 0
br i1 %173, label %174, label %186
174: ; preds = %159
%175 = load i32, i32* @stderr
%176 = load i8**, i8*** %5
%177 = getelementptr inbounds i8*, i8** %176, i64 0
%178 = load i8*, i8** %177
%179 = load i8**, i8*** %5
%180 = getelementptr inbounds i8*, i8** %179, i64 1
%181 = load i8*, i8** %180
%182 = load i32, i32* @errno
%183 = call i8* @strerror(i32 %182)
%184 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %175, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i8* %178, i8* %181, i8* %183)
%185 = call i32 @exit(i32 1)
unreachable
186: ; preds = %159
%187 = load i32, i32* %8
%188 = load i32, i32* @NBD_SET_SIZE
%189 = load i32, i32* %14
%190 = call i32 (i32, i32, ...) @ioctl(i32 %187, i32 %188, i32 %189)
%191 = icmp slt i32 %190, 0
br i1 %191, label %192, label %204
192: ; preds = %186
%193 = load i32, i32* @stderr
%194 = load i8**, i8*** %5
%195 = getelementptr inbounds i8*, i8** %194, i64 0
%196 = load i8*, i8** %195
%197 = load i8**, i8*** %5
%198 = getelementptr inbounds i8*, i8** %197, i64 1
%199 = load i8*, i8** %198
%200 = load i32, i32* @errno
%201 = call i8* @strerror(i32 %200)
%202 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %193, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0), i8* %196, i8* %199, i8* %201)
%203 = call i32 @exit(i32 1)
unreachable
204: ; preds = %186
%205 = load i32, i32* %8
%206 = load i32, i32* @NBD_CLEAR_SOCK
%207 = call i32 (i32, i32, ...) @ioctl(i32 %205, i32 %206)
%208 = load i32, i32* %8
%209 = load i32, i32* @NBD_SET_SOCK
%210 = load i32, i32* %7
%211 = call i32 (i32, i32, ...) @ioctl(i32 %208, i32 %209, i32 %210)
%212 = icmp slt i32 %211, 0
br i1 %212, label %213, label %225
213: ; preds = %204
%214 = load i32, i32* @stderr
%215 = load i8**, i8*** %5
%216 = getelementptr inbounds i8*, i8** %215, i64 0
%217 = load i8*, i8** %216
%218 = load i8**, i8*** %5
%219 = getelementptr inbounds i8*, i8** %218, i64 1
%220 = load i8*, i8** %219
%221 = load i32, i32* @errno
%222 = call i8* @strerror(i32 %221)
%223 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %214, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.15, i64 0, i64 0), i8* %217, i8* %220, i8* %222)
%224 = call i32 @exit(i32 1)
unreachable
225: ; preds = %204
%226 = load i32, i32* %8
%227 = load i32, i32* @NBD_DO_IT
%228 = call i32 (i32, i32, ...) @ioctl(i32 %226, i32 %227)
%229 = icmp slt i32 %228, 0
br i1 %229, label %230, label %241
230: ; preds = %225
%231 = load i32, i32* @stderr
%232 = load i8**, i8*** %5
%233 = getelementptr inbounds i8*, i8** %232, i64 0
%234 = load i8*, i8** %233
%235 = load i8**, i8*** %5
%236 = getelementptr inbounds i8*, i8** %235, i64 1
%237 = load i8*, i8** %236
%238 = load i32, i32* @errno
%239 = call i8* @strerror(i32 %238)
%240 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %231, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.16, i64 0, i64 0), i8* %234, i8* %237, i8* %239)
br label %241
241: ; preds = %230, %225
%242 = load i32, i32* %8
%243 = load i32, i32* @NBD_CLEAR_QUE
%244 = call i32 (i32, i32, ...) @ioctl(i32 %242, i32 %243)
%245 = load i32, i32* %8
%246 = load i32, i32* @NBD_CLEAR_SOCK
%247 = call i32 (i32, i32, ...) @ioctl(i32 %245, i32 %246)
%248 = call i32 @exit(i32 0)
unreachable
249: ; preds = %148
%250 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%251 = load i32, i32* %250
%252 = call i32 @close(i32 %251)
%253 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%254 = load i32, i32* %253
store i32 %254, i32* %7
%255 = load i32, i32* @NBD_REPLY_MAGIC
%256 = call i64 @htonl(i32 %255)
%257 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %13, i32 0, i32 2
store i64 %256, i64* %257
%258 = call i64 @htonl(i32 0)
%259 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %13, i32 0, i32 0
store i64 %258, i64* %259
br label %260
260: ; preds = %249, %390
%261 = load i32, i32* %7
%262 = call i32 @read(i32 %261, %struct.nbd_request* %12, i32 32)
%263 = sext i32 %262 to i64
%264 = icmp ne i64 %263, 32
br i1 %264, label %265, label %271
265: ; preds = %260
%266 = load i32, i32* @stderr
%267 = load i8**, i8*** %5
%268 = getelementptr inbounds i8*, i8** %267, i64 0
%269 = load i8*, i8** %268
%270 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %266, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.17, i64 0, i64 0), i8* %269)
br label %271
271: ; preds = %265, %260
%272 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %13, i32 0, i32 1
%273 = load i8*, i8** %272
%274 = getelementptr inbounds %struct.nbd_request, %struct.nbd_request* %12, i32 0, i32 4
%275 = load %struct.nbd_reply*, %struct.nbd_reply** %274
%276 = call i32 @memcpy(i8* %273, %struct.nbd_reply* %275, i32 8)
%277 = getelementptr inbounds %struct.nbd_request, %struct.nbd_request* %12, i32 0, i32 3
%278 = load i32, i32* %277
%279 = call i32 @ntohl(i32 %278)
store i32 %279, i32* %16
%280 = getelementptr inbounds %struct.nbd_request, %struct.nbd_request* %12, i32 0, i32 2
%281 = load i32, i32* %280
%282 = call i32 @ntohll(i32 %281)
store i32 %282, i32* %15
%283 = getelementptr inbounds %struct.nbd_request, %struct.nbd_request* %12, i32 0, i32 0
%284 = load i64, i64* %283
%285 = load i32, i32* @NBD_REQUEST_MAGIC
%286 = call i64 @htonl(i32 %285)
%287 = icmp ne i64 %284, %286
br i1 %287, label %288, label %297
288: ; preds = %271
%289 = load i32, i32* @stderr
%290 = load i8**, i8*** %5
%291 = getelementptr inbounds i8*, i8** %290, i64 0
%292 = load i8*, i8** %291
%293 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %289, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.18, i64 0, i64 0), i8* %292)
%294 = load i32, i32* @EIO
%295 = call i64 @htonl(i32 %294)
%296 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %13, i32 0, i32 0
store i64 %295, i64* %296
br label %297
297: ; preds = %288, %271
%298 = getelementptr inbounds %struct.nbd_request, %struct.nbd_request* %12, i32 0, i32 1
%299 = load i32, i32* %298
%300 = call i32 @ntohl(i32 %299)
%301 = icmp ne i32 %300, 0
br i1 %301, label %302, label %311
302: ; preds = %297
%303 = load i32, i32* @stderr
%304 = load i8**, i8*** %5
%305 = getelementptr inbounds i8*, i8** %304, i64 0
%306 = load i8*, i8** %305
%307 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %303, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.19, i64 0, i64 0), i8* %306)
%308 = load i32, i32* @EROFS
%309 = call i64 @htonl(i32 %308)
%310 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %13, i32 0, i32 0
store i64 %309, i64* %310
br label %311
311: ; preds = %302, %297
%312 = load i32, i32* %16
%313 = sext i32 %312 to i64
%314 = add i64 %313, 24
%315 = icmp ugt i64 %314, 20480
br i1 %315, label %316, label %325
316: ; preds = %311
%317 = load i32, i32* @stderr
%318 = load i8**, i8*** %5
%319 = getelementptr inbounds i8*, i8** %318, i64 0
%320 = load i8*, i8** %319
%321 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %317, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.20, i64 0, i64 0), i8* %320)
%322 = load i32, i32* @EIO
%323 = call i64 @htonl(i32 %322)
%324 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %13, i32 0, i32 0
store i64 %323, i64* %324
br label %325
325: ; preds = %316, %311
%326 = load i32, i32* %16
%327 = load i32, i32* %15
%328 = add nsw i32 %326, %327
%329 = load i32, i32* %14
%330 = icmp sgt i32 %328, %329
br i1 %330, label %331, label %340
331: ; preds = %325
%332 = load i32, i32* @stderr
%333 = load i8**, i8*** %5
%334 = getelementptr inbounds i8*, i8** %333, i64 0
%335 = load i8*, i8** %334
%336 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %332, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.21, i64 0, i64 0), i8* %335)
%337 = load i32, i32* @EIO
%338 = call i64 @htonl(i32 %337)
%339 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %13, i32 0, i32 0
store i64 %338, i64* %339
br label %340
340: ; preds = %331, %325
%341 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %13, i32 0, i32 0
%342 = load i64, i64* %341
%343 = call i64 @htonl(i32 0)
%344 = icmp eq i64 %342, %343
br i1 %344, label %345, label %366
345: ; preds = %340
%346 = load i32*, i32** %9
%347 = load i32, i32* %15
%348 = call i32 @gzseek(i32* %346, i32 %347, i32 0)
%349 = load i32*, i32** %9
%350 = getelementptr inbounds [20480 x i8], [20480 x i8]* %11, i64 0, i64 0
%351 = getelementptr inbounds i8, i8* %350, i64 24
%352 = load i32, i32* %16
%353 = call i32 @gzread(i32* %349, i8* %351, i32 %352)
%354 = load i32, i32* %16
%355 = icmp ne i32 %353, %354
br i1 %355, label %356, label %365
356: ; preds = %345
%357 = load i32, i32* @stderr
%358 = load i8**, i8*** %5
%359 = getelementptr inbounds i8*, i8** %358, i64 0
%360 = load i8*, i8** %359
%361 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %357, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.22, i64 0, i64 0), i8* %360)
%362 = load i32, i32* @EIO
%363 = call i64 @htonl(i32 %362)
%364 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %13, i32 0, i32 0
store i64 %363, i64* %364
store i32 0, i32* %16
br label %365
365: ; preds = %356, %345
br label %367
366: ; preds = %340
store i32 0, i32* %16
br label %367
367: ; preds = %366, %365
%368 = getelementptr inbounds [20480 x i8], [20480 x i8]* %11, i64 0, i64 0
%369 = call i32 @memcpy(i8* %368, %struct.nbd_reply* %13, i32 24)
%370 = load i32, i32* %7
%371 = getelementptr inbounds [20480 x i8], [20480 x i8]* %11, i64 0, i64 0
%372 = load i32, i32* %16
%373 = sext i32 %372 to i64
%374 = add i64 %373, 24
%375 = trunc i64 %374 to i32
%376 = call i32 @write(i32 %370, i8* %371, i32 %375)
%377 = sext i32 %376 to i64
%378 = load i32, i32* %16
%379 = sext i32 %378 to i64
%380 = add i64 %379, 24
%381 = icmp ne i64 %377, %380
br i1 %381, label %382, label %390
382: ; preds = %367
%383 = load i32, i32* @stderr
%384 = load i8**, i8*** %5
%385 = getelementptr inbounds i8*, i8** %384, i64 0
%386 = load i8*, i8** %385
%387 = load i32, i32* @errno
%388 = call i8* @strerror(i32 %387)
%389 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %383, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.23, i64 0, i64 0), i8* %386, i8* %388)
br label %390
390: ; preds = %382, %367
br label %260
}

LLVM IR (-O2):
%struct.nbd_request = type { i64, i32, i32, i32, %struct.nbd_reply* }
%struct.nbd_reply = type { i64, i8*, i64 }
@.str = [34 x i8] c"Usage: %s nbdevice gzfile [size]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"%s: unable open compressed file %s\0A\00"
@.str.3 = [43 x i8] c"%s: %s does not appear to be a valid size\0A\00"
@.str.4 = [23 x i8] c"%s: file=%s, size=%Ld\0A\00"
@.str.5 = [23 x i8] c"%s: file=%s, seeking, \00"
@stdout = global i32 0
@.str.6 = [10 x i8] c"size=%Ld\0A\00"
@.str.8 = [21 x i8] c"%s: read failed: %s\0A\00"
@.str.9 = [59 x i8] c"%s: incomplete last read, file has to be a multiple of %d\0A\00"
@.str.10 = [29 x i8] c"%s: unable to rewind gzfile\0A\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str.11 = [37 x i8] c"%s: unable to create socketpair: %s\0A\00"
@errno = global i32 0
@.str.12 = [24 x i8] c"%s: unable to fork: %s\0A\00"
@O_RDWR = global i32 0
@.str.13 = [27 x i8] c"%s: unable to open %s: %s\0A\00"
@NBD_SET_SIZE = global i32 0
@.str.14 = [35 x i8] c"%s: failed to set size for %s: %s\0A\00"
@NBD_CLEAR_SOCK = global i32 0
@NBD_SET_SOCK = global i32 0
@.str.15 = [37 x i8] c"%s: failed to set socket for %s: %s\0A\00"
@NBD_DO_IT = global i32 0
@.str.16 = [36 x i8] c"%s: block device %s terminated: %s\0A\00"
@NBD_CLEAR_QUE = global i32 0
@NBD_REPLY_MAGIC = global i32 0
@.str.17 = [24 x i8] c"%s: incomplete request\0A\00"
@NBD_REQUEST_MAGIC = global i32 0
@.str.18 = [15 x i8] c"%s: bad magic\0A\00"
@EIO = global i32 0
@.str.19 = [31 x i8] c"%s: unsupported write request\0A\00"
@EROFS = global i32 0
@.str.20 = [22 x i8] c"%s: request too long\0A\00"
@.str.21 = [27 x i8] c"%s: request outside range\0A\00"
@.str.22 = [20 x i8] c"%s: unable to read\0A\00"
@.str.23 = [22 x i8] c"%s: write failed: %s\0A\00"
@str = [7 x i8] c"failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca [20480 x i8]
%6 = alloca %struct.nbd_request
%7 = alloca %struct.nbd_reply
%8 = alloca [1024 x i8]
%9 = bitcast [2 x i32]* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = getelementptr inbounds [20480 x i8], [20480 x i8]* %5, i64 0, i64 0
%12 = bitcast %struct.nbd_request* %6 to i8*
%13 = bitcast %struct.nbd_reply* %7 to i8*
%14 = icmp slt i32 %0, 3
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8*, i8** %1
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32* @gzopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = load i8*, i8** %20
%28 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %27)
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %19
%31 = icmp ugt i32 %0, 3
br i1 %31, label %32, label %49
32: ; preds = %30
%33 = getelementptr inbounds i8*, i8** %1, i64 3
%34 = load i8*, i8** %33
%35 = tail call i32 @atol(i8* %34)
%36 = icmp ne i32 %35, 0
%37 = and i32 %35, 1023
%38 = icmp eq i32 %37, 0
%39 = and i1 %36, %38
br i1 %39, label %45, label %40
40: ; preds = %32
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %1
%43 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %42, i8* %34)
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %32
%46 = load i8*, i8** %1
%47 = load i8*, i8** %20
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %46, i8* %47, i32 %35)
br label %83
49: ; preds = %30
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%51 = load i8*, i8** %1
%52 = load i8*, i8** %20
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %51, i8* %52)
%54 = load i32, i32* @stdout
%55 = tail call i32 @fflush(i32 %54)
br label %56
56: ; preds = %59, %49
%57 = phi i32 [ 0, %49 ], [ %60, %59 ]
%58 = call i32 @gzread(i32* %22, i8* %50, i32 1024)
switch i32 %58, label %65 [
i32 1024, label %59
i32 0, label %61
]
59: ; preds = %56
%60 = add nuw nsw i32 %57, 1024
br label %56
61: ; preds = %56
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %57)
%63 = call i64 @gzrewind(i32* %22)
%64 = icmp eq i64 %63, 0
br i1 %64, label %82, label %77
65: ; preds = %56
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%67 = icmp slt i32 %58, 0
%68 = load i32, i32* @stderr
%69 = load i8*, i8** %1
br i1 %67, label %70, label %73
70: ; preds = %65
%71 = call i8* @gzerror(i32* %22, i32* %4)
%72 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %69, i8* %71)
br label %75
73: ; preds = %65
%74 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.9, i64 0, i64 0), i8* %69, i32 1024)
br label %75
75: ; preds = %73, %70
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %61
%78 = load i32, i32* @stderr
%79 = load i8*, i8** %1
%80 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %79)
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %61
br label %83
83: ; preds = %82, %45
%84 = phi i32 [ %35, %45 ], [ %57, %82 ]
%85 = load i32, i32* @AF_UNIX
%86 = load i32, i32* @SOCK_STREAM
%87 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%88 = call i64 @socketpair(i32 %85, i32 %86, i32 0, i32* %87)
%89 = icmp eq i64 %88, 0
br i1 %89, label %97, label %90
90: ; preds = %83
%91 = load i32, i32* @stderr
%92 = load i8*, i8** %1
%93 = load i32, i32* @errno
%94 = call i8* @strerror(i32 %93)
%95 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0), i8* %92, i8* %94)
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %83
%98 = call i32 (...) @fork()
switch i32 %98, label %168 [
i32 -1, label %99
i32 0, label %106
]
99: ; preds = %97
%100 = load i32, i32* @stderr
%101 = load i8*, i8** %1
%102 = load i32, i32* @errno
%103 = call i8* @strerror(i32 %102)
%104 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i8* %101, i8* %103)
%105 = call i32 @exit(i32 1)
unreachable
106: ; preds = %97
%107 = call i32 @gzclose(i32* %22)
%108 = load i32, i32* %87
%109 = call i32 @close(i32 %108)
%110 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%111 = load i32, i32* %110
%112 = getelementptr inbounds i8*, i8** %1, i64 1
%113 = load i8*, i8** %112
%114 = load i32, i32* @O_RDWR
%115 = call i32 @open(i8* %113, i32 %114)
%116 = icmp slt i32 %115, 0
br i1 %116, label %117, label %125
117: ; preds = %106
%118 = load i32, i32* @stderr
%119 = load i8*, i8** %1
%120 = load i8*, i8** %112
%121 = load i32, i32* @errno
%122 = call i8* @strerror(i32 %121)
%123 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), i8* %119, i8* %120, i8* %122)
%124 = call i32 @exit(i32 1)
unreachable
125: ; preds = %106
%126 = load i32, i32* @NBD_SET_SIZE
%127 = call i32 (i32, i32, ...) @ioctl(i32 %115, i32 %126, i32 %84)
%128 = icmp slt i32 %127, 0
br i1 %128, label %129, label %137
129: ; preds = %125
%130 = load i32, i32* @stderr
%131 = load i8*, i8** %1
%132 = load i8*, i8** %112
%133 = load i32, i32* @errno
%134 = call i8* @strerror(i32 %133)
%135 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0), i8* %131, i8* %132, i8* %134)
%136 = call i32 @exit(i32 1)
unreachable
137: ; preds = %125
%138 = load i32, i32* @NBD_CLEAR_SOCK
%139 = call i32 (i32, i32, ...) @ioctl(i32 %115, i32 %138)
%140 = load i32, i32* @NBD_SET_SOCK
%141 = call i32 (i32, i32, ...) @ioctl(i32 %115, i32 %140, i32 %111)
%142 = icmp slt i32 %141, 0
br i1 %142, label %143, label %151
143: ; preds = %137
%144 = load i32, i32* @stderr
%145 = load i8*, i8** %1
%146 = load i8*, i8** %112
%147 = load i32, i32* @errno
%148 = call i8* @strerror(i32 %147)
%149 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %144, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.15, i64 0, i64 0), i8* %145, i8* %146, i8* %148)
%150 = call i32 @exit(i32 1)
unreachable
151: ; preds = %137
%152 = load i32, i32* @NBD_DO_IT
%153 = call i32 (i32, i32, ...) @ioctl(i32 %115, i32 %152)
%154 = icmp slt i32 %153, 0
br i1 %154, label %155, label %162
155: ; preds = %151
%156 = load i32, i32* @stderr
%157 = load i8*, i8** %1
%158 = load i8*, i8** %112
%159 = load i32, i32* @errno
%160 = call i8* @strerror(i32 %159)
%161 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.16, i64 0, i64 0), i8* %157, i8* %158, i8* %160)
br label %162
162: ; preds = %155, %151
%163 = load i32, i32* @NBD_CLEAR_QUE
%164 = call i32 (i32, i32, ...) @ioctl(i32 %115, i32 %163)
%165 = load i32, i32* @NBD_CLEAR_SOCK
%166 = call i32 (i32, i32, ...) @ioctl(i32 %115, i32 %165)
%167 = call i32 @exit(i32 0)
unreachable
168: ; preds = %97
%169 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%170 = load i32, i32* %169
%171 = call i32 @close(i32 %170)
%172 = load i32, i32* %87
%173 = load i32, i32* @NBD_REPLY_MAGIC
%174 = call i64 @htonl(i32 %173)
%175 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %7, i64 0, i32 2
store i64 %174, i64* %175
%176 = call i64 @htonl(i32 0)
%177 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %7, i64 0, i32 0
store i64 %176, i64* %177
%178 = getelementptr inbounds %struct.nbd_reply, %struct.nbd_reply* %7, i64 0, i32 1
%179 = getelementptr inbounds %struct.nbd_request, %struct.nbd_request* %6, i64 0, i32 4
%180 = getelementptr inbounds %struct.nbd_request, %struct.nbd_request* %6, i64 0, i32 3
%181 = getelementptr inbounds %struct.nbd_request, %struct.nbd_request* %6, i64 0, i32 2
%182 = getelementptr inbounds %struct.nbd_request, %struct.nbd_request* %6, i64 0, i32 0
%183 = getelementptr inbounds %struct.nbd_request, %struct.nbd_request* %6, i64 0, i32 1
%184 = getelementptr inbounds [20480 x i8], [20480 x i8]* %5, i64 0, i64 24
br label %185
185: ; preds = %270, %168
%186 = call i32 @read(i32 %172, %struct.nbd_request* %6, i32 32)
%187 = icmp eq i32 %186, 32
br i1 %187, label %192, label %188
188: ; preds = %185
%189 = load i32, i32* @stderr
%190 = load i8*, i8** %1
%191 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %189, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.17, i64 0, i64 0), i8* %190)
br label %192
192: ; preds = %188, %185
%193 = load i8*, i8** %178
%194 = load %struct.nbd_reply*, %struct.nbd_reply** %179
%195 = call i32 @memcpy(i8* %193, %struct.nbd_reply* %194, i32 8)
%196 = load i32, i32* %180
%197 = call i32 @ntohl(i32 %196)
%198 = load i32, i32* %181
%199 = call i32 @ntohll(i32 %198)
%200 = load i64, i64* %182
%201 = load i32, i32* @NBD_REQUEST_MAGIC
%202 = call i64 @htonl(i32 %201)
%203 = icmp eq i64 %200, %202
br i1 %203, label %210, label %204
204: ; preds = %192
%205 = load i32, i32* @stderr
%206 = load i8*, i8** %1
%207 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %205, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.18, i64 0, i64 0), i8* %206)
%208 = load i32, i32* @EIO
%209 = call i64 @htonl(i32 %208)
store i64 %209, i64* %177
br label %210
210: ; preds = %204, %192
%211 = load i32, i32* %183
%212 = call i32 @ntohl(i32 %211)
%213 = icmp eq i32 %212, 0
br i1 %213, label %220, label %214
214: ; preds = %210
%215 = load i32, i32* @stderr
%216 = load i8*, i8** %1
%217 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %215, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.19, i64 0, i64 0), i8* %216)
%218 = load i32, i32* @EROFS
%219 = call i64 @htonl(i32 %218)
store i64 %219, i64* %177
br label %220
220: ; preds = %214, %210
%221 = sext i32 %197 to i64
%222 = add nsw i64 %221, -20457
%223 = icmp ult i64 %222, -20481
br i1 %223, label %224, label %230
224: ; preds = %220
%225 = load i32, i32* @stderr
%226 = load i8*, i8** %1
%227 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %225, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.20, i64 0, i64 0), i8* %226)
%228 = load i32, i32* @EIO
%229 = call i64 @htonl(i32 %228)
store i64 %229, i64* %177
br label %230
230: ; preds = %224, %220
%231 = add nsw i32 %199, %197
%232 = icmp sgt i32 %231, %84
br i1 %232, label %235, label %233
233: ; preds = %230
%234 = load i64, i64* %177
br label %241
235: ; preds = %230
%236 = load i32, i32* @stderr
%237 = load i8*, i8** %1
%238 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %236, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.21, i64 0, i64 0), i8* %237)
%239 = load i32, i32* @EIO
%240 = call i64 @htonl(i32 %239)
store i64 %240, i64* %177
br label %241
241: ; preds = %233, %235
%242 = phi i64 [ %234, %233 ], [ %240, %235 ]
%243 = call i64 @htonl(i32 0)
%244 = icmp eq i64 %242, %243
br i1 %244, label %245, label %255
245: ; preds = %241
%246 = call i32 @gzseek(i32* %22, i32 %199, i32 0)
%247 = call i32 @gzread(i32* %22, i8* %184, i32 %197)
%248 = icmp eq i32 %247, %197
br i1 %248, label %255, label %249
249: ; preds = %245
%250 = load i32, i32* @stderr
%251 = load i8*, i8** %1
%252 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %250, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.22, i64 0, i64 0), i8* %251)
%253 = load i32, i32* @EIO
%254 = call i64 @htonl(i32 %253)
store i64 %254, i64* %177
br label %255
255: ; preds = %241, %245, %249
%256 = phi i32 [ 0, %249 ], [ %197, %245 ], [ 0, %241 ]
%257 = call i32 @memcpy(i8* %11, %struct.nbd_reply* %7, i32 24)
%258 = sext i32 %256 to i64
%259 = add nsw i64 %258, 24
%260 = trunc i64 %259 to i32
%261 = call i32 @write(i32 %172, i8* %11, i32 %260)
%262 = sext i32 %261 to i64
%263 = icmp eq i64 %259, %262
br i1 %263, label %270, label %264
264: ; preds = %255
%265 = load i32, i32* @stderr
%266 = load i8*, i8** %1
%267 = load i32, i32* @errno
%268 = call i8* @strerror(i32 %267)
%269 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %265, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.23, i64 0, i64 0), i8* %266, i8* %268)
br label %270
270: ; preds = %264, %255
br label %185
}