#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 scalar_t__ uint32_t;
struct pointerFile {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ EVP_CIPHER_CTX;

/* Variables and functions */
int /*<<< orphan*/ cleanupContext(int /*<<< orphan*/ *);
int /*<<< orphan*/ copyFile(char *, char *);
struct pointerFile *createPtrFile(char *);
int /*<<< orphan*/ doGCMDecrypt(struct pointerFile *, unsigned char *);
int /*<<< orphan*/ *encryptKeyStreamSetup(char *, scalar_t__, unsigned char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(scalar_t__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(struct pointerFile *);
int /*<<< orphan*/ fwrite(scalar_t__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
struct pointerFile *readPtrFile(char *, char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ scryptLogout(struct pointerFile *);
int /*<<< orphan*/ *setupCTR(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ verifyPtrFile(struct pointerFile *);
int /*<<< orphan*/ writeFile(char *, scalar_t__, int /*<<< orphan*/ *,
                             int /*<<< orphan*/ *, char *);
int generateChunks(char *path, char *ptrPath, uint32_t chunksNo,
                   uint32_t fileSize, char *secondaryPath,
                   char *secondaryPtrPath) {
  int isSecondFile = secondaryPath[0] != '\0';
  char progressPath[150];
  FILE *prog1, *prog2;
  uint32_t progCtr1, progCtr2;
  progCtr1 = progCtr2 = 0;
  int lastFailed = 0;
  sprintf(progressPath, "%s/progress.lock", path);
  prog1 = fopen(progressPath, "r+");
  if (prog1 != NULL)
    lastFailed = 1;
  if (isSecondFile && lastFailed) {
    sprintf(progressPath, "%s/progress.lock", secondaryPath);
    prog2 = fopen(progressPath, "r+");
    if (prog2 != NULL) {
      printf("Last run on disk 1 failed, but disk 2 shows no sign of those "
             "this. Resume failed.");
      exit(-1);
    }
  }
  uint32_t startingChunk = 0;
  struct pointerFile *ptr;
  if (lastFailed) {
    fread(&progCtr1, sizeof(uint32_t), 1, prog1);
    if (isSecondFile)
      fread(&progCtr2, sizeof(uint32_t), 1, prog2);
    if (isSecondFile && (progCtr1 != progCtr2)) {
      printf("Disks are showing differing progress");
      exit(-1);
    }
    startingChunk = progCtr1;
    ptr = readPtrFile(ptrPath, "nextAvailable.ptr");
  } else {
    sprintf(progressPath, "%s/progress.lock", path);
    prog1 = fopen(progressPath, "w");
    sprintf(progressPath, "%s/progress.lock", secondaryPath);
    prog2 = fopen(progressPath, "w");
    ptr = createPtrFile(ptrPath);
  }
  verifyPtrFile(ptr);
  char filename[150];
  char filename2[150];
  for (uint32_t i = startingChunk; i < chunksNo; i++) {
    EVP_CIPHER_CTX *context = setupCTR(NULL, NULL);
    unsigned char k2[16];
    doGCMDecrypt(ptr, k2);
    EVP_CIPHER_CTX *cipherContext = encryptKeyStreamSetup(path, i, k2);
    sprintf(filename, "%s/%u.bin", path, i);
    if (isSecondFile) {
      sprintf(filename2, "%s/%u.bin", secondaryPath, i);
    } else {
      filename2[0] = '\0';
    }
    writeFile(filename, fileSize, context, cipherContext, filename2);
    cleanupContext(context);
    cleanupContext(cipherContext);
    progCtr1++;
    progCtr2++;
    fwrite(&progCtr1, sizeof(uint32_t), 1, prog1);
    fflush(prog1);
    rewind(prog1);
    if (isSecondFile) {
      fwrite(&progCtr2, sizeof(uint32_t), 1, prog2);
      fflush(prog2);
      rewind(prog2);
    }
  }
  verifyPtrFile(ptr);
  scryptLogout(ptr);
  fclose(prog1);
  sprintf(progressPath, "%s/progress.lock", path);
  remove(progressPath);
  if (isSecondFile) {
    char src[100], dest[100];
    sprintf(src, "%s/keys", path);
    sprintf(dest, "%s/keys", secondaryPath);
    copyFile(dest, src);
    sprintf(src, "%s/nextAvailable.ptr", ptrPath);
    sprintf(dest, "%s/nextAvailable.ptr", secondaryPtrPath);
    copyFile(dest, src);
    fclose(prog2);
    sprintf(progressPath, "%s/progress.lock", secondaryPath);
    remove(progressPath);
  }
  free(ptr);
}


x86 assembly (clang, -O0):
<generateChunks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
movq   $0x0,-0x100(%rbp)
movq   $0x0,-0xf8(%rbp)
movl   $0x0,-0x104(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd46(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
lea    0xd42(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0xe8(%rbp)
cmpq   $0x0,-0xe8(%rbp)
je     12f3 <generateChunks+0xa3>
movl   $0x1,-0x104(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1366 <generateChunks+0x116>
cmpl   $0x0,-0x104(%rbp)
je     1366 <generateChunks+0x116>
lea    -0xe0(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xce4(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
lea    0xce0(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0xf0(%rbp)
cmpq   $0x0,-0xf0(%rbp)
je     1361 <generateChunks+0x111>
lea    0xcc2(%rip),%rdi
call   1080 <printf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
jmp    1366 <generateChunks+0x116>
movq   $0x0,-0x110(%rbp)
cmpl   $0x0,-0x104(%rbp)
je     1420 <generateChunks+0x1d0>
mov    -0xe8(%rbp),%rcx
lea    -0xf8(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1060 <fread@plt>
cmpl   $0x0,-0x3c(%rbp)
je     13c2 <generateChunks+0x172>
mov    -0xf0(%rbp),%rcx
lea    -0x100(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1060 <fread@plt>
cmpl   $0x0,-0x3c(%rbp)
je     13f6 <generateChunks+0x1a6>
mov    -0xf8(%rbp),%rax
cmp    -0x100(%rbp),%rax
je     13f6 <generateChunks+0x1a6>
lea    0xc7f(%rip),%rdi
call   1080 <printf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>
mov    -0xf8(%rbp),%rax
mov    %rax,-0x110(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xc93(%rip),%rsi
call   10d0 <readPtrFile@plt>
mov    %rax,-0x118(%rbp)
jmp    1496 <generateChunks+0x246>
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xbce(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
lea    0xc44(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0xe8(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xb9b(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
lea    0xc11(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0xf0(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <createPtrFile@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
call   1170 <verifyPtrFile@plt>
mov    -0x110(%rbp),%rax
mov    %rax,-0x258(%rbp)
mov    -0x258(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    164c <generateChunks+0x3fc>
xor    %eax,%eax
mov    %eax,%esi
mov    %rsi,%rdi
call   1120 <setupCTR@plt>
mov    %rax,-0x260(%rbp)
mov    -0x118(%rbp),%rdi
lea    -0x270(%rbp),%rsi
call   10e0 <doGCMDecrypt@plt>
mov    -0x10(%rbp),%rdi
mov    -0x258(%rbp),%rsi
lea    -0x270(%rbp),%rdx
call   1050 <encryptKeyStreamSetup@plt>
mov    %rax,-0x278(%rbp)
lea    -0x1b0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x258(%rbp),%rcx
lea    0xb6f(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
cmpl   $0x0,-0x3c(%rbp)
je     1554 <generateChunks+0x304>
lea    -0x250(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x258(%rbp),%rcx
lea    0xb45(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
jmp    155b <generateChunks+0x30b>
movb   $0x0,-0x250(%rbp)
lea    -0x1b0(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x260(%rbp),%rdx
mov    -0x278(%rbp),%rcx
lea    -0x250(%rbp),%r8
call   10b0 <writeFile@plt>
mov    -0x260(%rbp),%rdi
call   1140 <cleanupContext@plt>
mov    -0x278(%rbp),%rdi
call   1140 <cleanupContext@plt>
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
mov    -0x100(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x100(%rbp)
mov    -0xe8(%rbp),%rcx
lea    -0xf8(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1160 <fwrite@plt>
mov    -0xe8(%rbp),%rdi
call   10c0 <fflush@plt>
mov    -0xe8(%rbp),%rdi
call   1090 <rewind@plt>
cmpl   $0x0,-0x3c(%rbp)
je     1630 <generateChunks+0x3e0>
mov    -0xf0(%rbp),%rcx
lea    -0x100(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1160 <fwrite@plt>
mov    -0xf0(%rbp),%rdi
call   10c0 <fflush@plt>
mov    -0xf0(%rbp),%rdi
call   1090 <rewind@plt>
jmp    1635 <generateChunks+0x3e5>
mov    -0x258(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x258(%rbp)
jmp    14b0 <generateChunks+0x260>
mov    -0x118(%rbp),%rdi
call   1170 <verifyPtrFile@plt>
mov    -0x118(%rbp),%rdi
call   1100 <scryptLogout@plt>
mov    -0xe8(%rbp),%rdi
call   1070 <fclose@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0x97e(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
call   1040 <remove@plt>
cmpl   $0x0,-0x3c(%rbp)
je     175a <generateChunks+0x50a>
lea    -0x2e0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0x9e6(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0x350(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0x9cd(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0x350(%rbp),%rdi
lea    -0x2e0(%rbp),%rsi
call   10f0 <copyFile@plt>
lea    -0x2e0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0x9a9(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0x350(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0x990(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0x350(%rbp),%rdi
lea    -0x2e0(%rbp),%rsi
call   10f0 <copyFile@plt>
mov    -0xf0(%rbp),%rdi
call   1070 <fclose@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0x8b9(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x118(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateChunks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x318,%rsp
mov    %r9,%r15
mov    %rcx,0x58(%rsp)
mov    %rdx,0x38(%rsp)
mov    %rsi,%r12
mov    %rdi,%r13
mov    %r8,0x10(%rsp)
mov    (%r8),%bl
movq   $0x0,0x18(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xd6b(%rip),%rsi
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1130 <sprintf@plt>
lea    0xd63(%rip),%rsi
mov    %rbp,%rdi
call   1110 <fopen@plt>
mov    %rax,%rbp
mov    %bl,0x7(%rsp)
test   %bl,%bl
je     12f9 <generateChunks+0xa9>
test   %rbp,%rbp
je     12f9 <generateChunks+0xa9>
lea    0xd33(%rip),%rsi
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1130 <sprintf@plt>
lea    0xd29(%rip),%rsi
mov    %rbx,%rdi
call   1110 <fopen@plt>
test   %rax,%rax
jne    165f <generateChunks+0x40f>
test   %rbp,%rbp
mov    %r13,0x30(%rsp)
mov    %r15,0x48(%rsp)
mov    %r12,0x40(%rsp)
je     135d <generateChunks+0x10d>
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1060 <fread@plt>
cmpb   $0x0,0x7(%rsp)
je     13c5 <generateChunks+0x175>
lea    0x18(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <fread@plt>
mov    0x8(%rsp),%r13
cmp    0x18(%rsp),%r13
je     13ca <generateChunks+0x17a>
lea    0xd0e(%rip),%rdi
jmp    1666 <generateChunks+0x416>
mov    %r12,%r15
lea    0xc99(%rip),%r12
mov    %r13,%rdx
xor    %r13d,%r13d
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1130 <sprintf@plt>
lea    0xd05(%rip),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1110 <fopen@plt>
mov    %rax,0x28(%rsp)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1130 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1110 <fopen@plt>
mov    %rax,0x20(%rsp)
mov    %r15,%rdi
call   10a0 <createPtrFile@plt>
mov    %rax,%rbp
jmp    13e8 <generateChunks+0x198>
mov    0x8(%rsp),%r13
mov    %rbp,0x28(%rsp)
lea    0xccc(%rip),%rsi
mov    %r12,%rdi
call   10d0 <readPtrFile@plt>
mov    %rax,%rbp
xor    %eax,%eax
mov    %rax,0x20(%rsp)
mov    %rbp,%rdi
call   1170 <verifyPtrFile@plt>
cmp    0x38(%rsp),%r13
jge    154c <generateChunks+0x2fc>
lea    0xc8b(%rip),%r14
lea    0x170(%rsp),%r12
mov    %rbp,0x50(%rsp)
mov    0x30(%rsp),%r15
jmp    142f <generateChunks+0x1df>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r13,0x38(%rsp)
je     154c <generateChunks+0x2fc>
xor    %edi,%edi
xor    %esi,%esi
call   1120 <setupCTR@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
lea    0x100(%rsp),%rbp
mov    %rbp,%rsi
call   10e0 <doGCMDecrypt@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1050 <encryptKeyStreamSetup@plt>
mov    %rax,%rbp
lea    0x210(%rsp),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1130 <sprintf@plt>
cmpb   $0x0,0x7(%rsp)
je     14a0 <generateChunks+0x250>
mov    %r12,%rdi
mov    %r14,%rsi
mov    0x10(%rsp),%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1130 <sprintf@plt>
jmp    14a8 <generateChunks+0x258>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,0x170(%rsp)
lea    0x210(%rsp),%rdi
mov    0x58(%rsp),%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r12,%r8
call   10b0 <writeFile@plt>
mov    %rbx,%rdi
call   1140 <cleanupContext@plt>
mov    %rbp,%rdi
call   1140 <cleanupContext@plt>
addq   $0x1,0x8(%rsp)
addq   $0x1,0x18(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    0x28(%rsp),%rbx
mov    %rbx,%rcx
call   1160 <fwrite@plt>
mov    %rbx,%rdi
call   10c0 <fflush@plt>
mov    %rbx,%rdi
call   1090 <rewind@plt>
cmpb   $0x0,0x7(%rsp)
mov    0x50(%rsp),%rbp
je     1420 <generateChunks+0x1d0>
lea    0x18(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    0x20(%rsp),%rbx
mov    %rbx,%rcx
call   1160 <fwrite@plt>
mov    %rbx,%rdi
call   10c0 <fflush@plt>
mov    %rbx,%rdi
call   1090 <rewind@plt>
jmp    1420 <generateChunks+0x1d0>
mov    %rbp,%rdi
call   1170 <verifyPtrFile@plt>
mov    %rbp,%rdi
call   1100 <scryptLogout@plt>
mov    0x28(%rsp),%rdi
call   1070 <fclose@plt>
lea    0xa93(%rip),%rsi
lea    0x60(%rsp),%r14
mov    %r14,%rdi
mov    0x30(%rsp),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1130 <sprintf@plt>
mov    %r14,%rdi
call   1040 <remove@plt>
cmpb   $0x0,0x7(%rsp)
je     1645 <generateChunks+0x3f5>
lea    0xaf9(%rip),%r14
mov    %rbp,%r12
lea    0x100(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1130 <sprintf@plt>
lea    0x2b0(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
mov    0x10(%rsp),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1130 <sprintf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10f0 <copyFile@plt>
lea    0xab7(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    0x40(%rsp),%rdx
xor    %eax,%eax
call   1130 <sprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    0x48(%rsp),%rdx
xor    %eax,%eax
call   1130 <sprintf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rbp
call   10f0 <copyFile@plt>
mov    0x20(%rsp),%rdi
call   1070 <fclose@plt>
lea    0x9d5(%rip),%rsi
lea    0x60(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1130 <sprintf@plt>
mov    %r14,%rdi
call   1040 <remove@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x318,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x9ae(%rip),%rdi
call   1080 <printf@plt>
mov    $0xffffffff,%edi
call   1150 <exit@plt>

LLVM IR (-O0):
%struct.pointerFile = type { i32 }
@.str = [17 x i8] c"%s/progress.lock\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [82 x i8] c"Last run on disk 1 failed, but disk 2 shows no sign of those this. Resume failed.\00"
@.str.3 = [37 x i8] c"Disks are showing differing progress\00"
@.str.4 = [18 x i8] c"nextAvailable.ptr\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [10 x i8] c"%s/%u.bin\00"
@.str.7 = [8 x i8] c"%s/keys\00"
@.str.8 = [21 x i8] c"%s/nextAvailable.ptr\00"
define i32 @generateChunks(i8* %0, i8* %1, i64 %2, i64 %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca [150 x i8]
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i64
%19 = alloca i64
%20 = alloca i32
%21 = alloca i64
%22 = alloca %struct.pointerFile*
%23 = alloca [150 x i8]
%24 = alloca [150 x i8]
%25 = alloca i64
%26 = alloca i32*
%27 = alloca [16 x i8]
%28 = alloca i32*
%29 = alloca [100 x i8]
%30 = alloca [100 x i8]
store i8* %0, i8** %8
store i8* %1, i8** %9
store i64 %2, i64* %10
store i64 %3, i64* %11
store i8* %4, i8** %12
store i8* %5, i8** %13
%31 = load i8*, i8** %12
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i32
store i32 %36, i32* %14
store i64 0, i64* %19
store i64 0, i64* %18
store i32 0, i32* %20
%37 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%38 = load i8*, i8** %8
%39 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %41, i32** %16
%42 = load i32*, i32** %16
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %45
44: ; preds = %6
store i32 1, i32* %20
br label %45
45: ; preds = %44, %6
%46 = load i32, i32* %14
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %63
48: ; preds = %45
%49 = load i32, i32* %20
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %63
51: ; preds = %48
%52 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%53 = load i8*, i8** %12
%54 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %52, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %53)
%55 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%56 = call i32* @fopen(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %56, i32** %17
%57 = load i32*, i32** %17
%58 = icmp ne i32* %57, null
br i1 %58, label %59, label %62
59: ; preds = %51
%60 = call i32 @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0))
%61 = call i32 @exit(i32 -1)
unreachable
62: ; preds = %51
br label %63
63: ; preds = %62, %48, %45
store i64 0, i64* %21
%64 = load i32, i32* %20
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %88
66: ; preds = %63
%67 = load i32*, i32** %16
%68 = call i32 @fread(i64* %18, i32 8, i32 1, i32* %67)
%69 = load i32, i32* %14
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %66
%72 = load i32*, i32** %17
%73 = call i32 @fread(i64* %19, i32 8, i32 1, i32* %72)
br label %74
74: ; preds = %71, %66
%75 = load i32, i32* %14
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %84
77: ; preds = %74
%78 = load i64, i64* %18
%79 = load i64, i64* %19
%80 = icmp ne i64 %78, %79
br i1 %80, label %81, label %84
81: ; preds = %77
%82 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%83 = call i32 @exit(i32 -1)
unreachable
84: ; preds = %77, %74
%85 = load i64, i64* %18
store i64 %85, i64* %21
%86 = load i8*, i8** %9
%87 = call %struct.pointerFile* @readPtrFile(i8* %86, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
store %struct.pointerFile* %87, %struct.pointerFile** %22
br label %101
88: ; preds = %63
%89 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%90 = load i8*, i8** %8
%91 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %89, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %90)
%92 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%93 = call i32* @fopen(i8* %92, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %93, i32** %16
%94 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%95 = load i8*, i8** %12
%96 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %94, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %95)
%97 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%98 = call i32* @fopen(i8* %97, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %98, i32** %17
%99 = load i8*, i8** %9
%100 = call %struct.pointerFile* @createPtrFile(i8* %99)
store %struct.pointerFile* %100, %struct.pointerFile** %22
br label %101
101: ; preds = %88, %84
%102 = load %struct.pointerFile*, %struct.pointerFile** %22
%103 = call i32 @verifyPtrFile(%struct.pointerFile* %102)
%104 = load i64, i64* %21
store i64 %104, i64* %25
br label %105
105: ; preds = %162, %101
%106 = load i64, i64* %25
%107 = load i64, i64* %10
%108 = icmp slt i64 %106, %107
br i1 %108, label %109, label %165
109: ; preds = %105
%110 = call i32* @setupCTR(i32* null, i32* null)
store i32* %110, i32** %26
%111 = load %struct.pointerFile*, %struct.pointerFile** %22
%112 = getelementptr inbounds [16 x i8], [16 x i8]* %27, i64 0, i64 0
%113 = call i32 @doGCMDecrypt(%struct.pointerFile* %111, i8* %112)
%114 = load i8*, i8** %8
%115 = load i64, i64* %25
%116 = getelementptr inbounds [16 x i8], [16 x i8]* %27, i64 0, i64 0
%117 = call i32* @encryptKeyStreamSetup(i8* %114, i64 %115, i8* %116)
store i32* %117, i32** %28
%118 = getelementptr inbounds [150 x i8], [150 x i8]* %23, i64 0, i64 0
%119 = load i8*, i8** %8
%120 = load i64, i64* %25
%121 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %118, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %119, i64 %120)
%122 = load i32, i32* %14
%123 = icmp ne i32 %122, 0
br i1 %123, label %124, label %129
124: ; preds = %109
%125 = getelementptr inbounds [150 x i8], [150 x i8]* %24, i64 0, i64 0
%126 = load i8*, i8** %12
%127 = load i64, i64* %25
%128 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %125, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %126, i64 %127)
br label %131
129: ; preds = %109
%130 = getelementptr inbounds [150 x i8], [150 x i8]* %24, i64 0, i64 0
store i8 0, i8* %130
br label %131
131: ; preds = %129, %124
%132 = getelementptr inbounds [150 x i8], [150 x i8]* %23, i64 0, i64 0
%133 = load i64, i64* %11
%134 = load i32*, i32** %26
%135 = load i32*, i32** %28
%136 = getelementptr inbounds [150 x i8], [150 x i8]* %24, i64 0, i64 0
%137 = call i32 @writeFile(i8* %132, i64 %133, i32* %134, i32* %135, i8* %136)
%138 = load i32*, i32** %26
%139 = call i32 @cleanupContext(i32* %138)
%140 = load i32*, i32** %28
%141 = call i32 @cleanupContext(i32* %140)
%142 = load i64, i64* %18
%143 = add nsw i64 %142, 1
store i64 %143, i64* %18
%144 = load i64, i64* %19
%145 = add nsw i64 %144, 1
store i64 %145, i64* %19
%146 = load i32*, i32** %16
%147 = call i32 @fwrite(i64* %18, i32 8, i32 1, i32* %146)
%148 = load i32*, i32** %16
%149 = call i32 @fflush(i32* %148)
%150 = load i32*, i32** %16
%151 = call i32 @rewind(i32* %150)
%152 = load i32, i32* %14
%153 = icmp ne i32 %152, 0
br i1 %153, label %154, label %161
154: ; preds = %131
%155 = load i32*, i32** %17
%156 = call i32 @fwrite(i64* %19, i32 8, i32 1, i32* %155)
%157 = load i32*, i32** %17
%158 = call i32 @fflush(i32* %157)
%159 = load i32*, i32** %17
%160 = call i32 @rewind(i32* %159)
br label %161
161: ; preds = %154, %131
br label %162
162: ; preds = %161
%163 = load i64, i64* %25
%164 = add nsw i64 %163, 1
store i64 %164, i64* %25
br label %105
165: ; preds = %105
%166 = load %struct.pointerFile*, %struct.pointerFile** %22
%167 = call i32 @verifyPtrFile(%struct.pointerFile* %166)
%168 = load %struct.pointerFile*, %struct.pointerFile** %22
%169 = call i32 @scryptLogout(%struct.pointerFile* %168)
%170 = load i32*, i32** %16
%171 = call i32 @fclose(i32* %170)
%172 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%173 = load i8*, i8** %8
%174 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %172, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %173)
%175 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%176 = call i32 @remove(i8* %175)
%177 = load i32, i32* %14
%178 = icmp ne i32 %177, 0
br i1 %178, label %179, label %205
179: ; preds = %165
%180 = getelementptr inbounds [100 x i8], [100 x i8]* %29, i64 0, i64 0
%181 = load i8*, i8** %8
%182 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %180, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %181)
%183 = getelementptr inbounds [100 x i8], [100 x i8]* %30, i64 0, i64 0
%184 = load i8*, i8** %12
%185 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %183, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %184)
%186 = getelementptr inbounds [100 x i8], [100 x i8]* %30, i64 0, i64 0
%187 = getelementptr inbounds [100 x i8], [100 x i8]* %29, i64 0, i64 0
%188 = call i32 @copyFile(i8* %186, i8* %187)
%189 = getelementptr inbounds [100 x i8], [100 x i8]* %29, i64 0, i64 0
%190 = load i8*, i8** %9
%191 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %189, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %190)
%192 = getelementptr inbounds [100 x i8], [100 x i8]* %30, i64 0, i64 0
%193 = load i8*, i8** %13
%194 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %192, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %193)
%195 = getelementptr inbounds [100 x i8], [100 x i8]* %30, i64 0, i64 0
%196 = getelementptr inbounds [100 x i8], [100 x i8]* %29, i64 0, i64 0
%197 = call i32 @copyFile(i8* %195, i8* %196)
%198 = load i32*, i32** %17
%199 = call i32 @fclose(i32* %198)
%200 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%201 = load i8*, i8** %12
%202 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %200, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %201)
%203 = getelementptr inbounds [150 x i8], [150 x i8]* %15, i64 0, i64 0
%204 = call i32 @remove(i8* %203)
br label %205
205: ; preds = %179, %165
%206 = load %struct.pointerFile*, %struct.pointerFile** %22
%207 = call i32 @free(%struct.pointerFile* %206)
%208 = load i32, i32* %7
ret i32 %208
}

LLVM IR (-O2):
%struct.pointerFile = type { i32 }
@.str = [17 x i8] c"%s/progress.lock\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [82 x i8] c"Last run on disk 1 failed, but disk 2 shows no sign of those this. Resume failed.\00"
@.str.3 = [37 x i8] c"Disks are showing differing progress\00"
@.str.4 = [18 x i8] c"nextAvailable.ptr\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [10 x i8] c"%s/%u.bin\00"
@.str.7 = [8 x i8] c"%s/keys\00"
@.str.8 = [21 x i8] c"%s/nextAvailable.ptr\00"
define i32 @generateChunks(i8* %0, i8* %1, i64 %2, i64 %3, i8* %4, i8* %5) {
%7 = alloca [150 x i8]
%8 = alloca i64
%9 = alloca i64
%10 = alloca [150 x i8]
%11 = alloca [150 x i8]
%12 = alloca [16 x i8]
%13 = alloca [100 x i8]
%14 = alloca [100 x i8]
%15 = load i8, i8* %4
%16 = icmp ne i8 %15, 0
%17 = getelementptr inbounds [150 x i8], [150 x i8]* %7, i64 0, i64 0
%18 = bitcast i64* %8 to i8*
%19 = bitcast i64* %9 to i8*
store i64 0, i64* %9
store i64 0, i64* %8
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%21 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32* %21, null
%23 = xor i1 %22, true
%24 = and i1 %16, %23
br i1 %24, label %25, label %32
25: ; preds = %6
%26 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %4)
%27 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0))
%31 = tail call i32 @exit(i32 -1)
unreachable
32: ; preds = %25, %6
br i1 %22, label %48, label %33
33: ; preds = %32
%34 = call i32 @fread(i64* %8, i32 8, i32 1, i32* %21)
br i1 %16, label %37, label %35
35: ; preds = %33
%36 = load i64, i64* %8
br label %45
37: ; preds = %33
%38 = call i32 @fread(i64* %9, i32 8, i32 1, i32* null)
%39 = load i64, i64* %8
%40 = load i64, i64* %9
%41 = icmp eq i64 %39, %40
br i1 %41, label %45, label %42
42: ; preds = %37
%43 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%44 = tail call i32 @exit(i32 -1)
unreachable
45: ; preds = %35, %37
%46 = phi i64 [ %36, %35 ], [ %39, %37 ]
%47 = tail call %struct.pointerFile* @readPtrFile(i8* %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %54
48: ; preds = %32
%49 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%50 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %4)
%52 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%53 = tail call %struct.pointerFile* @createPtrFile(i8* %1)
br label %54
54: ; preds = %48, %45
%55 = phi i64 [ %46, %45 ], [ 0, %48 ]
%56 = phi %struct.pointerFile* [ %47, %45 ], [ %53, %48 ]
%57 = phi i32* [ null, %45 ], [ %52, %48 ]
%58 = phi i32* [ %21, %45 ], [ %50, %48 ]
%59 = tail call i32 @verifyPtrFile(%struct.pointerFile* %56)
%60 = getelementptr inbounds [150 x i8], [150 x i8]* %10, i64 0, i64 0
%61 = getelementptr inbounds [150 x i8], [150 x i8]* %11, i64 0, i64 0
%62 = icmp slt i64 %55, %2
br i1 %62, label %63, label %65
63: ; preds = %54
%64 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
br label %71
65: ; preds = %95, %54
%66 = call i32 @verifyPtrFile(%struct.pointerFile* %56)
%67 = call i32 @scryptLogout(%struct.pointerFile* %56)
%68 = call i32 @fclose(i32* %58)
%69 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%70 = call i32 @remove(i8* %17)
br i1 %16, label %98, label %110
71: ; preds = %63, %95
%72 = phi i64 [ %55, %63 ], [ %96, %95 ]
%73 = call i32* @setupCTR(i32* null, i32* null)
%74 = call i32 @doGCMDecrypt(%struct.pointerFile* %56, i8* %64)
%75 = call i32* @encryptKeyStreamSetup(i8* %0, i64 %72, i8* %64)
%76 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %60, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %0, i64 %72)
br i1 %16, label %77, label %79
77: ; preds = %71
%78 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %61, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %4, i64 %72)
br label %80
79: ; preds = %71
store i8 0, i8* %61
br label %80
80: ; preds = %79, %77
%81 = call i32 @writeFile(i8* %60, i64 %3, i32* %73, i32* %75, i8* %61)
%82 = call i32 @cleanupContext(i32* %73)
%83 = call i32 @cleanupContext(i32* %75)
%84 = load i64, i64* %8
%85 = add nsw i64 %84, 1
store i64 %85, i64* %8
%86 = load i64, i64* %9
%87 = add nsw i64 %86, 1
store i64 %87, i64* %9
%88 = call i32 @fwrite(i64* %8, i32 8, i32 1, i32* %58)
%89 = call i32 @fflush(i32* %58)
%90 = call i32 @rewind(i32* %58)
br i1 %16, label %91, label %95
91: ; preds = %80
%92 = call i32 @fwrite(i64* %9, i32 8, i32 1, i32* %57)
%93 = call i32 @fflush(i32* %57)
%94 = call i32 @rewind(i32* %57)
br label %95
95: ; preds = %91, %80
%96 = add i64 %72, 1
%97 = icmp eq i64 %96, %2
br i1 %97, label %65, label %71
98: ; preds = %65
%99 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%100 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%101 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %99, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %0)
%102 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %100, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%103 = call i32 @copyFile(i8* %100, i8* %99)
%104 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %99, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %1)
%105 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %100, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %5)
%106 = call i32 @copyFile(i8* %100, i8* %99)
%107 = call i32 @fclose(i32* %57)
%108 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %4)
%109 = call i32 @remove(i8* %17)
br label %110
110: ; preds = %98, %65
%111 = call i32 @free(%struct.pointerFile* %56)
ret i32 undef
}