#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int INT_MAX;
int /*<<< orphan*/ SEEK_END;
unsigned char *calloc(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int swap_mem(int, int, int, unsigned char *, unsigned char *);
int swap_fs(int unit, int many, ssize_t size, FILE *ifs, FILE *ofs) {
  int m = 0;
  unsigned char *buf;
  if (many == INT_MAX) {
    long len;
    buf = calloc(unit, 1);
    if (fseek(ifs, 0, SEEK_END) < 0 || (len = ftell(ifs)) < 0 ||
        ((m = len % unit) &&
         (fread(buf, 1, m, ifs) < m || fwrite(buf, 1, m, ofs) < m)))
      goto IOE;
    for (len -= m; len > 0; len -= unit)
      if (fread(buf, 1, unit, ifs) < unit || fwrite(buf, 1, unit, ofs) < unit)
        goto IOE;
    goto OUT;
  IOE:
    fprintf(stderr, "File IO error: %s\n", strerror(errno));
    goto ERR;
  }
  if (!(buf = malloc((m = unit * many)))) {
    fprintf(stderr, "Fail to alocate memory of %d bytes\n", m);
    return -1;
  }
  for (size = (size / m) + ((size % m) > 0); size > 0; --size) {
    int c, e;
    for (c = 0; c < many; c += e) {
      if ((e = fread((buf + c * unit), unit, (many - c), ifs)) < 0) {
        fprintf(stderr, "Fail to read from file: %s\n", strerror(errno));
        goto ERR;
      } else if (e > 0) {
        ;
      } else {
        if (c == 0) {
          free(buf);
          return 0;
        }
        if (c < m) {
          memset((buf + c), 0, (m - c));
          size = 1;
        }
        break;
      }
    }
    if ((e = swap_mem(unit, many, m, buf, buf)) < 0) {
      fprintf(stderr, "Fail to swap by %d units in %d bytes\n", many, unit);
      goto ERR;
    } else if (e > 0)
      fprintf(stderr, "Something isn't right while swapping.\n");
    for (c = 0; c < many; c += e) {
      if ((e = fwrite((buf + c * unit), unit, (many - c), ofs)) < 0) {
        fprintf(stderr, "Fail to write to file: %s\n", strerror(errno));
        goto ERR;
      } else if (e > 0) {
        ;
      } else
        break;
    }
  }
OUT:
  free(buf);
  return 0;
ERR:
  free(buf);
  return 1;
}


x86 assembly (clang, -O0):
<swap_fs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e06(%rip),%rcx
cmp    (%rcx),%eax
jne    1330 <swap_fs+0x180>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
cmp    $0x0,%rax
jl     127f <swap_fs+0xcf>
mov    -0x18(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jl     127f <swap_fs+0xcf>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     1284 <swap_fs+0xd4>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x24(%rbp),%eax
jl     127f <swap_fs+0xcf>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
cmp    -0x24(%rbp),%eax
jge    1284 <swap_fs+0xd4>
jmp    12fd <swap_fs+0x14d>
movslq -0x24(%rbp),%rcx
mov    -0x38(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jle    12f8 <swap_fs+0x148>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x8(%rbp),%eax
jl     12da <swap_fs+0x12a>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
cmp    -0x8(%rbp),%eax
jge    12df <swap_fs+0x12f>
jmp    12fd <swap_fs+0x14d>
jmp    12e4 <swap_fs+0x134>
movslq -0x8(%rbp),%rcx
mov    -0x38(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    1293 <swap_fs+0xe3>
jmp    15ae <swap_fs+0x3fe>
mov    0x2ccc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xcdc(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15c3 <swap_fs+0x413>
mov    -0x8(%rbp),%edi
imul   -0xc(%rbp),%edi
mov    %edi,-0x24(%rbp)
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1373 <swap_fs+0x1c3>
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xcb3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d3 <swap_fs+0x423>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x24(%rbp)
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%eax
cltd
idivl  -0x24(%rbp)
mov    -0x48(%rbp),%eax
cmp    $0x0,%edx
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    15a9 <swap_fs+0x3f9>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    148c <swap_fs+0x2dc>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
sub    -0x3c(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <fread@plt>
mov    %eax,-0x40(%rbp)
cmp    $0x0,%eax
jge    1416 <swap_fs+0x266>
mov    0x2be6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xc2d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15c3 <swap_fs+0x413>
cmpl   $0x0,-0x40(%rbp)
jle    1425 <swap_fs+0x275>
jmp    1474 <swap_fs+0x2c4>
cmpl   $0x0,-0x3c(%rbp)
jne    1444 <swap_fs+0x294>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    15d3 <swap_fs+0x423>
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    146f <swap_fs+0x2bf>
mov    -0x30(%rbp),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
mov    -0x24(%rbp),%edx
sub    -0x3c(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
movl   $0x1,-0x10(%rbp)
jmp    148c <swap_fs+0x2dc>
jmp    1479 <swap_fs+0x2c9>
jmp    147e <swap_fs+0x2ce>
mov    -0x40(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    13a9 <swap_fs+0x1f9>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1050 <swap_mem@plt>
mov    %eax,-0x40(%rbp)
cmp    $0x0,%eax
jge    14d0 <swap_fs+0x320>
mov    0x2b1b(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xb8f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15c3 <swap_fs+0x413>
cmpl   $0x0,-0x40(%rbp)
jle    14f1 <swap_fs+0x341>
mov    0x2aef(%rip),%rax
mov    (%rax),%edi
lea    0xb8f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    14f6 <swap_fs+0x346>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1596 <swap_fs+0x3e6>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
sub    -0x3c(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   10c0 <fwrite@plt>
mov    %eax,-0x40(%rbp)
cmp    $0x0,%eax
jge    156a <swap_fs+0x3ba>
mov    0x2a92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2a7e(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    %rax,%rdx
lea    0xb42(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15c3 <swap_fs+0x413>
cmpl   $0x0,-0x40(%rbp)
jle    1579 <swap_fs+0x3c9>
jmp    157e <swap_fs+0x3ce>
jmp    1596 <swap_fs+0x3e6>
jmp    1583 <swap_fs+0x3d3>
jmp    1588 <swap_fs+0x3d8>
mov    -0x40(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    14fd <swap_fs+0x34d>
jmp    159b <swap_fs+0x3eb>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1398 <swap_fs+0x1e8>
jmp    15ae <swap_fs+0x3fe>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    15d3 <swap_fs+0x423>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_fs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r13
mov    %edi,%r15d
mov    0x2e15(%rip),%rax
cmp    %esi,(%rax)
jne    1243 <swap_fs+0x93>
mov    %r13,0x10(%rsp)
mov    %r15d,%edi
mov    $0x1,%esi
mov    %rcx,%rbx
call   1070 <calloc@plt>
mov    %rax,%r12
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rbp
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
test   %rax,%rax
js     1411 <swap_fs+0x261>
mov    %rbp,%rdi
call   1090 <ftell@plt>
test   %rax,%rax
js     1411 <swap_fs+0x261>
mov    %rax,%rbx
movslq %r15d,%r14
or     %r14,%rax
shr    $0x20,%rax
je     13d0 <swap_fs+0x220>
mov    %rbx,%rax
cqto
idiv   %r14
mov    %rdx,%r13
test   %r13d,%r13d
jne    13df <swap_fs+0x22f>
jmp    144a <swap_fs+0x29a>
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rcx,0x10(%rsp)
mov    %esi,%ebp
imul   %r15d,%ebp
mov    %ebp,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     136d <swap_fs+0x1bd>
mov    %rax,%r12
mov    %r14d,%eax
cltd
idiv   %ebp
xor    %r14d,%r14d
test   %edx,%edx
setg   %r14b
add    %eax,%r14d
jle    148a <swap_fs+0x2da>
mov    %ebp,0xc(%rsp)
mov    %r13,%rbp
test   %ebx,%ebx
jle    12f0 <swap_fs+0x140>
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    %r13d,%eax
imul   %r15d,%eax
movslq %eax,%rdi
add    %r12,%rdi
mov    %ebx,%edx
sub    %r13d,%edx
mov    %r15d,%esi
mov    0x10(%rsp),%rcx
call   1040 <fread@plt>
test   %eax,%eax
js     13b0 <swap_fs+0x200>
je     12c3 <swap_fs+0x113>
add    %eax,%r13d
cmp    %ebx,%r13d
jl     1290 <swap_fs+0xe0>
jmp    12f0 <swap_fs+0x140>
test   %r13d,%r13d
je     148a <swap_fs+0x2da>
mov    0xc(%rsp),%edx
sub    %r13d,%edx
jle    12f0 <swap_fs+0x140>
movslq %r13d,%rdi
add    %r12,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0x1,%r14d
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %ebx,%esi
mov    0xc(%rsp),%edx
mov    %r12,%rcx
mov    %r12,%r8
call   1050 <swap_mem@plt>
test   %eax,%eax
js     14a3 <swap_fs+0x2f3>
je     1325 <swap_fs+0x175>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
lea    0xd5b(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
test   %ebx,%ebx
mov    %rbp,%r13
jle    1357 <swap_fs+0x1a7>
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %ebp,%eax
imul   %r15d,%eax
movslq %eax,%rdi
add    %r12,%rdi
mov    %ebx,%edx
sub    %ebp,%edx
mov    %r15d,%esi
mov    %r13,%rcx
call   10c0 <fwrite@plt>
test   %eax,%eax
js     1390 <swap_fs+0x1e0>
je     1357 <swap_fs+0x1a7>
add    %eax,%ebp
cmp    %ebx,%ebp
jl     1330 <swap_fs+0x180>
lea    -0x1(%r14),%eax
cmp    $0x1,%r14d
mov    %eax,%r14d
jg     1282 <swap_fs+0xd2>
jmp    148a <swap_fs+0x2da>
mov    0x2c5c(%rip),%rax
mov    (%rax),%edi
lea    0xc96(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1494 <swap_fs+0x2e4>
mov    0x2c39(%rip),%rax
mov    (%rax),%ebx
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xcf2(%rip),%rsi
jmp    142f <swap_fs+0x27f>
mov    0x2c19(%rip),%rax
mov    (%rax),%ebx
mov    0x2c08(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xc69(%rip),%rsi
jmp    142f <swap_fs+0x27f>
mov    %ebx,%eax
xor    %edx,%edx
div    %r15d
mov    %edx,%r13d
test   %r13d,%r13d
je     144a <swap_fs+0x29a>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
cmp    %r13d,%eax
jl     1411 <swap_fs+0x261>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    0x10(%rsp),%rcx
call   10c0 <fwrite@plt>
cmp    %r13d,%eax
jge    144a <swap_fs+0x29a>
mov    0x2bb8(%rip),%rax
mov    (%rax),%ebx
mov    0x2ba7(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xbd1(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
jmp    1494 <swap_fs+0x2e4>
sub    %r13,%rbx
jle    148a <swap_fs+0x2da>
nop
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
cmp    %r15d,%eax
jl     1411 <swap_fs+0x261>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    0x10(%rsp),%rcx
call   10c0 <fwrite@plt>
cmp    %r15d,%eax
jl     1411 <swap_fs+0x261>
sub    %r14,%rbx
test   %rbx,%rbx
jg     1450 <swap_fs+0x2a0>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b26(%rip),%rax
mov    (%rax),%edi
lea    0xba0(%rip),%rsi
mov    %ebx,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    143b <swap_fs+0x28b>

LLVM IR (-O0):
@INT_MAX = global i32 0
@SEEK_END = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"File IO error: %s\0A\00"
@errno = global i32 0
@.str.1 = [36 x i8] c"Fail to alocate memory of %d bytes\0A\00"
@.str.2 = [28 x i8] c"Fail to read from file: %s\0A\00"
@.str.3 = [38 x i8] c"Fail to swap by %d units in %d bytes\0A\00"
@.str.4 = [39 x i8] c"Something isn't right while swapping.\0A\00"
@.str.5 = [27 x i8] c"Fail to write to file: %s\0A\00"
define i32 @swap_fs(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32 0, i32* %12
%17 = load i32, i32* %8
%18 = load i32, i32* @INT_MAX
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %88
20: ; preds = %5
%21 = load i32, i32* %7
%22 = call i8* @calloc(i32 %21, i32 1)
store i8* %22, i8** %13
%23 = load i32*, i32** %10
%24 = load i32, i32* @SEEK_END
%25 = call i64 @fseek(i32* %23, i32 0, i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %52, label %27
27: ; preds = %20
%28 = load i32*, i32** %10
%29 = call i64 @ftell(i32* %28)
store i64 %29, i64* %14
%30 = icmp slt i64 %29, 0
br i1 %30, label %52, label %31
31: ; preds = %27
%32 = load i64, i64* %14
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = srem i64 %32, %34
%36 = trunc i64 %35 to i32
store i32 %36, i32* %12
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %53
38: ; preds = %31
%39 = load i8*, i8** %13
%40 = load i32, i32* %12
%41 = load i32*, i32** %10
%42 = call i32 @fread(i8* %39, i32 1, i32 %40, i32* %41)
%43 = load i32, i32* %12
%44 = icmp slt i32 %42, %43
br i1 %44, label %52, label %45
45: ; preds = %38
%46 = load i8*, i8** %13
%47 = load i32, i32* %12
%48 = load i32*, i32** %11
%49 = call i32 @fwrite(i8* %46, i32 1, i32 %47, i32* %48)
%50 = load i32, i32* %12
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %53
52: ; preds = %45, %38, %27, %20
br label %83
53: ; preds = %45, %31
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
%56 = load i64, i64* %14
%57 = sub nsw i64 %56, %55
store i64 %57, i64* %14
br label %58
58: ; preds = %77, %53
%59 = load i64, i64* %14
%60 = icmp sgt i64 %59, 0
br i1 %60, label %61, label %82
61: ; preds = %58
%62 = load i8*, i8** %13
%63 = load i32, i32* %7
%64 = load i32*, i32** %10
%65 = call i32 @fread(i8* %62, i32 1, i32 %63, i32* %64)
%66 = load i32, i32* %7
%67 = icmp slt i32 %65, %66
br i1 %67, label %75, label %68
68: ; preds = %61
%69 = load i8*, i8** %13
%70 = load i32, i32* %7
%71 = load i32*, i32** %11
%72 = call i32 @fwrite(i8* %69, i32 1, i32 %70, i32* %71)
%73 = load i32, i32* %7
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %76
75: ; preds = %68, %61
br label %83
76: ; preds = %68
br label %77
77: ; preds = %76
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = load i64, i64* %14
%81 = sub nsw i64 %80, %79
store i64 %81, i64* %14
br label %58
82: ; preds = %58
br label %225
83: ; preds = %75, %52
%84 = load i32, i32* @stderr
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %86)
br label %228
88: ; preds = %5
%89 = load i32, i32* %7
%90 = load i32, i32* %8
%91 = mul nsw i32 %89, %90
store i32 %91, i32* %12
%92 = call i8* @malloc(i32 %91)
store i8* %92, i8** %13
%93 = icmp ne i8* %92, null
br i1 %93, label %98, label %94
94: ; preds = %88
%95 = load i32, i32* @stderr
%96 = load i32, i32* %12
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %96)
store i32 -1, i32* %6
br label %231
98: ; preds = %88
%99 = load i32, i32* %9
%100 = load i32, i32* %12
%101 = sdiv i32 %99, %100
%102 = load i32, i32* %9
%103 = load i32, i32* %12
%104 = srem i32 %102, %103
%105 = icmp sgt i32 %104, 0
%106 = zext i1 %105 to i32
%107 = add nsw i32 %101, %106
store i32 %107, i32* %9
br label %108
108: ; preds = %221, %98
%109 = load i32, i32* %9
%110 = icmp sgt i32 %109, 0
br i1 %110, label %111, label %224
111: ; preds = %108
store i32 0, i32* %15
br label %112
112: ; preds = %161, %111
%113 = load i32, i32* %15
%114 = load i32, i32* %8
%115 = icmp slt i32 %113, %114
br i1 %115, label %116, label %165
116: ; preds = %112
%117 = load i8*, i8** %13
%118 = load i32, i32* %15
%119 = load i32, i32* %7
%120 = mul nsw i32 %118, %119
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i8, i8* %117, i64 %121
%123 = load i32, i32* %7
%124 = load i32, i32* %8
%125 = load i32, i32* %15
%126 = sub nsw i32 %124, %125
%127 = load i32*, i32** %10
%128 = call i32 @fread(i8* %122, i32 %123, i32 %126, i32* %127)
store i32 %128, i32* %16
%129 = icmp slt i32 %128, 0
br i1 %129, label %130, label %135
130: ; preds = %116
%131 = load i32, i32* @stderr
%132 = load i32, i32* @errno
%133 = call i8* @strerror(i32 %132)
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %133)
br label %228
135: ; preds = %116
%136 = load i32, i32* %16
%137 = icmp sgt i32 %136, 0
br i1 %137, label %138, label %139
138: ; preds = %135
br label %159
139: ; preds = %135
%140 = load i32, i32* %15
%141 = icmp eq i32 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %139
%143 = load i8*, i8** %13
%144 = call i32 @free(i8* %143)
store i32 0, i32* %6
br label %231
145: ; preds = %139
%146 = load i32, i32* %15
%147 = load i32, i32* %12
%148 = icmp slt i32 %146, %147
br i1 %148, label %149, label %158
149: ; preds = %145
%150 = load i8*, i8** %13
%151 = load i32, i32* %15
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds i8, i8* %150, i64 %152
%154 = load i32, i32* %12
%155 = load i32, i32* %15
%156 = sub nsw i32 %154, %155
%157 = call i32 @memset(i8* %153, i32 0, i32 %156)
store i32 1, i32* %9
br label %158
158: ; preds = %149, %145
br label %165
159: ; preds = %138
br label %160
160: ; preds = %159
br label %161
161: ; preds = %160
%162 = load i32, i32* %16
%163 = load i32, i32* %15
%164 = add nsw i32 %163, %162
store i32 %164, i32* %15
br label %112
165: ; preds = %158, %112
%166 = load i32, i32* %7
%167 = load i32, i32* %8
%168 = load i32, i32* %12
%169 = load i8*, i8** %13
%170 = load i8*, i8** %13
%171 = call i32 @swap_mem(i32 %166, i32 %167, i32 %168, i8* %169, i8* %170)
store i32 %171, i32* %16
%172 = icmp slt i32 %171, 0
br i1 %172, label %173, label %178
173: ; preds = %165
%174 = load i32, i32* @stderr
%175 = load i32, i32* %8
%176 = load i32, i32* %7
%177 = call i32 (i32, i8*, ...) @fprintf(i32 %174, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %175, i32 %176)
br label %228
178: ; preds = %165
%179 = load i32, i32* %16
%180 = icmp sgt i32 %179, 0
br i1 %180, label %181, label %184
181: ; preds = %178
%182 = load i32, i32* @stderr
%183 = call i32 (i32, i8*, ...) @fprintf(i32 %182, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %184
184: ; preds = %181, %178
br label %185
185: ; preds = %184
store i32 0, i32* %15
br label %186
186: ; preds = %216, %185
%187 = load i32, i32* %15
%188 = load i32, i32* %8
%189 = icmp slt i32 %187, %188
br i1 %189, label %190, label %220
190: ; preds = %186
%191 = load i8*, i8** %13
%192 = load i32, i32* %15
%193 = load i32, i32* %7
%194 = mul nsw i32 %192, %193
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds i8, i8* %191, i64 %195
%197 = load i32, i32* %7
%198 = load i32, i32* %8
%199 = load i32, i32* %15
%200 = sub nsw i32 %198, %199
%201 = load i32*, i32** %11
%202 = call i32 @fwrite(i8* %196, i32 %197, i32 %200, i32* %201)
store i32 %202, i32* %16
%203 = icmp slt i32 %202, 0
br i1 %203, label %204, label %209
204: ; preds = %190
%205 = load i32, i32* @stderr
%206 = load i32, i32* @errno
%207 = call i8* @strerror(i32 %206)
%208 = call i32 (i32, i8*, ...) @fprintf(i32 %205, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %207)
br label %228
209: ; preds = %190
%210 = load i32, i32* %16
%211 = icmp sgt i32 %210, 0
br i1 %211, label %212, label %213
212: ; preds = %209
br label %214
213: ; preds = %209
br label %220
214: ; preds = %212
br label %215
215: ; preds = %214
br label %216
216: ; preds = %215
%217 = load i32, i32* %16
%218 = load i32, i32* %15
%219 = add nsw i32 %218, %217
store i32 %219, i32* %15
br label %186
220: ; preds = %213, %186
br label %221
221: ; preds = %220
%222 = load i32, i32* %9
%223 = add nsw i32 %222, -1
store i32 %223, i32* %9
br label %108
224: ; preds = %108
br label %225
225: ; preds = %224, %82
%226 = load i8*, i8** %13
%227 = call i32 @free(i8* %226)
store i32 0, i32* %6
br label %231
228: ; preds = %204, %173, %130, %83
%229 = load i8*, i8** %13
%230 = call i32 @free(i8* %229)
store i32 1, i32* %6
br label %231
231: ; preds = %228, %225, %142, %94
%232 = load i32, i32* %6
ret i32 %232
}

LLVM IR (-O2):
@INT_MAX = global i32 0
@SEEK_END = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"File IO error: %s\0A\00"
@errno = global i32 0
@.str.1 = [36 x i8] c"Fail to alocate memory of %d bytes\0A\00"
@.str.2 = [28 x i8] c"Fail to read from file: %s\0A\00"
@.str.3 = [38 x i8] c"Fail to swap by %d units in %d bytes\0A\00"
@.str.4 = [39 x i8] c"Something isn't right while swapping.\0A\00"
@.str.5 = [27 x i8] c"Fail to write to file: %s\0A\00"
define i32 @swap_fs(i32 %0, i32 %1, i32 %2, i32* nocapture %3, i32* nocapture %4) {
%6 = load i32, i32* @INT_MAX
%7 = icmp eq i32 %6, %1
br i1 %7, label %8, label %45
8: ; preds = %5
%9 = tail call i8* @calloc(i32 %0, i32 1)
%10 = load i32, i32* @SEEK_END
%11 = tail call i64 @fseek(i32* %3, i32 0, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %40, label %13
13: ; preds = %8
%14 = tail call i64 @ftell(i32* %3)
%15 = icmp slt i64 %14, 0
br i1 %15, label %40, label %16
16: ; preds = %13
%17 = sext i32 %0 to i64
%18 = srem i64 %14, %17
%19 = trunc i64 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %16
%22 = tail call i32 @fread(i8* %9, i32 1, i32 %19, i32* %3)
%23 = icmp slt i32 %22, %19
br i1 %23, label %40, label %24
24: ; preds = %21
%25 = tail call i32 @fwrite(i8* %9, i32 1, i32 %19, i32* %4)
%26 = icmp slt i32 %25, %19
br i1 %26, label %40, label %27
27: ; preds = %24, %16
%28 = sub nsw i64 %14, %18
%29 = icmp sgt i64 %28, 0
br i1 %29, label %32, label %126
30: ; preds = %36
%31 = icmp sgt i64 %39, 0
br i1 %31, label %32, label %126
32: ; preds = %27, %30
%33 = phi i64 [ %39, %30 ], [ %28, %27 ]
%34 = tail call i32 @fread(i8* %9, i32 1, i32 %0, i32* %3)
%35 = icmp slt i32 %34, %0
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = tail call i32 @fwrite(i8* %9, i32 1, i32 %0, i32* %4)
%38 = icmp slt i32 %37, %0
%39 = sub nsw i64 %33, %17
br i1 %38, label %40, label %30
40: ; preds = %36, %32, %24, %21, %13, %8
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = tail call i8* @strerror(i32 %42)
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %43)
br label %129
45: ; preds = %5
%46 = mul nsw i32 %1, %0
%47 = tail call i8* @malloc(i32 %46)
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = load i32, i32* @stderr
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %46)
br label %132
52: ; preds = %45
%53 = sdiv i32 %2, %46
%54 = srem i32 %2, %46
%55 = icmp sgt i32 %54, 0
%56 = zext i1 %55 to i32
%57 = add nsw i32 %53, %56
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %126
59: ; preds = %52
%60 = icmp sgt i32 %1, 0
br label %61
61: ; preds = %59, %123
%62 = phi i32 [ %57, %59 ], [ %124, %123 ]
br i1 %60, label %65, label %90
63: ; preds = %78
%64 = icmp slt i32 %80, %1
br i1 %64, label %65, label %90
65: ; preds = %61, %63
%66 = phi i32 [ %80, %63 ], [ 0, %61 ]
%67 = mul nsw i32 %66, %0
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %47, i64 %68
%70 = sub nsw i32 %1, %66
%71 = tail call i32 @fread(i8* %69, i32 %0, i32 %70, i32* %3)
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %65
%74 = load i32, i32* @stderr
%75 = load i32, i32* @errno
%76 = tail call i8* @strerror(i32 %75)
%77 = tail call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %76)
br label %129
78: ; preds = %65
%79 = icmp eq i32 %71, 0
%80 = add nsw i32 %71, %66
br i1 %79, label %81, label %63
81: ; preds = %78
%82 = icmp eq i32 %66, 0
br i1 %82, label %121, label %83
83: ; preds = %81
%84 = icmp sgt i32 %46, %66
br i1 %84, label %85, label %90
85: ; preds = %83
%86 = sext i32 %66 to i64
%87 = getelementptr inbounds i8, i8* %47, i64 %86
%88 = sub nsw i32 %46, %66
%89 = tail call i32 @memset(i8* %87, i32 0, i32 %88)
br label %90
90: ; preds = %63, %61, %83, %85
%91 = phi i32 [ 1, %85 ], [ %62, %83 ], [ %62, %61 ], [ %62, %63 ]
%92 = tail call i32 @swap_mem(i32 %0, i32 %1, i32 %46, i8* %47, i8* %47)
%93 = icmp slt i32 %92, 0
br i1 %93, label %94, label %97
94: ; preds = %90
%95 = load i32, i32* @stderr
%96 = tail call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %1, i32 %0)
br label %129
97: ; preds = %90
%98 = icmp eq i32 %92, 0
br i1 %98, label %102, label %99
99: ; preds = %97
%100 = load i32, i32* @stderr
%101 = tail call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %102
102: ; preds = %97, %99
br i1 %60, label %103, label %123
103: ; preds = %102, %116
%104 = phi i32 [ %118, %116 ], [ 0, %102 ]
%105 = mul nsw i32 %104, %0
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i8, i8* %47, i64 %106
%108 = sub nsw i32 %1, %104
%109 = tail call i32 @fwrite(i8* %107, i32 %0, i32 %108, i32* %4)
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %116
111: ; preds = %103
%112 = load i32, i32* @stderr
%113 = load i32, i32* @errno
%114 = tail call i8* @strerror(i32 %113)
%115 = tail call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %114)
br label %129
116: ; preds = %103
%117 = icmp ne i32 %109, 0
%118 = add nsw i32 %109, %104
%119 = icmp slt i32 %118, %1
%120 = select i1 %117, i1 %119, i1 false
br i1 %120, label %103, label %123
121: ; preds = %81
%122 = tail call i32 @free(i8* %47)
br label %132
123: ; preds = %116, %102
%124 = add nsw i32 %91, -1
%125 = icmp sgt i32 %91, 1
br i1 %125, label %61, label %126
126: ; preds = %123, %30, %52, %27
%127 = phi i8* [ %9, %27 ], [ %47, %52 ], [ %9, %30 ], [ %47, %123 ]
%128 = tail call i32 @free(i8* %127)
br label %132
129: ; preds = %111, %94, %73, %40
%130 = phi i8* [ %9, %40 ], [ %47, %73 ], [ %47, %94 ], [ %47, %111 ]
%131 = tail call i32 @free(i8* %130)
br label %132
132: ; preds = %121, %129, %126, %49
%133 = phi i32 [ 1, %129 ], [ 0, %126 ], [ 0, %121 ], [ -1, %49 ]
ret i32 %133
}