#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  puts("Client");
  char *strMessage[] = {"Welcome", "to",   "the", "module.",
                        "This",    "will", "now", "STOP"};
  int fd = open("/tmp/demo6_fifo", O_WRONLY);
  if (fd == -1) {
    perror("Cannot open fifo");
    return EXIT_FAILURE;
  }
  for (unsigned int n = 0; n < 8; n++) {
    char L = (char)strlen(strMessage[n]);
    write(fd, &L, 1);
    write(fd, strMessage[n], strlen(strMessage[n]));
  }
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
lea    -0x50(%rbp),%rdi
lea    0x2c2a(%rip),%rsi
mov    $0x40,%edx
call   1070 <memcpy@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    11df <main+0x6f>
lea    0xe78(%rip),%rdi
call   1090 <perror@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1260 <main+0xf0>
movl   $0x0,-0x58(%rbp)
cmpl   $0x8,-0x58(%rbp)
jae    124c <main+0xdc>
mov    -0x58(%rbp),%eax
mov    -0x50(%rbp,%rax,8),%rdi
call   1050 <strlen@plt>
mov    %al,-0x59(%rbp)
mov    -0x54(%rbp),%edi
lea    -0x59(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x58(%rbp),%eax
mov    -0x50(%rbp,%rax,8),%rax
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%eax
mov    -0x50(%rbp,%rax,8),%rdi
call   1050 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11e6 <main+0x76>
mov    -0x54(%rbp),%edi
call   1060 <close@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    0xeac(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1364 <main+0x204>
mov    %eax,%ebx
lea    0xe6b(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xe38(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %al,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xe05(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %al,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xdd3(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %al,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xda5(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %al,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xd74(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %al,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xd43(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %al,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xd11(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %al,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xcd6(%rip),%rdi
call   1080 <perror@plt>
mov    0x2c69(%rip),%rax
jmp    1358 <main+0x1f8>

LLVM IR (-O0):
@.str = [7 x i8] c"Client\00"
@.str.1 = [8 x i8] c"Welcome\00"
@.str.2 = [3 x i8] c"to\00"
@.str.3 = [4 x i8] c"the\00"
@.str.4 = [8 x i8] c"module.\00"
@.str.5 = [5 x i8] c"This\00"
@.str.6 = [5 x i8] c"will\00"
@.str.7 = [4 x i8] c"now\00"
@.str.8 = [5 x i8] c"STOP\00"
@__const.main.strMessage = [8 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i32 0, i32 0)]
@.str.9 = [16 x i8] c"/tmp/demo6_fifo\00"
@O_WRONLY = global i32 0
@.str.10 = [17 x i8] c"Cannot open fifo\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8*]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 0, i32* %1
%6 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = bitcast [8 x i8*]* %2 to i8*
%8 = load i32, i32* @O_WRONLY
%9 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %1
br label %46
15: ; preds = %0
store i32 0, i32* %4
br label %16
16: ; preds = %39, %15
%17 = load i32, i32* %4
%18 = icmp ult i32 %17, 8
br i1 %18, label %19, label %42
19: ; preds = %16
%20 = load i32, i32* %4
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [8 x i8*], [8 x i8*]* %2, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = call i32 @strlen(i8* %23)
%25 = trunc i32 %24 to i8
store i8 %25, i8* %5
%26 = load i32, i32* %3
%27 = call i32 @write(i32 %26, i8* %5, i32 1)
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds [8 x i8*], [8 x i8*]* %2, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = load i32, i32* %4
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [8 x i8*], [8 x i8*]* %2, i64 0, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @write(i32 %28, i8* %32, i32 %37)
br label %39
39: ; preds = %19
%40 = load i32, i32* %4
%41 = add i32 %40, 1
store i32 %41, i32* %4
br label %16
42: ; preds = %16
%43 = load i32, i32* %3
%44 = call i32 @close(i32 %43)
%45 = load i32, i32* @EXIT_SUCCESS
store i32 %45, i32* %1
br label %46
46: ; preds = %42, %12
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [7 x i8] c"Client\00"
@.str.1 = [8 x i8] c"Welcome\00"
@.str.2 = [3 x i8] c"to\00"
@.str.3 = [4 x i8] c"the\00"
@.str.4 = [8 x i8] c"module.\00"
@.str.5 = [5 x i8] c"This\00"
@.str.6 = [5 x i8] c"will\00"
@.str.7 = [4 x i8] c"now\00"
@.str.8 = [5 x i8] c"STOP\00"
@.str.9 = [16 x i8] c"/tmp/demo6_fifo\00"
@O_WRONLY = global i32 0
@.str.10 = [17 x i8] c"Cannot open fifo\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i8
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %48, label %6
6: ; preds = %0
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = trunc i32 %7 to i8
store i8 %8, i8* %1
%9 = call i32 @write(i32 %4, i8* %1, i32 1)
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = trunc i32 %12 to i8
store i8 %13, i8* %1
%14 = call i32 @write(i32 %4, i8* %1, i32 1)
%15 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%18 = trunc i32 %17 to i8
store i8 %18, i8* %1
%19 = call i32 @write(i32 %4, i8* %1, i32 1)
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%23 = trunc i32 %22 to i8
store i8 %23, i8* %1
%24 = call i32 @write(i32 %4, i8* %1, i32 1)
%25 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%26 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%28 = trunc i32 %27 to i8
store i8 %28, i8* %1
%29 = call i32 @write(i32 %4, i8* %1, i32 1)
%30 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%31 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%33 = trunc i32 %32 to i8
store i8 %33, i8* %1
%34 = call i32 @write(i32 %4, i8* %1, i32 1)
%35 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%36 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %35)
%37 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%38 = trunc i32 %37 to i8
store i8 %38, i8* %1
%39 = call i32 @write(i32 %4, i8* %1, i32 1)
%40 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%41 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %40)
%42 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%43 = trunc i32 %42 to i8
store i8 %43, i8* %1
%44 = call i32 @write(i32 %4, i8* %1, i32 1)
%45 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%46 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 %45)
%47 = tail call i32 @close(i32 %4)
br label %50
48: ; preds = %0
%49 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0))
br label %50
50: ; preds = %6, %48
%51 = phi i32* [ @EXIT_FAILURE, %48 ], [ @EXIT_SUCCESS, %6 ]
%52 = load i32, i32* %51
ret i32 %52
}