#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ O_WRONLY;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gets(char *);
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int pipe;
  char buf[256];
  if (argc != 2) {
    printf("usage : %s <file> \n", argv[0]);
    exit(0);
  }
  if (access(argv[1], F_OK) == -1) {
    if (mkfifo(argv[1], 0777) != -1) {
      printf("Fifo file created...\n");
    } else {
      printf("Error : create fifo file \n");
      exit(1);
    }
  }
  pipe = open(argv[1], O_WRONLY);
  if (pipe != -1) {
    printf("Enter data to write : \n");
    gets(buf);
    write(pipe, buf, sizeof(buf));
    close(pipe);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bf <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
jne    1229 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x1ff,%esi
call   1060 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     120c <main+0x8c>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1224 <main+0xa4>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1229 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     1282 <main+0x102>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
call   1070 <gets@plt>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    122f <main+0x9f>
mov    0x8(%rbx),%rdi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
jne    11dc <main+0x4c>
mov    0x8(%rbx),%rdi
mov    $0x1ff,%esi
call   1070 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     1247 <main+0xb7>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1222 <main+0x92>
mov    %eax,%ebx
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1080 <gets@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rbx),%rsi
lea    0xdc7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xddd(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"usage : %s <file> \0A\00"
@F_OK = global i32 0
@.str.1 = [22 x i8] c"Fifo file created...\0A\00"
@.str.2 = [27 x i8] c"Error : create fifo file \0A\00"
@O_WRONLY = global i32 0
@.str.3 = [24 x i8] c"Enter data to write : \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @F_OK
%21 = call i32 @access(i8* %19, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %35
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @mkfifo(i8* %26, i32 511)
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %34
31: ; preds = %23
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %29
br label %35
35: ; preds = %34, %16
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = load i32, i32* @O_WRONLY
%40 = call i32 @open(i8* %38, i32 %39)
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = icmp ne i32 %41, -1
br i1 %42, label %43, label %52
43: ; preds = %35
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%46 = call i32 @gets(i8* %45)
%47 = load i32, i32* %6
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%49 = call i32 @write(i32 %47, i8* %48, i32 256)
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
br label %52
52: ; preds = %43, %35
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"usage : %s <file> \0A\00"
@F_OK = global i32 0
@O_WRONLY = global i32 0
@str = [23 x i8] c"Enter data to write : \00"
@str.4 = [26 x i8] c"Error : create fifo file \00"
@str.5 = [21 x i8] c"Fifo file created...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @F_OK
%14 = tail call i32 @access(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %25
16: ; preds = %10
%17 = load i8*, i8** %11
%18 = tail call i32 @mkfifo(i8* %17, i32 511)
%19 = icmp eq i32 %18, -1
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
br label %25
22: ; preds = %16
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.4, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %20, %10
%26 = load i8*, i8** %11
%27 = load i32, i32* @O_WRONLY
%28 = tail call i32 @open(i8* %26, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %35, label %30
30: ; preds = %25
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%32 = call i32 @gets(i8* %4)
%33 = call i32 @write(i32 %28, i8* %4, i32 256)
%34 = call i32 @close(i32 %28)
br label %35
35: ; preds = %30, %25
ret i32 0
}