#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*/ F_OK;
int /*<<< orphan*/ O_WRONLY;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int getpid();
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  char buff[1024];
  int real_write;
  int fd;
  if (argc <= 1) {
    printf("Usage: %s string\n", argv[0]);
    exit(1);
  } else {
    printf("%s at PID = %d\n", argv[0], getpid());
  }
  sscanf(argv[1], "%s", buff);
  if (access("myfifo", F_OK) == -1) {
    if ((mkfifo("myfifo", 0666) < 0) && (errno != EEXIST)) {
      printf("Can NOT create fifo file!\n");
      exit(1);
    }
  }
  if ((fd = open("myfifo", O_WRONLY)) == -1) {
    printf("Open fifo error!\n");
    exit(1);
  }
  if ((real_write = write(fd, buff, 1024)) > 0) {
    printf("Write into pipe: '%s'.\n", buff);
    exit(1);
  }
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11d2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x420(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x420(%rbp),%rsi
mov    %eax,%edx
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x410(%rbp),%rdx
lea    0xe0e(%rip),%rsi
call   1080 <sscanf@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
lea    0xdfc(%rip),%rdi
call   10a0 <access@plt>
cmp    $0xffffffff,%eax
jne    1289 <main+0xf9>
lea    0xde7(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
cmp    $0x0,%rax
jge    1284 <main+0xf4>
mov    0x2d7f(%rip),%rax
mov    (%rax),%rax
mov    0x2d7d(%rip),%rcx
cmp    (%rcx),%rax
je     1284 <main+0xf4>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1289 <main+0xf9>
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
lea    0xd8c(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x418(%rbp)
cmp    $0xffffffff,%eax
jne    12c5 <main+0x135>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x418(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1030 <write@plt>
mov    %eax,-0x414(%rbp)
cmp    $0x0,%eax
jle    130a <main+0x17a>
lea    -0x410(%rbp),%rsi
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x418(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    (%rsi),%r14
cmp    $0x1,%edi
jg     11cd <main+0x2d>
lea    0xe47(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %rsi,%rbx
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe34(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%rdi
lea    0xe2d(%rip),%rsi
mov    %rsp,%rdx
call   1090 <sscanf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
lea    0xe18(%rip),%rdi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
jne    1243 <main+0xa3>
lea    0xe07(%rip),%rdi
mov    $0x1b6,%esi
call   1080 <mkfifo@plt>
test   %rax,%rax
jns    1243 <main+0xa3>
mov    0x2da4(%rip),%rax
mov    (%rax),%rax
mov    0x2da2(%rip),%rcx
cmp    (%rcx),%rax
jne    1298 <main+0xf8>
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
lea    0xdd2(%rip),%rdi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
jne    1266 <main+0xc6>
lea    0xde0(%rip),%rdi
jmp    129f <main+0xff>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1040 <write@plt>
test   %eax,%eax
jle    128a <main+0xea>
lea    0xdaa(%rip),%rdi
mov    %rsp,%rsi
jmp    11bc <main+0x1c>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xdb6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s string\0A\00"
@.str.1 = [16 x i8] c"%s at PID = %d\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [7 x i8] c"myfifo\00"
@F_OK = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.4 = [27 x i8] c"Can NOT create fifo file!\0A\00"
@O_WRONLY = global i32 0
@.str.5 = [18 x i8] c"Open fifo error!\0A\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 i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (...) @getpid()
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21)
br label %23
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%28 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @F_OK
%30 = call i32 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %43
32: ; preds = %23
%33 = call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 438)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i64, i64* @errno
%37 = load i64, i64* @EEXIST
%38 = icmp ne i64 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %35, %32
br label %43
43: ; preds = %42, %23
%44 = load i32, i32* @O_WRONLY
%45 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %44)
store i32 %45, i32* %8
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %43
%51 = load i32, i32* %8
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%53 = call i32 @write(i32 %51, i8* %52, i32 1024)
store i32 %53, i32* %7
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %50
%60 = load i32, i32* %8
%61 = call i32 @close(i32 %60)
%62 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s string\0A\00"
@.str.1 = [16 x i8] c"%s at PID = %d\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [7 x i8] c"myfifo\00"
@F_OK = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@O_WRONLY = global i32 0
@.str.6 = [24 x i8] c"Write into pipe: '%s'.\0A\00"
@str = [17 x i8] c"Open fifo error!\00"
@str.7 = [26 x i8] c"Can NOT create fifo file!\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 = icmp slt i32 %0, 2
%6 = load i8*, i8** %1
br i1 %5, label %7, label %10
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %6)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i32 (...) @getpid()
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%16 = load i32, i32* @F_OK
%17 = call i32 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %29
19: ; preds = %10
%20 = call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 438)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i64, i64* @errno
%24 = load i64, i64* @EEXIST
%25 = icmp eq i64 %23, %24
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %19, %22, %10
%30 = load i32, i32* @O_WRONLY
%31 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %29
%37 = call i32 @write(i32 %31, i8* %4, i32 1024)
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %36
%43 = call i32 @close(i32 %31)
%44 = call i32 @exit(i32 0)
unreachable
}