#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 stat {
  int st_size;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ bootsector;

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_END;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
char getopt(int, char **, char *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
unsigned char *malloc(size_t);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, size_t);
int open(char *, int, ...);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int stat(char *, struct stat *);
int /*<<< orphan*/ usage(char const *);
int /*<<< orphan*/ write(int, unsigned char *, size_t);
int main(int argc, char *argv[]) {
  struct stat st;
  int err;
  unsigned int blocks;
  unsigned char bootsector[1024];
  unsigned char buf[512];
  size_t read_size;
  size_t written_bytes;
  int padding;
  int enable_vesa;
  int vesa_x, vesa_y, vesa_bit;
  int infd;
  int outfd;
  signed char opt;
  char const *progname;
  padding = 0;
  progname = argv[0];
  enable_vesa = 0;
  vesa_x = 640;
  vesa_y = 480;
  vesa_bit = 16;
  while ((opt = getopt(argc, argv, "p:vx:y:d:")) != -1)
    switch (opt) {
    case 'p':
      padding = atoi(optarg);
      if (padding < 0) {
        usage(progname);
        return -1;
      }
      break;
    case 'v':
      enable_vesa = 1;
      break;
    case 'x':
      vesa_x = atoi(optarg);
      if (vesa_x < 0) {
        usage(progname);
        return -1;
      }
      break;
    case 'y':
      vesa_y = atoi(optarg);
      if (vesa_y < 0) {
        usage(progname);
        return -1;
      }
      break;
    case 'd':
      vesa_bit = atoi(optarg);
      if (vesa_bit < 0) {
        usage(progname);
        return -1;
      }
      break;
    case '?':
    default:
      usage(progname);
      return -1;
    }
  argc -= optind - 1;
  argv += optind - 1;
  if (argc < 4) {
    printf("insufficient args\n");
    usage(progname);
    return -1;
  }
  err = stat(argv[2], &st);
  if (err < 0) {
    printf("error stating file '%s'\n", argv[2]);
    return -1;
  }
  outfd = open(argv[3], 0 | O_WRONLY | O_CREAT | O_TRUNC, 0666);
  if (outfd < 0) {
    printf("error: cannot open output file '%s'\n", argv[3]);
    return -1;
  }
  infd = open(argv[1], 0 | O_RDONLY);
  if (infd < 0) {
    printf("error: cannot open bootblock file '%s'\n", argv[1]);
    return -1;
  }
  if (read(infd, bootsector, sizeof(bootsector)) < sizeof(bootsector) ||
      lseek(infd, 0, SEEK_END) != sizeof(bootsector)) {
    printf("error: size of bootblock file '%s' must match %d bytes.\n", argv[1],
           sizeof(bootsector));
    return -1;
  }
  close(infd);
  blocks = st.st_size / 512;
  if ((st.st_size % 512) != 0)
    blocks++;
  printf("size %d, blocks %d (size %d)\n", (unsigned long)st.st_size, blocks,
         blocks * 512);
  bootsector[2] = (blocks & 0x00ff);
  bootsector[3] = (blocks & 0xff00) >> 8;
  if (enable_vesa) {
    bootsector[512] = 1;
    bootsector[513] = (vesa_x & 0x00ff);
    bootsector[514] = (vesa_x & 0xff00) >> 8;
    bootsector[515] = (vesa_y & 0x00ff);
    bootsector[516] = (vesa_y & 0xff00) >> 8;
    bootsector[517] = vesa_bit;
  }
  write(outfd, bootsector, sizeof(bootsector));
  written_bytes = sizeof(bootsector);
  infd = open(argv[2], 0 | O_RDONLY);
  if (infd < 0) {
    printf("error: cannot open input file '%s'\n", argv[1]);
    return -1;
  }
  while ((read_size = read(infd, buf, sizeof(buf))) > 0) {
    write(outfd, buf, read_size);
    written_bytes += read_size;
  }
  if (padding) {
    if (written_bytes % padding) {
      size_t towrite = padding - written_bytes % padding;
      unsigned char *buf = malloc(towrite);
      memset(buf, 0, towrite);
      write(outfd, buf, towrite);
      written_bytes += towrite;
      printf("output file padded to %ld\n", (unsigned long)written_bytes);
    }
  }
  close(outfd);
  close(infd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x680,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x634(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x658(%rbp)
movl   $0x0,-0x638(%rbp)
movl   $0x280,-0x63c(%rbp)
movl   $0x1e0,-0x640(%rbp)
movl   $0x10,-0x644(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xec5(%rip),%rdx
call   10d0 <getopt@plt>
mov    %al,-0x64d(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     139a <main+0x1da>
movsbl -0x64d(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x670(%rbp)
sub    $0x3a,%eax
ja     137d <main+0x1bd>
mov    -0x670(%rbp),%rax
lea    0xd98(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   10e0 <atoi@plt>
mov    %eax,-0x634(%rbp)
cmpl   $0x0,-0x634(%rbp)
jge    12aa <main+0xea>
mov    -0x658(%rbp),%rdi
call   10b0 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17fa <main+0x63a>
jmp    1395 <main+0x1d5>
movl   $0x1,-0x638(%rbp)
jmp    1395 <main+0x1d5>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   10e0 <atoi@plt>
mov    %eax,-0x63c(%rbp)
cmpl   $0x0,-0x63c(%rbp)
jge    12f7 <main+0x137>
mov    -0x658(%rbp),%rdi
call   10b0 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17fa <main+0x63a>
jmp    1395 <main+0x1d5>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   10e0 <atoi@plt>
mov    %eax,-0x640(%rbp)
cmpl   $0x0,-0x640(%rbp)
jge    1335 <main+0x175>
mov    -0x658(%rbp),%rdi
call   10b0 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17fa <main+0x63a>
jmp    1395 <main+0x1d5>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
call   10e0 <atoi@plt>
mov    %eax,-0x644(%rbp)
cmpl   $0x0,-0x644(%rbp)
jge    1373 <main+0x1b3>
mov    -0x658(%rbp),%rdi
call   10b0 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17fa <main+0x63a>
jmp    1395 <main+0x1d5>
jmp    137d <main+0x1bd>
mov    -0x658(%rbp),%rdi
call   10b0 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17fa <main+0x63a>
jmp    1219 <main+0x59>
mov    0x2c1f(%rip),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    -0x8(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    0x2c0b(%rip),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    13fc <main+0x23c>
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x658(%rbp),%rdi
call   10b0 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17fa <main+0x63a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    143c <main+0x27c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xce0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17fa <main+0x63a>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2b5d(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
mov    0x2ba1(%rip),%rax
or     (%rax),%esi
mov    0x2b88(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x64c(%rbp)
cmpl   $0x0,-0x64c(%rbp)
jge    14a3 <main+0x2e3>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xc92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17fa <main+0x63a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2b16(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x648(%rbp)
cmpl   $0x0,-0x648(%rbp)
jge    14f3 <main+0x333>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xc67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17fa <main+0x63a>
mov    -0x648(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
cltq
cmp    $0x400,%rax
jb     153c <main+0x37c>
mov    -0x648(%rbp),%edi
mov    0x2aab(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
cltq
cmp    $0x400,%rax
je     1563 <main+0x3a3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xc24(%rip),%rdi
mov    $0x400,%edx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17fa <main+0x63a>
mov    -0x648(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1599 <main+0x3d9>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movslq -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x20(%rbp),%ecx
shl    $0x9,%ecx
lea    0xbfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x41e(%rbp)
mov    -0x20(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,-0x41d(%rbp)
cmpl   $0x0,-0x638(%rbp)
je     163d <main+0x47d>
movb   $0x1,-0x220(%rbp)
mov    -0x63c(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x21f(%rbp)
mov    -0x63c(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x21e(%rbp)
mov    -0x640(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x21d(%rbp)
mov    -0x640(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,-0x21c(%rbp)
mov    -0x644(%rbp),%eax
mov    %al,-0x21b(%rbp)
mov    -0x64c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1030 <write@plt>
movq   $0x400,-0x630(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x295a(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x648(%rbp)
cmpl   $0x0,-0x648(%rbp)
jge    16af <main+0x4ef>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xb2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17fa <main+0x63a>
jmp    16b4 <main+0x4f4>
mov    -0x648(%rbp),%edi
lea    -0x620(%rbp),%rsi
mov    $0x200,%edx
call   1080 <read@plt>
cltq
mov    %rax,-0x628(%rbp)
cmp    $0x0,%rax
jbe    1711 <main+0x551>
mov    -0x64c(%rbp),%edi
lea    -0x620(%rbp),%rsi
mov    -0x628(%rbp),%rdx
call   1030 <write@plt>
mov    -0x628(%rbp),%rax
add    -0x630(%rbp),%rax
mov    %rax,-0x630(%rbp)
jmp    16b4 <main+0x4f4>
cmpl   $0x0,-0x634(%rbp)
je     17dd <main+0x61d>
mov    -0x630(%rbp),%rax
movslq -0x634(%rbp),%rcx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
je     17d8 <main+0x618>
movslq -0x634(%rbp),%rax
mov    %rax,-0x678(%rbp)
mov    -0x630(%rbp),%rax
movslq -0x634(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    -0x678(%rbp),%rax
sub    %rdx,%rax
mov    %rax,-0x660(%rbp)
mov    -0x660(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x668(%rbp)
mov    -0x668(%rbp),%rdi
mov    -0x660(%rbp),%rdx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x64c(%rbp),%edi
mov    -0x668(%rbp),%rsi
mov    -0x660(%rbp),%rdx
call   1030 <write@plt>
mov    -0x660(%rbp),%rax
add    -0x630(%rbp),%rax
mov    %rax,-0x630(%rbp)
mov    -0x630(%rbp),%rsi
lea    0xa19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    17dd <main+0x61d>
mov    -0x64c(%rbp),%edi
call   1070 <close@plt>
mov    -0x648(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x680,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x628,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%rax
mov    %rax,0x10(%rsp)
lea    0xe63(%rip),%rdx
call   10e0 <getopt@plt>
cmp    $0xff,%al
je     12ce <main+0xfe>
xor    %r15d,%r15d
movl   $0x280,(%rsp)
movl   $0x1e0,0x4(%rsp)
movl   $0x10,0x8(%rsp)
lea    0xddd(%rip),%r14
lea    0xe2e(%rip),%r13
movl   $0x0,0xc(%rsp)
jmp    1269 <main+0x99>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   10f0 <atoi@plt>
mov    %r15d,%r12d
mov    %eax,0xc(%rsp)
test   %eax,%eax
js     1311 <main+0x141>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   10e0 <getopt@plt>
mov    %r12d,%r15d
cmp    $0xff,%al
je     12f0 <main+0x120>
movsbl %al,%eax
add    $0xffffff9c,%eax
cmp    $0x15,%eax
ja     1311 <main+0x141>
mov    $0x1,%r12d
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   10f0 <atoi@plt>
mov    %r15d,%r12d
mov    %eax,0x8(%rsp)
jmp    1249 <main+0x79>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   10f0 <atoi@plt>
mov    %r15d,%r12d
mov    %eax,(%rsp)
jmp    1249 <main+0x79>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   10f0 <atoi@plt>
mov    %r15d,%r12d
mov    %eax,0x4(%rsp)
jmp    1249 <main+0x79>
movl   $0x10,0x8(%rsp)
movl   $0x1e0,0x4(%rsp)
movl   $0x280,(%rsp)
movl   $0x0,0xc(%rsp)
xor    %r12d,%r12d
mov    0x2cc9(%rip),%rax
movslq (%rax),%r13
sub    %r13d,%ebp
add    $0x1,%ebp
cmp    $0x3,%ebp
jg     1320 <main+0x150>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%rdi
call   10c0 <usage@plt>
jmp    1534 <main+0x364>
mov    0x8(%rbx,%r13,8),%rdi
lea    0x18(%rsp),%rsi
call   10a0 <stat@plt>
test   %eax,%eax
js     14ed <main+0x31d>
mov    0x2c6a(%rip),%rax
mov    0x2cb3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%rbx,%r13,8),%rdi
mov    0x2c93(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
xor    %eax,%eax
call   10d0 <open@plt>
test   %eax,%eax
js     14fb <main+0x32b>
mov    %eax,%r15d
mov    (%rbx,%r13,8),%rdi
mov    0x2c4f(%rip),%r14
mov    (%r14),%esi
xor    %eax,%eax
call   10d0 <open@plt>
test   %eax,%eax
js     1522 <main+0x352>
mov    %eax,%ebp
lea    0x20(%rsp),%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1090 <read@plt>
cmp    $0x400,%eax
jb     1509 <main+0x339>
mov    0x2c20(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0x400,%eax
jne    1509 <main+0x339>
mov    %ebp,%edi
call   1080 <close@plt>
movslq 0x18(%rsp),%rsi
lea    0x1ff(%rsi),%ebp
test   %esi,%esi
cmovns %esi,%ebp
sar    $0x9,%ebp
mov    %esi,%eax
and    $0x1ff,%eax
cmp    $0x1,%eax
sbb    $0xffffffff,%ebp
mov    %ebp,%ecx
shl    $0x9,%ecx
lea    0xd08(%rip),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %bp,0x22(%rsp)
test   %r12d,%r12d
je     1442 <main+0x272>
movb   $0x1,0x220(%rsp)
01
mov    (%rsp),%eax
mov    %al,0x221(%rsp)
mov    %ah,0x222(%rsp)
mov    0x4(%rsp),%eax
mov    %al,0x223(%rsp)
mov    %ah,0x224(%rsp)
mov    0x8(%rsp),%eax
mov    %al,0x225(%rsp)
lea    0x20(%rsp),%rsi
mov    $0x400,%ebp
mov    $0x400,%edx
mov    %r15d,%edi
call   1040 <write@plt>
mov    0x8(%rbx,%r13,8),%rdi
mov    (%r14),%esi
xor    %eax,%eax
call   10d0 <open@plt>
test   %eax,%eax
js     154b <main+0x37b>
mov    %eax,%r12d
lea    0x420(%rsp),%rsi
mov    %eax,%edi
mov    $0x200,%edx
call   1090 <read@plt>
test   %eax,%eax
je     14c8 <main+0x2f8>
mov    $0x400,%ebp
lea    0x420(%rsp),%r13
nopl   0x0(%rax,%rax,1)
movslq %eax,%rbx
mov    %r15d,%edi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <write@plt>
add    %rbx,%rbp
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x200,%edx
call   1090 <read@plt>
test   %eax,%eax
jne    14a0 <main+0x2d0>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
je     15a0 <main+0x3d0>
movslq %ecx,%rbx
mov    %rbp,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     1558 <main+0x388>
mov    %rbp,%rax
xor    %edx,%edx
div    %rbx
jmp    155e <main+0x38e>
mov    0x8(%rbx,%r13,8),%rsi
lea    0xb69(%rip),%rdi
jmp    152d <main+0x35d>
mov    0x10(%rbx,%r13,8),%rsi
lea    0xb74(%rip),%rdi
jmp    152d <main+0x35d>
mov    (%rbx,%r13,8),%rsi
lea    0xbb4(%rip),%rdi
mov    $0x400,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1534 <main+0x364>
mov    (%rbx,%r13,8),%rsi
lea    0xb73(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x628,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx,%r13,8),%rsi
lea    0xbc9(%rip),%rdi
jmp    152d <main+0x35d>
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
test   %rdx,%rdx
je     15a0 <main+0x3d0>
sub    %rdx,%rbx
mov    %rbx,%rdi
call   10b0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1070 <memset@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <write@plt>
add    %rbp,%rbx
lea    0xbad(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%edi
call   1080 <close@plt>
mov    %r12d,%edi
call   1080 <close@plt>
xor    %eax,%eax
jmp    1539 <main+0x369>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [10 x i8] c"p:vx:y:d:\00"
@optarg = global i32 0
@optind = global i32 0
@.str.1 = [19 x i8] c"insufficient args\0A\00"
@.str.2 = [25 x i8] c"error stating file '%s'\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [37 x i8] c"error: cannot open output file '%s'\0A\00"
@O_RDONLY = global i32 0
@.str.4 = [40 x i8] c"error: cannot open bootblock file '%s'\0A\00"
@SEEK_END = global i32 0
@.str.5 = [57 x i8] c"error: size of bootblock file '%s' must match %d bytes.\0A\00"
@.str.6 = [30 x i8] c"size %d, blocks %d (size %d)\0A\00"
@.str.7 = [36 x i8] c"error: cannot open input file '%s'\0A\00"
@.str.8 = [27 x i8] c"output file padded to %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca [512 x i8]
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8
%21 = alloca i8*
%22 = alloca i64
%23 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %13
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
store i8* %26, i8** %21
store i32 0, i32* %14
store i32 640, i32* %15
store i32 480, i32* %16
store i32 16, i32* %17
br label %27
27: ; preds = %77, %2
%28 = load i32, i32* %4
%29 = load i8**, i8*** %5
%30 = call signext i8 @getopt(i32 %28, i8** %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8 %30, i8* %20
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, -1
br i1 %32, label %33, label %78
33: ; preds = %27
%34 = load i8, i8* %20
%35 = sext i8 %34 to i32
switch i32 %35, label %74 [
i32 112, label %36
i32 118, label %45
i32 120, label %46
i32 121, label %55
i32 100, label %64
i32 63, label %73
]
36: ; preds = %33
%37 = load i32, i32* @optarg
%38 = call i32 @atoi(i32 %37)
store i32 %38, i32* %13
%39 = load i32, i32* %13
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i8*, i8** %21
%43 = call i32 @usage(i8* %42)
store i32 -1, i32* %3
br label %279
44: ; preds = %36
br label %77
45: ; preds = %33
store i32 1, i32* %14
br label %77
46: ; preds = %33
%47 = load i32, i32* @optarg
%48 = call i32 @atoi(i32 %47)
store i32 %48, i32* %15
%49 = load i32, i32* %15
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = load i8*, i8** %21
%53 = call i32 @usage(i8* %52)
store i32 -1, i32* %3
br label %279
54: ; preds = %46
br label %77
55: ; preds = %33
%56 = load i32, i32* @optarg
%57 = call i32 @atoi(i32 %56)
store i32 %57, i32* %16
%58 = load i32, i32* %16
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %55
%61 = load i8*, i8** %21
%62 = call i32 @usage(i8* %61)
store i32 -1, i32* %3
br label %279
63: ; preds = %55
br label %77
64: ; preds = %33
%65 = load i32, i32* @optarg
%66 = call i32 @atoi(i32 %65)
store i32 %66, i32* %17
%67 = load i32, i32* %17
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %64
%70 = load i8*, i8** %21
%71 = call i32 @usage(i8* %70)
store i32 -1, i32* %3
br label %279
72: ; preds = %64
br label %77
73: ; preds = %33
br label %74
74: ; preds = %33, %73
%75 = load i8*, i8** %21
%76 = call i32 @usage(i8* %75)
store i32 -1, i32* %3
br label %279
77: ; preds = %72, %63, %54, %45, %44
br label %27
78: ; preds = %27
%79 = load i32, i32* @optind
%80 = sub nsw i32 %79, 1
%81 = load i32, i32* %4
%82 = sub nsw i32 %81, %80
store i32 %82, i32* %4
%83 = load i32, i32* @optind
%84 = sub nsw i32 %83, 1
%85 = load i8**, i8*** %5
%86 = sext i32 %84 to i64
%87 = getelementptr inbounds i8*, i8** %85, i64 %86
store i8** %87, i8*** %5
%88 = load i32, i32* %4
%89 = icmp slt i32 %88, 4
br i1 %89, label %90, label %94
90: ; preds = %78
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%92 = load i8*, i8** %21
%93 = call i32 @usage(i8* %92)
store i32 -1, i32* %3
br label %279
94: ; preds = %78
%95 = load i8**, i8*** %5
%96 = getelementptr inbounds i8*, i8** %95, i64 2
%97 = load i8*, i8** %96
%98 = call i32 @stat(i8* %97, %struct.stat* %6)
store i32 %98, i32* %7
%99 = load i32, i32* %7
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %106
101: ; preds = %94
%102 = load i8**, i8*** %5
%103 = getelementptr inbounds i8*, i8** %102, i64 2
%104 = load i8*, i8** %103
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %104)
store i32 -1, i32* %3
br label %279
106: ; preds = %94
%107 = load i8**, i8*** %5
%108 = getelementptr inbounds i8*, i8** %107, i64 3
%109 = load i8*, i8** %108
%110 = load i32, i32* @O_WRONLY
%111 = or i32 0, %110
%112 = load i32, i32* @O_CREAT
%113 = or i32 %111, %112
%114 = load i32, i32* @O_TRUNC
%115 = or i32 %113, %114
%116 = call i32 (i8*, i32, ...) @open(i8* %109, i32 %115, i32 438)
store i32 %116, i32* %19
%117 = load i32, i32* %19
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %124
119: ; preds = %106
%120 = load i8**, i8*** %5
%121 = getelementptr inbounds i8*, i8** %120, i64 3
%122 = load i8*, i8** %121
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %122)
store i32 -1, i32* %3
br label %279
124: ; preds = %106
%125 = load i8**, i8*** %5
%126 = getelementptr inbounds i8*, i8** %125, i64 1
%127 = load i8*, i8** %126
%128 = load i32, i32* @O_RDONLY
%129 = or i32 0, %128
%130 = call i32 (i8*, i32, ...) @open(i8* %127, i32 %129)
store i32 %130, i32* %18
%131 = load i32, i32* %18
%132 = icmp slt i32 %131, 0
br i1 %132, label %133, label %138
133: ; preds = %124
%134 = load i8**, i8*** %5
%135 = getelementptr inbounds i8*, i8** %134, i64 1
%136 = load i8*, i8** %135
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %136)
store i32 -1, i32* %3
br label %279
138: ; preds = %124
%139 = load i32, i32* %18
%140 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%141 = call i32 @read(i32 %139, i8* %140, i32 1024)
%142 = sext i32 %141 to i64
%143 = icmp ult i64 %142, 1024
br i1 %143, label %150, label %144
144: ; preds = %138
%145 = load i32, i32* %18
%146 = load i32, i32* @SEEK_END
%147 = call i32 @lseek(i32 %145, i32 0, i32 %146)
%148 = sext i32 %147 to i64
%149 = icmp ne i64 %148, 1024
br i1 %149, label %150, label %155
150: ; preds = %144, %138
%151 = load i8**, i8*** %5
%152 = getelementptr inbounds i8*, i8** %151, i64 1
%153 = load i8*, i8** %152
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i8* %153, i64 1024)
store i32 -1, i32* %3
br label %279
155: ; preds = %144
%156 = load i32, i32* %18
%157 = call i32 @close(i32 %156)
%158 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%159 = load i32, i32* %158
%160 = sdiv i32 %159, 512
store i32 %160, i32* %8
%161 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%162 = load i32, i32* %161
%163 = srem i32 %162, 512
%164 = icmp ne i32 %163, 0
br i1 %164, label %165, label %168
165: ; preds = %155
%166 = load i32, i32* %8
%167 = add i32 %166, 1
store i32 %167, i32* %8
br label %168
168: ; preds = %165, %155
%169 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%170 = load i32, i32* %169
%171 = sext i32 %170 to i64
%172 = load i32, i32* %8
%173 = load i32, i32* %8
%174 = mul i32 %173, 512
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i64 %171, i32 %172, i32 %174)
%176 = load i32, i32* %8
%177 = and i32 %176, 255
%178 = trunc i32 %177 to i8
%179 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 2
store i8 %178, i8* %179
%180 = load i32, i32* %8
%181 = and i32 %180, 65280
%182 = lshr i32 %181, 8
%183 = trunc i32 %182 to i8
%184 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 3
store i8 %183, i8* %184
%185 = load i32, i32* %14
%186 = icmp ne i32 %185, 0
br i1 %186, label %187, label %210
187: ; preds = %168
%188 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 512
store i8 1, i8* %188
%189 = load i32, i32* %15
%190 = and i32 %189, 255
%191 = trunc i32 %190 to i8
%192 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 513
store i8 %191, i8* %192
%193 = load i32, i32* %15
%194 = and i32 %193, 65280
%195 = ashr i32 %194, 8
%196 = trunc i32 %195 to i8
%197 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 514
store i8 %196, i8* %197
%198 = load i32, i32* %16
%199 = and i32 %198, 255
%200 = trunc i32 %199 to i8
%201 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 515
store i8 %200, i8* %201
%202 = load i32, i32* %16
%203 = and i32 %202, 65280
%204 = ashr i32 %203, 8
%205 = trunc i32 %204 to i8
%206 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 516
store i8 %205, i8* %206
%207 = load i32, i32* %17
%208 = trunc i32 %207 to i8
%209 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 517
store i8 %208, i8* %209
br label %210
210: ; preds = %187, %168
%211 = load i32, i32* %19
%212 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%213 = call i32 @write(i32 %211, i8* %212, i64 1024)
store i64 1024, i64* %12
%214 = load i8**, i8*** %5
%215 = getelementptr inbounds i8*, i8** %214, i64 2
%216 = load i8*, i8** %215
%217 = load i32, i32* @O_RDONLY
%218 = or i32 0, %217
%219 = call i32 (i8*, i32, ...) @open(i8* %216, i32 %218)
store i32 %219, i32* %18
%220 = load i32, i32* %18
%221 = icmp slt i32 %220, 0
br i1 %221, label %222, label %227
222: ; preds = %210
%223 = load i8**, i8*** %5
%224 = getelementptr inbounds i8*, i8** %223, i64 1
%225 = load i8*, i8** %224
%226 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %225)
store i32 -1, i32* %3
br label %279
227: ; preds = %210
br label %228
228: ; preds = %234, %227
%229 = load i32, i32* %18
%230 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%231 = call i32 @read(i32 %229, i8* %230, i32 512)
%232 = sext i32 %231 to i64
store i64 %232, i64* %11
%233 = icmp ugt i64 %232, 0
br i1 %233, label %234, label %242
234: ; preds = %228
%235 = load i32, i32* %19
%236 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%237 = load i64, i64* %11
%238 = call i32 @write(i32 %235, i8* %236, i64 %237)
%239 = load i64, i64* %11
%240 = load i64, i64* %12
%241 = add i64 %240, %239
store i64 %241, i64* %12
br label %228
242: ; preds = %228
%243 = load i32, i32* %13
%244 = icmp ne i32 %243, 0
br i1 %244, label %245, label %274
245: ; preds = %242
%246 = load i64, i64* %12
%247 = load i32, i32* %13
%248 = sext i32 %247 to i64
%249 = urem i64 %246, %248
%250 = icmp ne i64 %249, 0
br i1 %250, label %251, label %273
251: ; preds = %245
%252 = load i32, i32* %13
%253 = sext i32 %252 to i64
%254 = load i64, i64* %12
%255 = load i32, i32* %13
%256 = sext i32 %255 to i64
%257 = urem i64 %254, %256
%258 = sub i64 %253, %257
store i64 %258, i64* %22
%259 = load i64, i64* %22
%260 = call i8* @malloc(i64 %259)
store i8* %260, i8** %23
%261 = load i8*, i8** %23
%262 = load i64, i64* %22
%263 = call i32 @memset(i8* %261, i32 0, i64 %262)
%264 = load i32, i32* %19
%265 = load i8*, i8** %23
%266 = load i64, i64* %22
%267 = call i32 @write(i32 %264, i8* %265, i64 %266)
%268 = load i64, i64* %22
%269 = load i64, i64* %12
%270 = add i64 %269, %268
store i64 %270, i64* %12
%271 = load i64, i64* %12
%272 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i64 %271)
br label %273
273: ; preds = %251, %245
br label %274
274: ; preds = %273, %242
%275 = load i32, i32* %19
%276 = call i32 @close(i32 %275)
%277 = load i32, i32* %18
%278 = call i32 @close(i32 %277)
store i32 0, i32* %3
br label %279
279: ; preds = %274, %222, %150, %133, %119, %101, %90, %74, %69, %60, %51, %41
%280 = load i32, i32* %3
ret i32 %280
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [10 x i8] c"p:vx:y:d:\00"
@optarg = global i32 0
@optind = global i32 0
@.str.2 = [25 x i8] c"error stating file '%s'\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [37 x i8] c"error: cannot open output file '%s'\0A\00"
@O_RDONLY = global i32 0
@.str.4 = [40 x i8] c"error: cannot open bootblock file '%s'\0A\00"
@SEEK_END = global i32 0
@.str.5 = [57 x i8] c"error: size of bootblock file '%s' must match %d bytes.\0A\00"
@.str.6 = [30 x i8] c"size %d, blocks %d (size %d)\0A\00"
@.str.7 = [36 x i8] c"error: cannot open input file '%s'\0A\00"
@.str.8 = [27 x i8] c"output file padded to %ld\0A\00"
@str = [18 x i8] c"insufficient args\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = alloca [1024 x i8]
%5 = alloca [512 x i8]
%6 = bitcast %struct.stat* %3 to i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = load i8*, i8** %1
%10 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8 %10, -1
br i1 %11, label %54, label %12
12: ; preds = %2, %46
%13 = phi i8 [ %52, %46 ], [ %10, %2 ]
%14 = phi i32 [ %51, %46 ], [ 16, %2 ]
%15 = phi i32 [ %50, %46 ], [ 480, %2 ]
%16 = phi i32 [ %49, %46 ], [ 640, %2 ]
%17 = phi i32 [ %48, %46 ], [ 0, %2 ]
%18 = phi i32 [ %47, %46 ], [ 0, %2 ]
%19 = sext i8 %13 to i32
switch i32 %19, label %44 [
i32 112, label %20
i32 118, label %46
i32 120, label %26
i32 121, label %32
i32 100, label %38
]
20: ; preds = %12
%21 = load i32, i32* @optarg
%22 = tail call i32 @atoi(i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %46
24: ; preds = %20
%25 = tail call i32 @usage(i8* %9)
br label %178
26: ; preds = %12
%27 = load i32, i32* @optarg
%28 = tail call i32 @atoi(i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %46
30: ; preds = %26
%31 = tail call i32 @usage(i8* %9)
br label %178
32: ; preds = %12
%33 = load i32, i32* @optarg
%34 = tail call i32 @atoi(i32 %33)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = tail call i32 @usage(i8* %9)
br label %178
38: ; preds = %12
%39 = load i32, i32* @optarg
%40 = tail call i32 @atoi(i32 %39)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = tail call i32 @usage(i8* %9)
br label %178
44: ; preds = %12
%45 = tail call i32 @usage(i8* %9)
br label %178
46: ; preds = %12, %38, %32, %26, %20
%47 = phi i32 [ %18, %38 ], [ %18, %32 ], [ %18, %26 ], [ %22, %20 ], [ %18, %12 ]
%48 = phi i32 [ %17, %38 ], [ %17, %32 ], [ %17, %26 ], [ %17, %20 ], [ 1, %12 ]
%49 = phi i32 [ %16, %38 ], [ %16, %32 ], [ %28, %26 ], [ %16, %20 ], [ %16, %12 ]
%50 = phi i32 [ %15, %38 ], [ %34, %32 ], [ %15, %26 ], [ %15, %20 ], [ %15, %12 ]
%51 = phi i32 [ %40, %38 ], [ %14, %32 ], [ %14, %26 ], [ %14, %20 ], [ %14, %12 ]
%52 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%53 = icmp eq i8 %52, -1
br i1 %53, label %54, label %12
54: ; preds = %46, %2
%55 = phi i32 [ 0, %2 ], [ %47, %46 ]
%56 = phi i32 [ 0, %2 ], [ %48, %46 ]
%57 = phi i32 [ 640, %2 ], [ %49, %46 ]
%58 = phi i32 [ 480, %2 ], [ %50, %46 ]
%59 = phi i32 [ 16, %2 ], [ %51, %46 ]
%60 = load i32, i32* @optind
%61 = add nsw i32 %60, -1
%62 = sub nsw i32 %0, %61
%63 = sext i32 %61 to i64
%64 = getelementptr inbounds i8*, i8** %1, i64 %63
%65 = icmp slt i32 %62, 4
br i1 %65, label %66, label %69
66: ; preds = %54
%67 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%68 = tail call i32 @usage(i8* %9)
br label %178
69: ; preds = %54
%70 = getelementptr inbounds i8*, i8** %64, i64 2
%71 = load i8*, i8** %70
%72 = call i32 @stat(i8* %71, %struct.stat* %3)
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %69
%75 = load i8*, i8** %70
%76 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %75)
br label %178
77: ; preds = %69
%78 = getelementptr inbounds i8*, i8** %64, i64 3
%79 = load i8*, i8** %78
%80 = load i32, i32* @O_WRONLY
%81 = load i32, i32* @O_CREAT
%82 = or i32 %81, %80
%83 = load i32, i32* @O_TRUNC
%84 = or i32 %82, %83
%85 = tail call i32 (i8*, i32, ...) @open(i8* %79, i32 %84, i32 438)
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %77
%88 = load i8*, i8** %78
%89 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %88)
br label %178
90: ; preds = %77
%91 = getelementptr inbounds i8*, i8** %64, i64 1
%92 = load i8*, i8** %91
%93 = load i32, i32* @O_RDONLY
%94 = tail call i32 (i8*, i32, ...) @open(i8* %92, i32 %93)
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %90
%97 = load i8*, i8** %91
%98 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %97)
br label %178
99: ; preds = %90
%100 = call i32 @read(i32 %94, i8* %7, i32 1024)
%101 = icmp ult i32 %100, 1024
br i1 %101, label %106, label %102
102: ; preds = %99
%103 = load i32, i32* @SEEK_END
%104 = tail call i32 @lseek(i32 %94, i32 0, i32 %103)
%105 = icmp eq i32 %104, 1024
br i1 %105, label %109, label %106
106: ; preds = %102, %99
%107 = load i8*, i8** %91
%108 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i8* %107, i64 1024)
br label %178
109: ; preds = %102
%110 = tail call i32 @close(i32 %94)
%111 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%112 = load i32, i32* %111
%113 = sdiv i32 %112, 512
%114 = and i32 %112, 511
%115 = icmp ne i32 %114, 0
%116 = zext i1 %115 to i32
%117 = add nsw i32 %113, %116
%118 = sext i32 %112 to i64
%119 = shl i32 %117, 9
%120 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i64 %118, i32 %117, i32 %119)
%121 = trunc i32 %117 to i8
%122 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 2
store i8 %121, i8* %122
%123 = lshr i32 %117, 8
%124 = trunc i32 %123 to i8
%125 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 3
store i8 %124, i8* %125
%126 = icmp eq i32 %56, 0
br i1 %126, label %141, label %127
127: ; preds = %109
%128 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 512
store i8 1, i8* %128
%129 = trunc i32 %57 to i8
%130 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 513
store i8 %129, i8* %130
%131 = lshr i32 %57, 8
%132 = trunc i32 %131 to i8
%133 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 514
store i8 %132, i8* %133
%134 = trunc i32 %58 to i8
%135 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 515
store i8 %134, i8* %135
%136 = lshr i32 %58, 8
%137 = trunc i32 %136 to i8
%138 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 516
store i8 %137, i8* %138
%139 = trunc i32 %59 to i8
%140 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 517
store i8 %139, i8* %140
br label %141
141: ; preds = %127, %109
%142 = call i32 @write(i32 %85, i8* %7, i64 1024)
%143 = load i8*, i8** %70
%144 = load i32, i32* @O_RDONLY
%145 = tail call i32 (i8*, i32, ...) @open(i8* %143, i32 %144)
%146 = icmp slt i32 %145, 0
br i1 %146, label %150, label %147
147: ; preds = %141
%148 = call i32 @read(i32 %145, i8* %8, i32 512)
%149 = icmp eq i32 %148, 0
br i1 %149, label %161, label %153
150: ; preds = %141
%151 = load i8*, i8** %91
%152 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %151)
br label %178
153: ; preds = %147, %153
%154 = phi i32 [ %159, %153 ], [ %148, %147 ]
%155 = phi i64 [ %158, %153 ], [ 1024, %147 ]
%156 = sext i32 %154 to i64
%157 = call i32 @write(i32 %85, i8* %8, i64 %156)
%158 = add i64 %155, %156
%159 = call i32 @read(i32 %145, i8* %8, i32 512)
%160 = icmp eq i32 %159, 0
br i1 %160, label %161, label %153
161: ; preds = %153, %147
%162 = phi i64 [ 1024, %147 ], [ %158, %153 ]
%163 = icmp eq i32 %55, 0
br i1 %163, label %175, label %164
164: ; preds = %161
%165 = sext i32 %55 to i64
%166 = urem i64 %162, %165
%167 = icmp eq i64 %166, 0
br i1 %167, label %175, label %168
168: ; preds = %164
%169 = sub i64 %165, %166
%170 = tail call i8* @malloc(i64 %169)
%171 = tail call i32 @memset(i8* %170, i32 0, i64 %169)
%172 = tail call i32 @write(i32 %85, i8* %170, i64 %169)
%173 = add i64 %169, %162
%174 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i64 %173)
br label %175
175: ; preds = %164, %168, %161
%176 = tail call i32 @close(i32 %85)
%177 = tail call i32 @close(i32 %145)
br label %178
178: ; preds = %175, %150, %106, %96, %87, %74, %66, %44, %42, %36, %30, %24
%179 = phi i32 [ -1, %44 ], [ -1, %42 ], [ -1, %36 ], [ -1, %30 ], [ -1, %24 ], [ -1, %66 ], [ -1, %74 ], [ -1, %87 ], [ -1, %96 ], [ -1, %106 ], [ -1, %150 ], [ 0, %175 ]
ret i32 %179
}