#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 */
scalar_t__ EAGAIN;
scalar_t__ EEXIST;
scalar_t__ ENXIO;
int O_NONBLOCK;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ mkfifo(char *, int);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ write(int, char *, int);
main(int argc, char **argv) {
  int fd;
  char w_buf[4096 * 2];
  int real_wnum;
  memset(w_buf, 0, 4096 * 2);
  if ((mkfifo("/tmp/fifoserver", S_IRUSR | S_IWUSR) < 0) && (errno != EEXIST)) {
    printf("cannot create fifoserver\n");
  }
  fd = open("/tmp/fifoserver", O_WRONLY | O_NONBLOCK, 0);
  fd = open("/tmp/fifoserver", O_WRONLY, 0);
  if (fd == -1) {
    if (errno == ENXIO) {
      printf("open error; no reading process\n");
    } else {
      printf("open error:%d\n", errno);
    }
    exit(1);
  }
  real_wnum = (int)write(fd, w_buf, 2048);
  if (real_wnum == -1) {
    if (errno == EAGAIN) {
      printf("write to fifo error; try later\n");
    } else {
      printf("write to fifo error:%d\n", errno);
    }
    exit(1);
  } else {
    printf("real write num is %d\n", real_wnum);
  }
  real_wnum = (int)write(fd, w_buf, 5000);
  if (real_wnum == -1) {
    if (errno == EAGAIN) {
      printf("try later\n");
    } else {
      printf("error\n");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x2020(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1050 <memset@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
mov    0x2e44(%rip),%rax
or     (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1060 <mkfifo@plt>
cmp    $0x0,%rax
jge    11dc <main+0x7c>
mov    0x2e0d(%rip),%rax
mov    (%rax),%rax
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%rax
je     11dc <main+0x7c>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
mov    0x2dfc(%rip),%rax
or     (%rax),%esi
lea    0xe0b(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
lea    0xdf1(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1272 <main+0x112>
mov    0x2d9e(%rip),%rax
mov    (%rax),%rax
mov    0x2d8c(%rip),%rcx
cmp    (%rcx),%rax
jne    1250 <main+0xf0>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1268 <main+0x108>
mov    0x2d71(%rip),%rax
mov    (%rax),%rsi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x800,%edx
call   1030 <write@plt>
mov    %eax,-0x2024(%rbp)
cmpl   $0xffffffff,-0x2024(%rbp)
jne    12e8 <main+0x188>
mov    0x2d28(%rip),%rax
mov    (%rax),%rax
mov    0x2cf6(%rip),%rcx
cmp    (%rcx),%rax
jne    12c6 <main+0x166>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12de <main+0x17e>
mov    0x2cfb(%rip),%rax
mov    (%rax),%rsi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x2024(%rbp),%esi
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x1388,%edx
call   1030 <write@plt>
mov    %eax,-0x2024(%rbp)
cmpl   $0xffffffff,-0x2024(%rbp)
jne    1363 <main+0x203>
mov    0x2c9e(%rip),%rax
mov    (%rax),%rax
mov    0x2c6c(%rip),%rcx
cmp    (%rcx),%rax
jne    1350 <main+0x1f0>
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    135e <main+0x1fe>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1363 <main+0x203>
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x2008,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
mov    0x2e28(%rip),%rax
mov    0x2e49(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1070 <mkfifo@plt>
test   %rax,%rax
jns    11ce <main+0x5e>
mov    0x2e15(%rip),%rax
mov    (%rax),%rax
mov    0x2e13(%rip),%rcx
cmp    (%rcx),%rax
je     11ce <main+0x5e>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dd3(%rip),%r14
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
or     (%r14),%esi
lea    0xe18(%rip),%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1080 <open@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1276 <main+0x106>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x800,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1295 <main+0x125>
lea    0xe16(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x1388,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1269 <main+0xf9>
mov    0x2d83(%rip),%rax
mov    (%rax),%rax
mov    0x2d51(%rip),%rcx
cmp    (%rcx),%rax
lea    0xe0f(%rip),%rax
lea    0xded(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d4b(%rip),%rax
mov    (%rax),%rsi
mov    0x2d39(%rip),%rax
cmp    (%rax),%rsi
jne    12c1 <main+0x151>
lea    0xddf(%rip),%rdi
jmp    12b2 <main+0x142>
mov    0x2d2c(%rip),%rax
mov    (%rax),%rsi
mov    0x2cfa(%rip),%rax
cmp    (%rax),%rsi
jne    12ca <main+0x15a>
lea    0xda1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xd48(%rip),%rdi
jmp    12d1 <main+0x161>
lea    0xd4e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"/tmp/fifoserver\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [26 x i8] c"cannot create fifoserver\0A\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@ENXIO = global i64 0
@.str.2 = [32 x i8] c"open error; no reading process\0A\00"
@.str.3 = [15 x i8] c"open error:%d\0A\00"
@EAGAIN = global i64 0
@.str.4 = [32 x i8] c"write to fifo error; try later\0A\00"
@.str.5 = [24 x i8] c"write to fifo error:%d\0A\00"
@.str.6 = [22 x i8] c"real write num is %d\0A\00"
@.str.7 = [11 x i8] c"try later\0A\00"
@.str.8 = [7 x i8] c"error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [8192 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 8192)
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %11, %12
%14 = call i64 @mkfifo(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i64, i64* @errno
%18 = load i64, i64* @EEXIST
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %16, %2
%23 = load i32, i32* @O_WRONLY
%24 = load i32, i32* @O_NONBLOCK
%25 = or i32 %23, %24
%26 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %25, i32 0)
store i32 %26, i32* %6
%27 = load i32, i32* @O_WRONLY
%28 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %27, i32 0)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %42
31: ; preds = %22
%32 = load i64, i64* @errno
%33 = load i64, i64* @ENXIO
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %40
37: ; preds = %31
%38 = load i64, i64* @errno
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %38)
br label %40
40: ; preds = %37, %35
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %22
%43 = load i32, i32* %6
%44 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%45 = call i64 @write(i32 %43, i8* %44, i32 2048)
%46 = trunc i64 %45 to i32
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %60
49: ; preds = %42
%50 = load i64, i64* @errno
%51 = load i64, i64* @EAGAIN
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %58
55: ; preds = %49
%56 = load i64, i64* @errno
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i64 %56)
br label %58
58: ; preds = %55, %53
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %42
%61 = load i32, i32* %8
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %60
%64 = load i32, i32* %6
%65 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%66 = call i64 @write(i32 %64, i8* %65, i32 5000)
%67 = trunc i64 %66 to i32
store i32 %67, i32* %8
%68 = load i32, i32* %8
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %79
70: ; preds = %63
%71 = load i64, i64* @errno
%72 = load i64, i64* @EAGAIN
%73 = icmp eq i64 %71, %72
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %78
76: ; preds = %70
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %78
78: ; preds = %76, %74
br label %79
79: ; preds = %78, %63
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
@.str = [16 x i8] c"/tmp/fifoserver\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@ENXIO = global i64 0
@.str.3 = [15 x i8] c"open error:%d\0A\00"
@EAGAIN = global i64 0
@.str.5 = [24 x i8] c"write to fifo error:%d\0A\00"
@.str.6 = [22 x i8] c"real write num is %d\0A\00"
@str = [6 x i8] c"error\00"
@str.9 = [10 x i8] c"try later\00"
@str.10 = [31 x i8] c"write to fifo error; try later\00"
@str.11 = [31 x i8] c"open error; no reading process\00"
@str.12 = [25 x i8] c"cannot create fifoserver\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 8192)
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %7, %6
%9 = call i64 @mkfifo(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i64, i64* @errno
%13 = load i64, i64* @EEXIST
%14 = icmp eq i64 %12, %13
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
br label %17
17: ; preds = %15, %11, %2
%18 = load i32, i32* @O_WRONLY
%19 = load i32, i32* @O_NONBLOCK
%20 = or i32 %19, %18
%21 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %20, i32 0)
%22 = load i32, i32* @O_WRONLY
%23 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %22, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %35
25: ; preds = %17
%26 = load i64, i64* @errno
%27 = load i64, i64* @ENXIO
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.11, i64 0, i64 0))
br label %33
31: ; preds = %25
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %26)
br label %33
33: ; preds = %31, %29
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %17
%36 = call i64 @write(i32 %23, i8* %4, i32 2048)
%37 = trunc i64 %36 to i32
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %49
39: ; preds = %35
%40 = load i64, i64* @errno
%41 = load i64, i64* @EAGAIN
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.10, i64 0, i64 0))
br label %47
45: ; preds = %39
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i64 %40)
br label %47
47: ; preds = %45, %43
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %35
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %37)
%51 = call i64 @write(i32 %23, i8* %4, i32 5000)
%52 = trunc i64 %51 to i32
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %60
54: ; preds = %49
%55 = load i64, i64* @errno
%56 = load i64, i64* @EAGAIN
%57 = icmp eq i64 %55, %56
%58 = select i1 %57, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0)
%59 = call i32 @puts(i8* dereferenceable(1) %58)
br label %60
60: ; preds = %54, %49
ret i32 0
}