#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 */

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ inverseP(char *, int);
int lseek(int, int, int /*<<< orphan*/);
char *malloc(int);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd1, fd2, rc, wc, t;
  char *tamp;
  if (argc == 4) {
    t = atoi(argv[3]);
  } else if (argc == 3)
    t = 500;
  else {
    fprintf(stderr,
            "usage:\n %s fichier_in"
            " fichier_out [taille_de_tampon]\n",
            argv[0]);
    exit(1);
  }
  if ((tamp = malloc(t)) == NULL)
    exit(1);
  if ((fd1 = open(argv[1], O_RDONLY)) < 0)
    exit(1);
  if ((fd2 = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC,
                  S_IRWXU | S_IRWXG | S_IRWXO)) < 0)
    exit(2);
  int i = 0;
  int tf = lseek(fd1, 0, SEEK_END);
  lseek(fd1, 0, SEEK_SET);
  for (;;) {
    i++;
    rc = read(fd1, tamp, t);
    if (rc < 0) {
      exit(3);
    }
    if (rc == 0)
      break;
    if (tf - i * t > 0)
      lseek(fd2, tf - (i * t), SEEK_SET);
    else
      lseek(fd2, 2, SEEK_SET);
    inverseP(tamp, rc);
    wc = write(fd2, tamp, rc);
    if (wc < 0) {
      exit(4);
    }
  }
  close(fd1);
  close(fd2);
  free(tamp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    11e5 <main+0x35>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    1226 <main+0x76>
cmpl   $0x3,-0x8(%rbp)
jne    11fb <main+0x4b>
movl   $0x1f4,-0x24(%rbp)
jmp    1221 <main+0x71>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdee(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1226 <main+0x76>
mov    -0x24(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1246 <main+0x96>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1274 <main+0xc4>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
mov    0x2d6c(%rip),%rax
or     (%rax),%esi
mov    0x2d5b(%rip),%rax
or     (%rax),%esi
mov    0x2d32(%rip),%rax
mov    (%rax),%edx
mov    0x2d19(%rip),%rax
or     (%rax),%edx
mov    0x2d30(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12cf <main+0x11f>
mov    $0x2,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2ce8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2caa(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    132e <main+0x17e>
mov    $0x3,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    133d <main+0x18d>
jmp    13c1 <main+0x211>
mov    -0x38(%rbp),%eax
mov    -0x34(%rbp),%ecx
imul   -0x24(%rbp),%ecx
sub    %ecx,%eax
cmp    $0x0,%eax
jle    1374 <main+0x1c4>
mov    -0x18(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%eax
imul   -0x24(%rbp),%eax
sub    %eax,%esi
mov    0x2c38(%rip),%rax
mov    (%rax),%edx
call   1060 <lseek@plt>
jmp    138a <main+0x1da>
mov    -0x18(%rbp),%edi
mov    0x2c22(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1060 <lseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <inverseP@plt>
mov    -0x18(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    13bc <main+0x20c>
mov    $0x4,%edi
call   10d0 <exit@plt>
jmp    12ff <main+0x14f>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%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,%rbp
mov    $0x1f4,%r15d
cmp    $0x3,%edi
je     11de <main+0x2e>
cmp    $0x4,%edi
jne    1326 <main+0x176>
mov    0x18(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
mov    %r15d,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     133f <main+0x18f>
mov    %rax,%r13
mov    0x8(%rbp),%rdi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10b0 <open@plt>
test   %eax,%eax
js     133f <main+0x18f>
mov    %eax,%r14d
mov    0x2d78(%rip),%rax
mov    0x2dd9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dc6(%rip),%rax
or     (%rax),%esi
mov    0x2d9d(%rip),%rax
mov    0x2d86(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x10(%rbp),%rdi
mov    0x2d97(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   10b0 <open@plt>
test   %eax,%eax
js     131c <main+0x16c>
mov    %eax,%r12d
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %eax,%ebp
mov    0x2d27(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
sub    %r15d,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r13,%rsi
mov    %r15d,%edx
call   1080 <read@plt>
test   %eax,%eax
js     1312 <main+0x162>
je     12e9 <main+0x139>
mov    %eax,%ebx
test   %ebp,%ebp
mov    0x2cf1(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
cmovg  %ebp,%esi
mov    %r12d,%edi
call   1060 <lseek@plt>
mov    %r13,%rdi
mov    %ebx,%esi
call   1050 <inverseP@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
sub    %r15d,%ebp
test   %eax,%eax
jns    1290 <main+0xe0>
mov    $0x4,%edi
call   10d0 <exit@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    %r12d,%edi
call   1070 <close@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    $0x3,%edi
call   10d0 <exit@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xcc6(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [54 x i8] c"usage:\0A %s fichier_in fichier_out [taille_de_tampon]\0A\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
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 i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 4
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 3
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %10
br label %33
21: ; preds = %2
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 3
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 500, i32* %10
br label %32
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %24
br label %33
33: ; preds = %32, %16
%34 = load i32, i32* %10
%35 = call i8* @malloc(i32 %34)
store i8* %35, i8** %11
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %33
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = load i32, i32* @O_RDONLY
%44 = call i32 (i8*, i32, ...) @open(i8* %42, i32 %43)
store i32 %44, i32* %6
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %39
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = load i32, i32* @O_WRONLY
%53 = load i32, i32* @O_CREAT
%54 = or i32 %52, %53
%55 = load i32, i32* @O_TRUNC
%56 = or i32 %54, %55
%57 = load i32, i32* @S_IRWXU
%58 = load i32, i32* @S_IRWXG
%59 = or i32 %57, %58
%60 = load i32, i32* @S_IRWXO
%61 = or i32 %59, %60
%62 = call i32 (i8*, i32, ...) @open(i8* %51, i32 %56, i32 %61)
store i32 %62, i32* %7
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %48
%65 = call i32 @exit(i32 2)
unreachable
66: ; preds = %48
store i32 0, i32* %12
%67 = load i32, i32* %6
%68 = load i32, i32* @SEEK_END
%69 = call i32 @lseek(i32 %67, i32 0, i32 %68)
store i32 %69, i32* %13
%70 = load i32, i32* %6
%71 = load i32, i32* @SEEK_SET
%72 = call i32 @lseek(i32 %70, i32 0, i32 %71)
br label %73
73: ; preds = %120, %66
%74 = load i32, i32* %12
%75 = add nsw i32 %74, 1
store i32 %75, i32* %12
%76 = load i32, i32* %6
%77 = load i8*, i8** %11
%78 = load i32, i32* %10
%79 = call i32 @read(i32 %76, i8* %77, i32 %78)
store i32 %79, i32* %8
%80 = load i32, i32* %8
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %73
%83 = call i32 @exit(i32 3)
unreachable
84: ; preds = %73
%85 = load i32, i32* %8
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %88
87: ; preds = %84
br label %121
88: ; preds = %84
%89 = load i32, i32* %13
%90 = load i32, i32* %12
%91 = load i32, i32* %10
%92 = mul nsw i32 %90, %91
%93 = sub nsw i32 %89, %92
%94 = icmp sgt i32 %93, 0
br i1 %94, label %95, label %104
95: ; preds = %88
%96 = load i32, i32* %7
%97 = load i32, i32* %13
%98 = load i32, i32* %12
%99 = load i32, i32* %10
%100 = mul nsw i32 %98, %99
%101 = sub nsw i32 %97, %100
%102 = load i32, i32* @SEEK_SET
%103 = call i32 @lseek(i32 %96, i32 %101, i32 %102)
br label %108
104: ; preds = %88
%105 = load i32, i32* %7
%106 = load i32, i32* @SEEK_SET
%107 = call i32 @lseek(i32 %105, i32 2, i32 %106)
br label %108
108: ; preds = %104, %95
%109 = load i8*, i8** %11
%110 = load i32, i32* %8
%111 = call i32 @inverseP(i8* %109, i32 %110)
%112 = load i32, i32* %7
%113 = load i8*, i8** %11
%114 = load i32, i32* %8
%115 = call i32 @write(i32 %112, i8* %113, i32 %114)
store i32 %115, i32* %9
%116 = load i32, i32* %9
%117 = icmp slt i32 %116, 0
br i1 %117, label %118, label %120
118: ; preds = %108
%119 = call i32 @exit(i32 4)
unreachable
120: ; preds = %108
br label %73
121: ; preds = %87
%122 = load i32, i32* %6
%123 = call i32 @close(i32 %122)
%124 = load i32, i32* %7
%125 = call i32 @close(i32 %124)
%126 = load i8*, i8** %11
%127 = call i32 @free(i8* %126)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [54 x i8] c"usage:\0A %s fichier_in fichier_out [taille_de_tampon]\0A\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %7 [
i32 4, label %3
i32 3, label %12
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 3
%5 = load i8*, i8** %4
%6 = tail call i32 @atoi(i8* %5)
br label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2, %3
%13 = phi i32 [ %6, %3 ], [ 500, %2 ]
%14 = tail call i8* @malloc(i32 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = tail call i32 (i8*, i32, ...) @open(i8* %20, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_WRONLY
%30 = load i32, i32* @O_CREAT
%31 = or i32 %30, %29
%32 = load i32, i32* @O_TRUNC
%33 = or i32 %31, %32
%34 = load i32, i32* @S_IRWXU
%35 = load i32, i32* @S_IRWXG
%36 = or i32 %35, %34
%37 = load i32, i32* @S_IRWXO
%38 = or i32 %36, %37
%39 = tail call i32 (i8*, i32, ...) @open(i8* %28, i32 %33, i32 %38)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %26
%42 = tail call i32 @exit(i32 2)
unreachable
43: ; preds = %26
%44 = load i32, i32* @SEEK_END
%45 = tail call i32 @lseek(i32 %22, i32 0, i32 %44)
%46 = load i32, i32* @SEEK_SET
%47 = tail call i32 @lseek(i32 %22, i32 0, i32 %46)
br label %48
48: ; preds = %57, %43
%49 = phi i32 [ 0, %43 ], [ %50, %57 ]
%50 = add nuw nsw i32 %49, 1
%51 = tail call i32 @read(i32 %22, i8* %14, i32 %13)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = tail call i32 @exit(i32 3)
unreachable
55: ; preds = %48
%56 = icmp eq i32 %51, 0
br i1 %56, label %69, label %57
57: ; preds = %55
%58 = mul nsw i32 %50, %13
%59 = sub nsw i32 %45, %58
%60 = icmp sgt i32 %59, 0
%61 = load i32, i32* @SEEK_SET
%62 = select i1 %60, i32 %59, i32 2
%63 = tail call i32 @lseek(i32 %39, i32 %62, i32 %61)
%64 = tail call i32 @inverseP(i8* %14, i32 %51)
%65 = tail call i32 @write(i32 %39, i8* %14, i32 %51)
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %48
67: ; preds = %57
%68 = tail call i32 @exit(i32 4)
unreachable
69: ; preds = %55
%70 = tail call i32 @close(i32 %22)
%71 = tail call i32 @close(i32 %39)
%72 = tail call i32 @free(i8* %14)
ret i32 0
}