#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int S_IFIFO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char const *, int);
int main(int argc, char **argv) {
  int i;
  if (argc == 1) {
    fprintf(stderr, "%s: opérande manquant\n", argv[0]);
  } else {
    if (argv[1][0] == 'r') {
      int fd = open("fifo", O_RDONLY);
      char buf[100];
      int len;
      while ((len = read(fd, buf, 100)) >= 0) {
        for (i = 0; i < len; i++) {
          printf("%c", buf[i]);
        }
        printf("\n");
      }
    } else {
      mknod("fifo", S_IFIFO | 0666, 0);
      printf("mknod\n");
      int fd = open("fifo", O_WRONLY);
      const char *buf = "Hello World!";
      write(fd, buf, 13);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11a4 <main+0x44>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12b3 <main+0x153>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x72,%eax
jne    1243 <main+0xe3>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    0xe50(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1050 <read@plt>
mov    %eax,-0x84(%rbp)
cmp    $0x0,%eax
jl     123e <main+0xde>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x84(%rbp),%eax
jge    122b <main+0xcb>
movslq -0x14(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%esi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f7 <main+0x97>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d0 <main+0x70>
jmp    12ae <main+0x14e>
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xdbf(%rip),%rdi
xor    %edx,%edx
call   1070 <mknod@plt>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%esi
lea    0xd9a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x88(%rbp)
lea    0xd97(%rip),%rax
mov    %rax,-0x90(%rbp)
mov    -0x88(%rbp),%edi
mov    -0x90(%rbp),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
jmp    12b3 <main+0x153>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
cmp    $0x1,%edi
jne    119c <main+0x2c>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe6e(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1273 <main+0x103>
mov    0x8(%rsi),%rax
cmpb   $0x72,(%rax)
jne    1224 <main+0xb4>
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
lea    0xe5f(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x64,%edx
call   1060 <read@plt>
test   %eax,%eax
js     1273 <main+0x103>
mov    %rsp,%r14
jmp    11fe <main+0x8e>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1060 <read@plt>
test   %eax,%eax
js     1273 <main+0x103>
test   %eax,%eax
je     11e0 <main+0x70>
mov    %eax,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movsbl (%rsp,%rbp,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1210 <main+0xa0>
jmp    11e0 <main+0x70>
mov    0x2da5(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
lea    0xddf(%rip),%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
lea    0xde0(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
lea    0xdb6(%rip),%rsi
mov    %eax,%edi
mov    $0xd,%edx
call   1050 <write@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"%s: op\C3\A9rande manquant\0A\00"
@.str.1 = [5 x i8] c"fifo\00"
@O_RDONLY = global i32 0
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [2 x i8] c"\0A\00"
@S_IFIFO = global i32 0
@.str.4 = [7 x i8] c"mknod\0A\00"
@O_WRONLY = global i32 0
@.str.5 = [13 x i8] c"Hello World!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %65
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 114
br i1 %27, label %28, label %54
28: ; preds = %20
%29 = load i32, i32* @O_RDONLY
%30 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %29)
store i32 %30, i32* %7
br label %31
31: ; preds = %51, %28
%32 = load i32, i32* %7
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 100)
store i32 %34, i32* %9
%35 = icmp sge i32 %34, 0
br i1 %35, label %36, label %53
36: ; preds = %31
store i32 0, i32* %6
br label %37
37: ; preds = %48, %36
%38 = load i32, i32* %6
%39 = load i32, i32* %9
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %51
41: ; preds = %37
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %41
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %37
51: ; preds = %37
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %31
53: ; preds = %31
br label %64
54: ; preds = %20
%55 = load i32, i32* @S_IFIFO
%56 = or i32 %55, 438
%57 = call i32 @mknod(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %56, i32 0)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%59 = load i32, i32* @O_WRONLY
%60 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %59)
store i32 %60, i32* %10
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8** %11
%61 = load i32, i32* %10
%62 = load i8*, i8** %11
%63 = call i32 @write(i32 %61, i8* %62, i32 13)
br label %64
64: ; preds = %54, %53
br label %65
65: ; preds = %64, %14
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"%s: op\C3\A9rande manquant\0A\00"
@.str.1 = [5 x i8] c"fifo\00"
@O_RDONLY = global i32 0
@S_IFIFO = global i32 0
@O_WRONLY = global i32 0
@.str.5 = [13 x i8] c"Hello World!\00"
@str = [6 x i8] c"mknod\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %46
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 114
br i1 %13, label %14, label %38
14: ; preds = %9
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 100)
%19 = icmp sgt i32 %18, -1
br i1 %19, label %20, label %37
20: ; preds = %14, %33
%21 = phi i32 [ %35, %33 ], [ %18, %14 ]
%22 = icmp eq i32 %21, 0
br i1 %22, label %33, label %23
23: ; preds = %20
%24 = zext i32 %21 to i64
br label %25
25: ; preds = %23, %25
%26 = phi i64 [ 0, %23 ], [ %31, %25 ]
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = tail call i32 @putchar(i32 %29)
%31 = add nuw nsw i64 %26, 1
%32 = icmp eq i64 %31, %24
br i1 %32, label %33, label %25
33: ; preds = %25, %20
%34 = tail call i32 @putchar(i32 10)
%35 = call i32 @read(i32 %16, i8* %17, i32 100)
%36 = icmp sgt i32 %35, -1
br i1 %36, label %20, label %37
37: ; preds = %33, %14
br label %46
38: ; preds = %9
%39 = load i32, i32* @S_IFIFO
%40 = or i32 %39, 438
%41 = tail call i32 @mknod(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 0)
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%43 = load i32, i32* @O_WRONLY
%44 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = tail call i32 @write(i32 %44, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 13)
br label %46
46: ; preds = %37, %38, %5
ret i32 0
}