#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 mode_t;

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int endOfFile(char *, int);
int /*<<< orphan*/ exit(int);
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usageSim();
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int lu = 0, ecrit = 0;
  int tubeEntree, tubeSortie;
  char buf[1024];
  int nombreImpression = 0;
  if (((strcmp(argv[1], "-t") != 0) || (strcmp(argv[3], "-n") != 0))) {
    usageSim();
    exit(-1);
  }
  mode_t mode = S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH;
  if (mkfifo(argv[2], mode) == -1) {
    perror("creation tubes");
    exit(-1);
  }
  tubeSortie = open("/dev/null", O_WRONLY);
  tubeEntree = open(argv[2], O_RDONLY);
  if (tubeEntree == -1 || tubeSortie == -1) {
    perror("open fichier_lire");
    exit(0);
  }
  while (1) {
    lu = read(tubeEntree, buf, 1024);
    if (lu > 0) {
      int ris = endOfFile(buf, lu);
      if (ris == 1) {
        nombreImpression++;
        printf("%s -> N^%d: Impression en cours...", argv[4], nombreImpression);
        sleep(3);
        printf(" --> DONE\n");
      }
      ecrit = write(tubeSortie, buf, lu);
      if (lu == -1 || ecrit == -1) {
        perror("write");
        close(tubeEntree);
        close(tubeSortie);
        exit(EXIT_FAILURE);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x424(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe00(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    122d <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xde5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     123e <main+0x7e>
mov    $0x0,%al
call   1090 <usageSim@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    0x2d7a(%rip),%rcx
or     (%rcx),%eax
mov    0x2d69(%rip),%rcx
or     (%rcx),%eax
mov    0x2d78(%rip),%rcx
or     (%rcx),%eax
mov    0x2d77(%rip),%rcx
or     (%rcx),%eax
mov    0x2d26(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x428(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x428(%rbp),%esi
call   1080 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    12ac <main+0xec>
lea    0xd69(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%esi
lea    0xd59(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d15(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     12f1 <main+0x131>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1304 <main+0x144>
lea    0xd27(%rip),%rdi
call   10c0 <perror@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    1309 <main+0x149>
mov    -0x1c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    13e7 <main+0x227>
lea    -0x420(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <endOfFile@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x1,-0x42c(%rbp)
jne    138f <main+0x1cf>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
mov    -0x424(%rbp),%edx
lea    0xcc1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x3,%edi
call   10e0 <sleep@plt>
lea    0xccc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     13b8 <main+0x1f8>
cmpl   $0xffffffff,-0x18(%rbp)
jne    13e2 <main+0x222>
lea    0xca0(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    0x2bdd(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    13e7 <main+0x227>
jmp    1309 <main+0x149>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe11(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1268 <main+0x98>
mov    0x18(%r14),%rdi
lea    0xdff(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1268 <main+0x98>
mov    0x2d9b(%rip),%rax
mov    0x2dac(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d99(%rip),%rax
or     (%rax),%esi
mov    0x2da8(%rip),%rax
or     (%rax),%esi
mov    0x2da7(%rip),%rax
or     (%rax),%esi
mov    0x2d56(%rip),%rax
or     (%rax),%esi
mov    0x10(%r14),%rdi
call   1090 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    1279 <main+0xa9>
lea    0xdad(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
xor    %eax,%eax
call   10a0 <usageSim@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%esi
lea    0xd8c(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
mov    0x2d4c(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
cmp    $0xffffffff,%r15d
je     1326 <main+0x156>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1326 <main+0x156>
mov    %rsp,%rbp
xor    %r12d,%r12d
jmp    12d0 <main+0x100>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %r13d,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1339 <main+0x169>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    12d0 <main+0x100>
mov    %eax,%r13d
mov    %rbp,%rdi
mov    %eax,%esi
call   10b0 <endOfFile@plt>
cmp    $0x1,%eax
jne    12b8 <main+0xe8>
add    $0x1,%r12d
mov    0x20(%r14),%rsi
lea    0xd2d(%rip),%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x3,%edi
call   10f0 <sleep@plt>
lea    0xd3b(%rip),%rdi
call   1030 <puts@plt>
jmp    12b8 <main+0xe8>
lea    0xcf2(%rip),%rdi
call   10d0 <perror@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0xd14(%rip),%rdi
call   10d0 <perror@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r15d,%edi
call   1060 <close@plt>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-t\00"
@.str.1 = [3 x i8] c"-n\00"
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@S_IWUSR = global i32 0
@S_IWGRP = global i32 0
@S_IWOTH = global i32 0
@.str.2 = [15 x i8] c"creation tubes\00"
@.str.3 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [18 x i8] c"open fichier_lire\00"
@.str.5 = [35 x i8] c"%s -> N^%d: Impression en cours...\00"
@.str.6 = [11 x i8] c" --> DONE\0A\00"
@.str.7 = [6 x i8] c"write\00"
@EXIT_FAILURE = 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 [1024 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %11
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %19, %2
%26 = call i32 (...) @usageSim()
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %19
%29 = load i32, i32* @S_IRUSR
%30 = load i32, i32* @S_IRGRP
%31 = or i32 %29, %30
%32 = load i32, i32* @S_IROTH
%33 = or i32 %31, %32
%34 = load i32, i32* @S_IWUSR
%35 = or i32 %33, %34
%36 = load i32, i32* @S_IWGRP
%37 = or i32 %35, %36
%38 = load i32, i32* @S_IWOTH
%39 = or i32 %37, %38
store i32 %39, i32* %12
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = load i32, i32* %12
%44 = call i32 @mkfifo(i8* %42, i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %28
%47 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%48 = call i32 @exit(i32 -1)
unreachable
49: ; preds = %28
%50 = load i32, i32* @O_WRONLY
%51 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %50)
store i32 %51, i32* %9
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = load i32, i32* @O_RDONLY
%56 = call i32 @open(i8* %54, i32 %55)
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = icmp eq i32 %57, -1
br i1 %58, label %62, label %59
59: ; preds = %49
%60 = load i32, i32* %9
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %65
62: ; preds = %59, %49
%63 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%64 = call i32 @exit(i32 0)
unreachable
65: ; preds = %59
br label %66
66: ; preds = %65, %107
%67 = load i32, i32* %8
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%69 = call i32 @read(i32 %67, i8* %68, i32 1024)
store i32 %69, i32* %6
%70 = load i32, i32* %6
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %107
72: ; preds = %66
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%74 = load i32, i32* %6
%75 = call i32 @endOfFile(i8* %73, i32 %74)
store i32 %75, i32* %13
%76 = load i32, i32* %13
%77 = icmp eq i32 %76, 1
br i1 %77, label %78, label %88
78: ; preds = %72
%79 = load i32, i32* %11
%80 = add nsw i32 %79, 1
store i32 %80, i32* %11
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 4
%83 = load i8*, i8** %82
%84 = load i32, i32* %11
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %83, i32 %84)
%86 = call i32 @sleep(i32 3)
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %88
88: ; preds = %78, %72
%89 = load i32, i32* %9
%90 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%91 = load i32, i32* %6
%92 = call i32 @write(i32 %89, i8* %90, i32 %91)
store i32 %92, i32* %7
%93 = load i32, i32* %6
%94 = icmp eq i32 %93, -1
br i1 %94, label %98, label %95
95: ; preds = %88
%96 = load i32, i32* %7
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %106
98: ; preds = %95, %88
%99 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%100 = load i32, i32* %8
%101 = call i32 @close(i32 %100)
%102 = load i32, i32* %9
%103 = call i32 @close(i32 %102)
%104 = load i32, i32* @EXIT_FAILURE
%105 = call i32 @exit(i32 %104)
unreachable
106: ; preds = %95
br label %107
107: ; preds = %106, %66
br label %66
}

LLVM IR (-O2):
@.str = [3 x i8] c"-t\00"
@.str.1 = [3 x i8] c"-n\00"
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@S_IWUSR = global i32 0
@S_IWGRP = global i32 0
@S_IWOTH = global i32 0
@.str.2 = [15 x i8] c"creation tubes\00"
@.str.3 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@O_RDONLY = global i32 0
@.str.4 = [18 x i8] c"open fichier_lire\00"
@.str.5 = [35 x i8] c"%s -> N^%d: Impression en cours...\00"
@.str.7 = [6 x i8] c"write\00"
@EXIT_FAILURE = global i32 0
@str = [10 x i8] c" --> DONE\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 3
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9, %2
%15 = tail call i32 (...) @usageSim()
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %9
%18 = load i32, i32* @S_IRUSR
%19 = load i32, i32* @S_IRGRP
%20 = or i32 %19, %18
%21 = load i32, i32* @S_IROTH
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IWUSR
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IWGRP
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IWOTH
%28 = or i32 %26, %27
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = tail call i32 @mkfifo(i8* %30, i32 %28)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %17
%34 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%35 = tail call i32 @exit(i32 -1)
unreachable
36: ; preds = %17
%37 = load i32, i32* @O_WRONLY
%38 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %29
%40 = load i32, i32* @O_RDONLY
%41 = tail call i32 @open(i8* %39, i32 %40)
%42 = icmp eq i32 %41, -1
%43 = icmp eq i32 %38, -1
%44 = or i1 %43, %42
br i1 %44, label %49, label %45
45: ; preds = %36
%46 = getelementptr inbounds i8*, i8** %1, i64 4
br label %47
47: ; preds = %64, %45
%48 = phi i32 [ %65, %64 ], [ 0, %45 ]
br label %52
49: ; preds = %36
%50 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%51 = tail call i32 @exit(i32 0)
unreachable
52: ; preds = %47, %52
%53 = call i32 @read(i32 %41, i8* %4, i32 1024)
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %52
55: ; preds = %52
%56 = call i32 @endOfFile(i8* %4, i32 %53)
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %64
58: ; preds = %55
%59 = add nsw i32 %48, 1
%60 = load i8*, i8** %46
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %60, i32 %59)
%62 = call i32 @sleep(i32 3)
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %64
64: ; preds = %58, %55
%65 = phi i32 [ %59, %58 ], [ %48, %55 ]
%66 = call i32 @write(i32 %38, i8* %4, i32 %53)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %47
68: ; preds = %64
%69 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%70 = call i32 @close(i32 %41)
%71 = call i32 @close(i32 %38)
%72 = load i32, i32* @EXIT_FAILURE
%73 = call i32 @exit(i32 %72)
unreachable
}