#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__ EEXIST;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ O_WRONLY;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  char str[1024];
  char buffer[1024];
  int real_write;
  int fd;
  if (argc <= 1) {
    printf("Usage: ./fifo_write string ...\n");
    exit(EXIT_FAILURE);
  }
  int i = 1;
  for (i = 1; i < argc; ++i) {
    sscanf(argv[i], "%s", str);
    strcat(str, " ");
    strcat(buffer, str);
  }
  if (access("myfifo", F_OK) == -1) {
    if ((mkfifo("myfifo", 0666) < 0) && (errno != EEXIST)) {
      perror("mkfifo");
      exit(EXIT_FAILURE);
    }
  }
  if ((fd = open("myfifo", O_WRONLY)) == -1) {
    perror("open");
    exit(EXIT_FAILURE);
  }
  if ((real_write = write(fd, buffer, 1024)) > 0) {
    printf("Write into pipe: '%s'.\n", buffer);
    exit(EXIT_FAILURE);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11df <main+0x3f>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
movl   $0x1,-0x81c(%rbp)
movl   $0x1,-0x81c(%rbp)
mov    -0x81c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    125e <main+0xbe>
mov    -0x10(%rbp),%rax
movslq -0x81c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x410(%rbp),%rdx
lea    0xe01(%rip),%rsi
call   1070 <sscanf@plt>
lea    -0x410(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0x810(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x81c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x81c(%rbp)
jmp    11f3 <main+0x53>
mov    0x2d53(%rip),%rax
mov    (%rax),%esi
lea    0xdb7(%rip),%rdi
call   1090 <access@plt>
cmp    $0xffffffff,%eax
jne    12d0 <main+0x130>
lea    0xda2(%rip),%rdi
mov    $0x1b6,%esi
call   1060 <mkfifo@plt>
cmp    $0x0,%rax
jge    12cb <main+0x12b>
mov    0x2d3a(%rip),%rax
mov    (%rax),%rax
mov    0x2d38(%rip),%rcx
cmp    (%rcx),%rax
je     12cb <main+0x12b>
lea    0xd74(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    12d0 <main+0x130>
mov    0x2ce9(%rip),%rax
mov    (%rax),%esi
lea    0xd45(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x818(%rbp)
cmp    $0xffffffff,%eax
jne    130e <main+0x16e>
lea    0xd38(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x818(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
call   1030 <write@plt>
mov    %eax,-0x814(%rbp)
cmp    $0x0,%eax
jle    1357 <main+0x1b7>
lea    -0x810(%rbp),%rsi
lea    0xcf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x818(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
cmp    $0x2,%edi
jl     12b6 <main+0x106>
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x1,%r14d
lea    0x400(%rsp),%rbx
lea    0xe1f(%rip),%r12
mov    %rsp,%r13
nopw   0x0(%rax,%rax,1)
mov    (%r15,%r14,8),%rdi
lea    0xe05(%rip),%rsi
mov    %rbx,%rdx
call   1080 <sscanf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10c0 <strcat@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   10c0 <strcat@plt>
add    $0x1,%r14
cmp    %r14,%rbp
jne    11f0 <main+0x40>
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
lea    0xdd3(%rip),%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
jne    126c <main+0xbc>
lea    0xdc2(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
test   %rax,%rax
jns    126c <main+0xbc>
mov    0x2d7f(%rip),%rax
mov    (%rax),%rax
mov    0x2d7d(%rip),%rcx
cmp    (%rcx),%rax
jne    12f1 <main+0x141>
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
lea    0xd89(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     12c4 <main+0x114>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1040 <write@plt>
test   %eax,%eax
jg     12d2 <main+0x122>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd73(%rip),%rdi
call   1030 <puts@plt>
jmp    12e3 <main+0x133>
lea    0xd48(%rip),%rdi
call   10b0 <perror@plt>
jmp    12e3 <main+0x133>
lea    0xd3f(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xd14(%rip),%rdi
jmp    12cb <main+0x11b>

LLVM IR (-O0):
@.str = [32 x i8] c"Usage: ./fifo_write string ...\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [7 x i8] c"myfifo\00"
@F_OK = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.4 = [7 x i8] c"mkfifo\00"
@O_WRONLY = global i32 0
@.str.5 = [5 x i8] c"open\00"
@.str.6 = [24 x i8] c"Write into pipe: '%s'.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
store i32 1, i32* %10
store i32 1, i32* %10
br label %18
18: ; preds = %35, %17
%19 = load i32, i32* %10
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %38
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%34 = call i32 @strcat(i8* %32, i8* %33)
br label %35
35: ; preds = %22
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %18
38: ; preds = %18
%39 = load i32, i32* @F_OK
%40 = call i32 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %54
42: ; preds = %38
%43 = call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 438)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %42
%46 = load i64, i64* @errno
%47 = load i64, i64* @EEXIST
%48 = icmp ne i64 %46, %47
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %45, %42
br label %54
54: ; preds = %53, %38
%55 = load i32, i32* @O_WRONLY
%56 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %55)
store i32 %56, i32* %9
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %62
58: ; preds = %54
%59 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %54
%63 = load i32, i32* %9
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%65 = call i32 @write(i32 %63, i8* %64, i32 1024)
store i32 %65, i32* %8
%66 = icmp sgt i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %62
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %68)
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %62
%73 = load i32, i32* %9
%74 = call i32 @close(i32 %73)
ret i32 0
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [7 x i8] c"myfifo\00"
@F_OK = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.4 = [7 x i8] c"mkfifo\00"
@O_WRONLY = global i32 0
@.str.5 = [5 x i8] c"open\00"
@.str.6 = [24 x i8] c"Write into pipe: '%s'.\0A\00"
@str = [31 x i8] c"Usage: ./fifo_write string ...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = zext i32 %0 to i64
br label %14
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %8, %14
%15 = phi i64 [ 1, %8 ], [ %21, %14 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%19 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @strcat(i8* %6, i8* %5)
%21 = add nuw nsw i64 %15, 1
%22 = icmp eq i64 %21, %9
br i1 %22, label %23, label %14
23: ; preds = %14
%24 = load i32, i32* @F_OK
%25 = call i32 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 438)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i64, i64* @errno
%32 = load i64, i64* @EEXIST
%33 = icmp eq i64 %31, %32
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %27, %30, %23
%39 = load i32, i32* @O_WRONLY
%40 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %38
%47 = call i32 @write(i32 %40, i8* %6, i32 1024)
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %46
%54 = call i32 @close(i32 %40)
ret i32 0
}