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

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ argv;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
unsigned char *calloc(int, int);
int /*<<< orphan*/ chmod(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int blockSize = 512;
  int keySize = 2048;
  int count;
  unsigned char *block;
  if (argc == 3 && strcmp(argv[1], "genwrite") != 0 &&
      (sizeof(argv[2]) / sizeof(char)) > 2) {
    char ch;
    FILE *keyF;
    keyF = fopen(argv[1], "r");
    if (keyF == NULL)
      exit(EXIT_FAILURE);
    fseek(keyF, 0, SEEK_END);
    keySize = ftell(keyF);
    rewind(keyF);
    printf("\nKey Size: %d\n", keySize);
    block = calloc(keySize, sizeof(char));
    printf("\n-- Start Key --:\n");
    for (count = 0; count < keySize; count++) {
      char ch = fgetc(keyF);
      block[count] = ch;
    }
    printf("\n-- End Key --:\n");
    fclose(keyF);
  } else if (argc == 3 && strcmp(argv[1], "genwrite") == 0 &&
             (sizeof(argv[2]) / sizeof(char)) > 2) {
    printf("\n-- Attempting to create random key(ish --) of size: %d\n",
           keySize);
    block = calloc(keySize, sizeof(char));
    int count;
    for (count = 0; count < keySize; count++) {
      block[count] = (char)rand();
    }
    FILE *tmpfile;
    tmpfile = fopen(".tmpckey", "w");
    if (tmpfile == NULL)
      exit(EXIT_FAILURE);
    fwrite(block, 1, keySize, tmpfile);
    fclose(tmpfile);
    chmod(".tmpckey", 0600);
  } else if (argc == 4 && strcmp(argv[1], "genwrite") == 0 &&
             (sizeof(argv[2]) / sizeof(char)) > 2 &&
             ((atoi(argv[3]) % 512) == 0)) {
    keySize = atoi(argv[3]);
    printf("\n-- Attempting to create random key(ish --) of size: %d\n",
           keySize);
    block = calloc(keySize, sizeof(char));
    int count;
    for (count = 0; count < keySize; count++) {
      block[count] = (char)rand();
    }
    FILE *tmpfile;
    tmpfile = fopen(".tmpckey", "w");
    if (tmpfile == NULL)
      exit(EXIT_FAILURE);
    fwrite(block, 1, keySize, tmpfile);
    fclose(tmpfile);
    chmod(".tmpckey", 0600);
  } else {
    printf("\n");
    printf("###################################################################"
           "#############\n");
    printf("#                                                                  "
           "            #\n");
    printf("#                              Usage:                              "
           "            #\n");
    printf("#                                                                  "
           "            #\n");
    printf("###################################################################"
           "#############\n");
    printf("#> To write existing key to device:                                "
           "            #\n");
    printf("#                                                                  "
           "            #\n");
    printf("#     writekey </path/to/keyfile> </path/to/removable/sd*>         "
           "            #\n");
    printf("#                                                                  "
           "            #\n");
    printf("#> To generate and write pseudo random key,                        "
           "            #\n");
    printf("#> key will be saved to temporary file .tmpckey                    "
           "            #\n");
    printf("#                                                                  "
           "            #\n");
    printf("#     writekey genwrite </path/to/removable/sd*> <keysize in "
           "multiples of 512> #\n");
    printf("#                                                                  "
           "            #\n");
    printf("#> When keysize is not provided default size is set to %d.         "
           "            #\n",
           keySize);
    printf("#                                                                  "
           "            #\n");
    printf("###################################################################"
           "#############\n");
    exit(1);
  }
  FILE *device = fopen(argv[2], "a");
  if (device == NULL)
    exit(EXIT_FAILURE);
  printf("\nDevice to write: %s\n", argv[2]);
  fseek(device, 0, SEEK_END);
  long endOfDisk = ftell(device);
  printf("\nDevice Size: %ld\n", endOfDisk);
  int numBlocks = 0;
  if (keySize % 512 != 0 || endOfDisk < (blockSize + keySize)) {
    printf("\nSorry but key size is not multiple of block size or device you "
           "trying to write to is too small, try again. TA.\n");
    fclose(device);
    exit(1);
  }
  rewind(device);
  long startFrom = endOfDisk - blockSize - keySize;
  printf("\nWriting data starting from: %ld\n", startFrom);
  fseek(device, startFrom, SEEK_SET);
  fwrite(block, 1, keySize, device);
  printf("\nBlock Position after data write procedure : %ld\n", ftell(device));
  fclose(device);
  memset(block, 0, keySize);
  free(block);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x200,-0x14(%rbp)
movl   $0x800,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1332 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc0(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1332 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdab(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1280 <main+0x80>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    0x2d5d(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
mov    -0x38(%rbp),%rdi
call   10b0 <ftell@plt>
mov    %eax,-0x18(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x18(%rbp),%esi
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x28(%rbp)
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1316 <main+0x116>
mov    -0x38(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%dl
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12e2 <main+0xe2>
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1639 <main+0x439>
cmpl   $0x3,-0x8(%rbp)
jne    1415 <main+0x215>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcb5(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1415 <main+0x215>
mov    -0x18(%rbp),%esi
lea    0xcda(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    13b1 <main+0x1b1>
mov    $0x0,%al
call   1120 <rand@plt>
mov    %al,%dl
mov    -0x28(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1383 <main+0x183>
lea    0xcbf(%rip),%rdi
lea    0xcc1(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    13e1 <main+0x1e1>
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x1,%esi
call   1110 <fwrite@plt>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xc71(%rip),%rdi
mov    $0x180,%esi
call   10d0 <chmod@plt>
jmp    1634 <main+0x434>
cmpl   $0x4,-0x8(%rbp)
jne    1526 <main+0x326>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xbd2(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1526 <main+0x326>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10f0 <atoi@plt>
mov    $0x200,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1526 <main+0x326>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xbc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    14c2 <main+0x2c2>
mov    $0x0,%al
call   1120 <rand@plt>
mov    %al,%dl
mov    -0x28(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1494 <main+0x294>
lea    0xbae(%rip),%rdi
lea    0xbb0(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    14f2 <main+0x2f2>
mov    0x2ae5(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x58(%rbp),%rcx
mov    $0x1,%esi
call   1110 <fwrite@plt>
mov    -0x58(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xb60(%rip),%rdi
mov    $0x180,%esi
call   10d0 <chmod@plt>
jmp    162f <main+0x42f>
lea    0xbf7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xb47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xb8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xbcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xb6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xb0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xbf7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xb45(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xc2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xb29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xc63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xca7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xaff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xae3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xac4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xa64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    1634 <main+0x434>
jmp    1639 <main+0x439>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd1c(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    166a <main+0x46a>
mov    0x296d(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x60(%rbp),%rdi
mov    0x295d(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
mov    -0x60(%rbp),%rdi
call   10b0 <ftell@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rsi
lea    0xcce(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x6c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x200,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    16e6 <main+0x4e6>
mov    -0x68(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    1707 <main+0x507>
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x60(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x60(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x68(%rbp),%rax
movslq -0x14(%rbp),%rcx
sub    %rcx,%rax
movslq -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rsi
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    0x2891(%rip),%rax
mov    (%rax),%edx
call   10c0 <fseek@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x60(%rbp),%rcx
mov    $0x1,%esi
call   1110 <fwrite@plt>
mov    -0x60(%rbp),%rdi
call   10b0 <ftell@plt>
mov    %rax,%rsi
lea    0xcac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x60(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x4,%edi
je     130f <main+0xef>
cmp    $0x3,%edi
jne    1598 <main+0x378>
mov    0x8(%r14),%rdi
lea    0xdb5(%rip),%rsi
call   10c0 <strcmp@plt>
mov    0x8(%r14),%rdi
test   %rax,%rax
je     13b4 <main+0x194>
lea    0xda5(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     156c <main+0x34c>
mov    %rax,%r12
mov    0x2d6c(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %r12,%rdi
call   10d0 <ftell@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1080 <rewind@plt>
lea    0xd69(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
mov    %rax,%r13
lea    0x1164(%rip),%rdi
call   1050 <puts@plt>
test   %r15d,%r15d
jle    12f6 <main+0xd6>
mov    %r15d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   10a0 <fgetc@plt>
mov    %al,0x0(%r13,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12e0 <main+0xc0>
lea    0x113c(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
jmp    145c <main+0x23c>
mov    0x8(%r14),%rdi
lea    0xce6(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
jne    1598 <main+0x378>
mov    0x18(%r14),%rdi
call   1110 <atoi@plt>
test   $0x1ff,%eax
jne    1598 <main+0x378>
mov    %eax,%r15d
lea    0xcd4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
mov    %rax,%r13
test   %r15d,%r15d
jle    1385 <main+0x165>
mov    %r15d,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1140 <rand@plt>
mov    %al,0x0(%r13,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1370 <main+0x150>
lea    0xcc7(%rip),%rdi
lea    0xcc9(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     156c <main+0x34c>
mov    %rax,%rbx
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
jmp    143b <main+0x21b>
lea    0xc45(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
jne    1598 <main+0x378>
lea    0xc4a(%rip),%rdi
mov    $0x800,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x800,%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
mov    %rax,%r13
xor    %ebx,%ebx
xor    %eax,%eax
call   1140 <rand@plt>
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    $0x800,%rbx
jne    13f0 <main+0x1d0>
lea    0xc43(%rip),%rdi
lea    0xc45(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     156c <main+0x34c>
mov    %rax,%rbx
mov    $0x800,%r15d
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x800,%edx
mov    %rbx,%rcx
call   1130 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xc01(%rip),%rdi
mov    $0x180,%esi
call   10f0 <chmod@plt>
mov    0x10(%r14),%rdi
lea    0xc49(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     156c <main+0x34c>
mov    %rax,%r12
mov    0x10(%r14),%rsi
lea    0xc2f(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2b57(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %r12,%rdi
call   10d0 <ftell@plt>
mov    %rax,%rbx
lea    0xc19(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
test   $0x1ff,%r15d
jne    157a <main+0x35a>
lea    0x200(%r15),%eax
cltq
cmp    %rax,%rbx
jl     157a <main+0x35a>
mov    %r12,%rdi
call   1080 <rewind@plt>
movslq %r15d,%rax
sub    %rax,%rbx
add    $0xfffffffffffffe00,%rbx
lea    0xbe7(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2ad3(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   10e0 <fseek@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r12,%rcx
call   1130 <fwrite@plt>
mov    %r12,%rdi
call   10d0 <ftell@plt>
lea    0xbc9(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1090 <memset@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a5d(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
lea    0xe36(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xdbd(%rip),%r14
mov    %r14,%rdi
call   1050 <puts@plt>
lea    0xd5d(%rip),%rbx
mov    %rbx,%rdi
call   1050 <puts@plt>
lea    0xb68(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1050 <puts@plt>
lea    0xb9d(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
lea    0xbda(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
lea    0xc17(%rip),%rdi
call   1050 <puts@plt>
lea    0xc5c(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
lea    0xc99(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
lea    0xa1f(%rip),%rdi
mov    $0x800,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"genwrite\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@.str.2 = [15 x i8] c"\0AKey Size: %d\0A\00"
@.str.3 = [19 x i8] c"\0A-- Start Key --:\0A\00"
@.str.4 = [17 x i8] c"\0A-- End Key --:\0A\00"
@.str.5 = [57 x i8] c"\0A-- Attempting to create random key(ish --) of size: %d\0A\00"
@.str.6 = [9 x i8] c".tmpckey\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [82 x i8] c"################################################################################\0A\00"
@.str.10 = [82 x i8] c"# #\0A\00"
@.str.11 = [82 x i8] c"# Usage: #\0A\00"
@.str.12 = [82 x i8] c"#> To write existing key to device: #\0A\00"
@.str.13 = [82 x i8] c"# writekey </path/to/keyfile> </path/to/removable/sd*> #\0A\00"
@.str.14 = [82 x i8] c"#> To generate and write pseudo random key, #\0A\00"
@.str.15 = [82 x i8] c"#> key will be saved to temporary file .tmpckey #\0A\00"
@.str.16 = [82 x i8] c"# writekey genwrite </path/to/removable/sd*> <keysize in multiples of 512> #\0A\00"
@.str.17 = [82 x i8] c"#> When keysize is not provided default size is set to %d. #\0A\00"
@.str.18 = [2 x i8] c"a\00"
@.str.19 = [22 x i8] c"\0ADevice to write: %s\0A\00"
@.str.20 = [19 x i8] c"\0ADevice Size: %ld\0A\00"
@.str.21 = [113 x i8] c"\0ASorry but key size is not multiple of block size or device you trying to write to is too small, try again. TA.\0A\00"
@.str.22 = [34 x i8] c"\0AWriting data starting from: %ld\0A\00"
@SEEK_SET = global i32 0
@.str.23 = [50 x i8] c"\0ABlock Position after data write procedure : %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i32*
%12 = alloca i8
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i64
%19 = alloca i32
%20 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 512, i32* %6
store i32 2048, i32* %7
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 3
br i1 %22, label %23, label %72
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %72
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %11
%34 = load i32*, i32** %11
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %29
%40 = load i32*, i32** %11
%41 = load i32, i32* @SEEK_END
%42 = call i32 @fseek(i32* %40, i64 0, i32 %41)
%43 = load i32*, i32** %11
%44 = call i64 @ftell(i32* %43)
%45 = trunc i64 %44 to i32
store i32 %45, i32* %7
%46 = load i32*, i32** %11
%47 = call i32 @rewind(i32* %46)
%48 = load i32, i32* %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %7
%51 = call i8* @calloc(i32 %50, i32 1)
store i8* %51, i8** %9
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %8
br label %53
53: ; preds = %65, %39
%54 = load i32, i32* %8
%55 = load i32, i32* %7
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %68
57: ; preds = %53
%58 = load i32*, i32** %11
%59 = call signext i8 @fgetc(i32* %58)
store i8 %59, i8* %12
%60 = load i8, i8* %12
%61 = load i8*, i8** %9
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 %60, i8* %64
br label %65
65: ; preds = %57
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
store i32 %67, i32* %8
br label %53
68: ; preds = %53
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%70 = load i32*, i32** %11
%71 = call i32 @fclose(i32* %70)
br label %192
72: ; preds = %23, %2
%73 = load i32, i32* %4
%74 = icmp eq i32 %73, 3
br i1 %74, label %75, label %115
75: ; preds = %72
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 1
%78 = load i8*, i8** %77
%79 = call i64 @strcmp(i8* %78, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %115
81: ; preds = %75
%82 = load i32, i32* %7
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i32 %82)
%84 = load i32, i32* %7
%85 = call i8* @calloc(i32 %84, i32 1)
store i8* %85, i8** %9
store i32 0, i32* %13
br label %86
86: ; preds = %97, %81
%87 = load i32, i32* %13
%88 = load i32, i32* %7
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %100
90: ; preds = %86
%91 = call i64 (...) @rand()
%92 = trunc i64 %91 to i8
%93 = load i8*, i8** %9
%94 = load i32, i32* %13
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %93, i64 %95
store i8 %92, i8* %96
br label %97
97: ; preds = %90
%98 = load i32, i32* %13
%99 = add nsw i32 %98, 1
store i32 %99, i32* %13
br label %86
100: ; preds = %86
%101 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %101, i32** %14
%102 = load i32*, i32** %14
%103 = icmp eq i32* %102, null
br i1 %103, label %104, label %107
104: ; preds = %100
%105 = load i32, i32* @EXIT_FAILURE
%106 = call i32 @exit(i32 %105)
unreachable
107: ; preds = %100
%108 = load i8*, i8** %9
%109 = load i32, i32* %7
%110 = load i32*, i32** %14
%111 = call i32 @fwrite(i8* %108, i32 1, i32 %109, i32* %110)
%112 = load i32*, i32** %14
%113 = call i32 @fclose(i32* %112)
%114 = call i32 @chmod(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 384)
br label %191
115: ; preds = %75, %72
%116 = load i32, i32* %4
%117 = icmp eq i32 %116, 4
br i1 %117, label %118, label %169
118: ; preds = %115
%119 = load i8**, i8*** %5
%120 = getelementptr inbounds i8*, i8** %119, i64 1
%121 = load i8*, i8** %120
%122 = call i64 @strcmp(i8* %121, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%123 = icmp eq i64 %122, 0
br i1 %123, label %124, label %169
124: ; preds = %118
%125 = load i8**, i8*** %5
%126 = getelementptr inbounds i8*, i8** %125, i64 3
%127 = load i8*, i8** %126
%128 = call i32 @atoi(i8* %127)
%129 = srem i32 %128, 512
%130 = icmp eq i32 %129, 0
br i1 %130, label %131, label %169
131: ; preds = %124
%132 = load i8**, i8*** %5
%133 = getelementptr inbounds i8*, i8** %132, i64 3
%134 = load i8*, i8** %133
%135 = call i32 @atoi(i8* %134)
store i32 %135, i32* %7
%136 = load i32, i32* %7
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i32 %136)
%138 = load i32, i32* %7
%139 = call i8* @calloc(i32 %138, i32 1)
store i8* %139, i8** %9
store i32 0, i32* %15
br label %140
140: ; preds = %151, %131
%141 = load i32, i32* %15
%142 = load i32, i32* %7
%143 = icmp slt i32 %141, %142
br i1 %143, label %144, label %154
144: ; preds = %140
%145 = call i64 (...) @rand()
%146 = trunc i64 %145 to i8
%147 = load i8*, i8** %9
%148 = load i32, i32* %15
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds i8, i8* %147, i64 %149
store i8 %146, i8* %150
br label %151
151: ; preds = %144
%152 = load i32, i32* %15
%153 = add nsw i32 %152, 1
store i32 %153, i32* %15
br label %140
154: ; preds = %140
%155 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %155, i32** %16
%156 = load i32*, i32** %16
%157 = icmp eq i32* %156, null
br i1 %157, label %158, label %161
158: ; preds = %154
%159 = load i32, i32* @EXIT_FAILURE
%160 = call i32 @exit(i32 %159)
unreachable
161: ; preds = %154
%162 = load i8*, i8** %9
%163 = load i32, i32* %7
%164 = load i32*, i32** %16
%165 = call i32 @fwrite(i8* %162, i32 1, i32 %163, i32* %164)
%166 = load i32*, i32** %16
%167 = call i32 @fclose(i32* %166)
%168 = call i32 @chmod(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 384)
br label %190
169: ; preds = %124, %118, %115
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.9, i64 0, i64 0))
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.10, i64 0, i64 0))
%173 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.11, i64 0, i64 0))
%174 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.10, i64 0, i64 0))
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.9, i64 0, i64 0))
%176 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.12, i64 0, i64 0))
%177 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.10, i64 0, i64 0))
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.13, i64 0, i64 0))
%179 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.10, i64 0, i64 0))
%180 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.14, i64 0, i64 0))
%181 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.15, i64 0, i64 0))
%182 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.10, i64 0, i64 0))
%183 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.16, i64 0, i64 0))
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.10, i64 0, i64 0))
%185 = load i32, i32* %7
%186 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.17, i64 0, i64 0), i32 %185)
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.10, i64 0, i64 0))
%188 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.9, i64 0, i64 0))
%189 = call i32 @exit(i32 1)
unreachable
190: ; preds = %161
br label %191
191: ; preds = %190, %107
br label %192
192: ; preds = %191, %68
%193 = load i8**, i8*** %5
%194 = getelementptr inbounds i8*, i8** %193, i64 2
%195 = load i8*, i8** %194
%196 = call i32* @fopen(i8* %195, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
store i32* %196, i32** %17
%197 = load i32*, i32** %17
%198 = icmp eq i32* %197, null
br i1 %198, label %199, label %202
199: ; preds = %192
%200 = load i32, i32* @EXIT_FAILURE
%201 = call i32 @exit(i32 %200)
unreachable
202: ; preds = %192
%203 = load i8**, i8*** %5
%204 = getelementptr inbounds i8*, i8** %203, i64 2
%205 = load i8*, i8** %204
%206 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.19, i64 0, i64 0), i8* %205)
%207 = load i32*, i32** %17
%208 = load i32, i32* @SEEK_END
%209 = call i32 @fseek(i32* %207, i64 0, i32 %208)
%210 = load i32*, i32** %17
%211 = call i64 @ftell(i32* %210)
store i64 %211, i64* %18
%212 = load i64, i64* %18
%213 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.20, i64 0, i64 0), i64 %212)
store i32 0, i32* %19
%214 = load i32, i32* %7
%215 = srem i32 %214, 512
%216 = icmp ne i32 %215, 0
br i1 %216, label %224, label %217
217: ; preds = %202
%218 = load i64, i64* %18
%219 = load i32, i32* %6
%220 = load i32, i32* %7
%221 = add nsw i32 %219, %220
%222 = sext i32 %221 to i64
%223 = icmp slt i64 %218, %222
br i1 %223, label %224, label %229
224: ; preds = %217, %202
%225 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([113 x i8], [113 x i8]* @.str.21, i64 0, i64 0))
%226 = load i32*, i32** %17
%227 = call i32 @fclose(i32* %226)
%228 = call i32 @exit(i32 1)
unreachable
229: ; preds = %217
%230 = load i32*, i32** %17
%231 = call i32 @rewind(i32* %230)
%232 = load i64, i64* %18
%233 = load i32, i32* %6
%234 = sext i32 %233 to i64
%235 = sub nsw i64 %232, %234
%236 = load i32, i32* %7
%237 = sext i32 %236 to i64
%238 = sub nsw i64 %235, %237
store i64 %238, i64* %20
%239 = load i64, i64* %20
%240 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.22, i64 0, i64 0), i64 %239)
%241 = load i32*, i32** %17
%242 = load i64, i64* %20
%243 = load i32, i32* @SEEK_SET
%244 = call i32 @fseek(i32* %241, i64 %242, i32 %243)
%245 = load i8*, i8** %9
%246 = load i32, i32* %7
%247 = load i32*, i32** %17
%248 = call i32 @fwrite(i8* %245, i32 1, i32 %246, i32* %247)
%249 = load i32*, i32** %17
%250 = call i64 @ftell(i32* %249)
%251 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.23, i64 0, i64 0), i64 %250)
%252 = load i32*, i32** %17
%253 = call i32 @fclose(i32* %252)
%254 = load i8*, i8** %9
%255 = load i32, i32* %7
%256 = call i32 @memset(i8* %254, i32 0, i32 %255)
%257 = load i8*, i8** %9
%258 = call i32 @free(i8* %257)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"genwrite\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@.str.2 = [15 x i8] c"\0AKey Size: %d\0A\00"
@.str.5 = [57 x i8] c"\0A-- Attempting to create random key(ish --) of size: %d\0A\00"
@.str.6 = [9 x i8] c".tmpckey\00"
@.str.7 = [2 x i8] c"w\00"
@.str.17 = [82 x i8] c"#> When keysize is not provided default size is set to %d. #\0A\00"
@.str.18 = [2 x i8] c"a\00"
@.str.19 = [22 x i8] c"\0ADevice to write: %s\0A\00"
@.str.20 = [19 x i8] c"\0ADevice Size: %ld\0A\00"
@.str.22 = [34 x i8] c"\0AWriting data starting from: %ld\0A\00"
@SEEK_SET = global i32 0
@.str.23 = [50 x i8] c"\0ABlock Position after data write procedure : %ld\0A\00"
@str.25 = [81 x i8] c"# Usage: #\00"
@str.28 = [81 x i8] c"#> To write existing key to device: #\00"
@str.30 = [81 x i8] c"# writekey </path/to/keyfile> </path/to/removable/sd*> #\00"
@str.32 = [81 x i8] c"#> To generate and write pseudo random key, #\00"
@str.33 = [81 x i8] c"#> key will be saved to temporary file .tmpckey #\00"
@str.35 = [81 x i8] c"# writekey genwrite </path/to/removable/sd*> <keysize in multiples of 512> #\00"
@str.37 = [81 x i8] c"# #\00"
@str.38 = [81 x i8] c"################################################################################\00"
@str.39 = [112 x i8] c"\0ASorry but key size is not multiple of block size or device you trying to write to is too small, try again. TA.\00"
@str.40 = [18 x i8] c"\0A-- Start Key --:\00"
@str.41 = [16 x i8] c"\0A-- End Key --:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %93 [
i32 3, label %3
i32 4, label %59
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
%8 = load i8*, i8** %4
br i1 %7, label %36, label %9
9: ; preds = %3
%10 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %9
%16 = load i32, i32* @SEEK_END
%17 = tail call i32 @fseek(i32* %10, i64 0, i32 %16)
%18 = tail call i64 @ftell(i32* %10)
%19 = trunc i64 %18 to i32
%20 = tail call i32 @rewind(i32* %10)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%22 = tail call i8* @calloc(i32 %19, i32 1)
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.40, i64 0, i64 0))
%24 = icmp sgt i32 %19, 0
br i1 %24, label %25, label %33
25: ; preds = %15
%26 = and i64 %18, 4294967295
br label %27
27: ; preds = %25, %27
%28 = phi i64 [ 0, %25 ], [ %31, %27 ]
%29 = tail call signext i8 @fgetc(i32* %10)
%30 = getelementptr inbounds i8, i8* %22, i64 %28
store i8 %29, i8* %30
%31 = add nuw nsw i64 %28, 1
%32 = icmp eq i64 %31, %26
br i1 %32, label %33, label %27
33: ; preds = %27, %15
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.41, i64 0, i64 0))
%35 = tail call i32 @fclose(i32* %10)
br label %113
36: ; preds = %3
%37 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %93
39: ; preds = %36
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i32 2048)
%41 = tail call dereferenceable_or_null(2048) i8* @calloc(i32 2048, i32 1)
br label %42
42: ; preds = %39, %42
%43 = phi i64 [ 0, %39 ], [ %47, %42 ]
%44 = tail call i64 (...) @rand()
%45 = trunc i64 %44 to i8
%46 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 %45, i8* %46
%47 = add nuw nsw i64 %43, 1
%48 = icmp eq i64 %47, 2048
br i1 %48, label %49, label %42
49: ; preds = %42
%50 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32, i32* @EXIT_FAILURE
%54 = tail call i32 @exit(i32 %53)
unreachable
55: ; preds = %49
%56 = tail call i32 @fwrite(i8* %41, i32 1, i32 2048, i32* %50)
%57 = tail call i32 @fclose(i32* %50)
%58 = tail call i32 @chmod(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 384)
br label %113
59: ; preds = %2
%60 = getelementptr inbounds i8*, i8** %1, i64 1
%61 = load i8*, i8** %60
%62 = tail call i64 @strcmp(i8* %61, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %93
64: ; preds = %59
%65 = getelementptr inbounds i8*, i8** %1, i64 3
%66 = load i8*, i8** %65
%67 = tail call i32 @atoi(i8* %66)
%68 = and i32 %67, 511
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %93
70: ; preds = %64
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i32 %67)
%72 = tail call i8* @calloc(i32 %67, i32 1)
%73 = icmp sgt i32 %67, 0
br i1 %73, label %74, label %83
74: ; preds = %70
%75 = zext i32 %67 to i64
br label %76
76: ; preds = %74, %76
%77 = phi i64 [ 0, %74 ], [ %81, %76 ]
%78 = tail call i64 (...) @rand()
%79 = trunc i64 %78 to i8
%80 = getelementptr inbounds i8, i8* %72, i64 %77
store i8 %79, i8* %80
%81 = add nuw nsw i64 %77, 1
%82 = icmp eq i64 %81, %75
br i1 %82, label %83, label %76
83: ; preds = %76, %70
%84 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%85 = icmp eq i32* %84, null
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i32, i32* @EXIT_FAILURE
%88 = tail call i32 @exit(i32 %87)
unreachable
89: ; preds = %83
%90 = tail call i32 @fwrite(i8* %72, i32 1, i32 %67, i32* %84)
%91 = tail call i32 @fclose(i32* %84)
%92 = tail call i32 @chmod(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 384)
br label %113
93: ; preds = %2, %36, %64, %59
%94 = tail call i32 @putchar(i32 10)
%95 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.38, i64 0, i64 0))
%96 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.37, i64 0, i64 0))
%97 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.25, i64 0, i64 0))
%98 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.37, i64 0, i64 0))
%99 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.38, i64 0, i64 0))
%100 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.28, i64 0, i64 0))
%101 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.37, i64 0, i64 0))
%102 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.30, i64 0, i64 0))
%103 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.37, i64 0, i64 0))
%104 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.32, i64 0, i64 0))
%105 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.33, i64 0, i64 0))
%106 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.37, i64 0, i64 0))
%107 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.35, i64 0, i64 0))
%108 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.37, i64 0, i64 0))
%109 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.17, i64 0, i64 0), i32 2048)
%110 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.37, i64 0, i64 0))
%111 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @str.38, i64 0, i64 0))
%112 = tail call i32 @exit(i32 1)
unreachable
113: ; preds = %55, %89, %33
%114 = phi i8* [ %22, %33 ], [ %41, %55 ], [ %72, %89 ]
%115 = phi i32 [ %19, %33 ], [ 2048, %55 ], [ %67, %89 ]
%116 = getelementptr inbounds i8*, i8** %1, i64 2
%117 = load i8*, i8** %116
%118 = tail call i32* @fopen(i8* %117, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
%119 = icmp eq i32* %118, null
br i1 %119, label %120, label %123
120: ; preds = %113
%121 = load i32, i32* @EXIT_FAILURE
%122 = tail call i32 @exit(i32 %121)
unreachable
123: ; preds = %113
%124 = load i8*, i8** %116
%125 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.19, i64 0, i64 0), i8* %124)
%126 = load i32, i32* @SEEK_END
%127 = tail call i32 @fseek(i32* %118, i64 0, i32 %126)
%128 = tail call i64 @ftell(i32* %118)
%129 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.20, i64 0, i64 0), i64 %128)
%130 = and i32 %115, 511
%131 = icmp eq i32 %130, 0
br i1 %131, label %132, label %136
132: ; preds = %123
%133 = add nsw i32 %115, 512
%134 = sext i32 %133 to i64
%135 = icmp slt i64 %128, %134
br i1 %135, label %136, label %140
136: ; preds = %132, %123
%137 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([112 x i8], [112 x i8]* @str.39, i64 0, i64 0))
%138 = tail call i32 @fclose(i32* %118)
%139 = tail call i32 @exit(i32 1)
unreachable
140: ; preds = %132
%141 = tail call i32 @rewind(i32* %118)
%142 = sext i32 %115 to i64
%143 = sub nsw i64 -512, %142
%144 = add i64 %143, %128
%145 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.22, i64 0, i64 0), i64 %144)
%146 = load i32, i32* @SEEK_SET
%147 = tail call i32 @fseek(i32* %118, i64 %144, i32 %146)
%148 = tail call i32 @fwrite(i8* %114, i32 1, i32 %115, i32* %118)
%149 = tail call i64 @ftell(i32* %118)
%150 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.23, i64 0, i64 0), i64 %149)
%151 = tail call i32 @fclose(i32* %118)
%152 = tail call i32 @memset(i8* %114, i32 0, i32 %115)
%153 = tail call i32 @free(i8* %114)
ret i32 0
}