#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 key_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int IPC_CREAT;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int mkfifo(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ shmdt(int *);
int shmget(int, int, int);
int unlink(char *);
int main(int argc, char *argv[]) {
  int *sharedInt;
  int shmid;
  key_t key = 5678;
  FILE *fp_fifo;
  int count;
  char buf[4096];
  unlink("RESULT_FIFO");
  if ((shmid = shmget(key, sizeof(int *), IPC_CREAT | 0666)) < 0) {
    perror("shmget");
    exit(EXIT_FAILURE);
  }
  if ((sharedInt = (int *)shmat(shmid, NULL, 0)) == (int *)-1) {
    perror("shmat");
    exit(EXIT_FAILURE);
  }
  int *sharedIntStart = sharedInt;
  *sharedIntStart++ = 0;
  if (mkfifo("RESULT_FIFO", 0777) == -1) {
    perror("mkfifo");
    exit(EXIT_FAILURE);
  }
  if ((fp_fifo = fopen("RESULT_FIFO", "r")) == NULL) {
    perror("fopen");
    exit(EXIT_FAILURE);
  }
  printf("I got: ");
  while ((count = fscanf(fp_fifo, "%s", buf)) > 0) {
    printf("%s", buf);
  }
  printf("\n");
  if (fclose(fp_fifo) == EOF) {
    perror("fclose");
    exit(EXIT_FAILURE);
  }
  if (unlink("RESULT_FIFO") == -1) {
    perror("unlink");
    exit(EXIT_FAILURE);
  }
  shmdt(sharedInt);
  shmctl(shmid, IPC_RMID, NULL);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x162e,-0x20(%rbp)
lea    0xe19(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x20(%rbp),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x8,%esi
call   10d0 <shmget@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    122e <main+0x6e>
lea    0xdf1(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x1c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10c0 <shmat@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    126a <main+0xaa>
lea    0xdbc(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1038(%rbp)
mov    -0x1038(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x1038(%rbp)
movl   $0x0,(%rax)
lea    0xd69(%rip),%rdi
mov    $0x1ff,%esi
call   1080 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    12c4 <main+0x104>
lea    0xd68(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xd35(%rip),%rdi
lea    0xd4e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12ff <main+0x13f>
lea    0xd36(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xd22(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x1030(%rbp),%rdx
lea    0xd11(%rip),%rsi
call   1070 <fscanf@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jle    134a <main+0x18a>
lea    -0x1030(%rbp),%rsi
lea    0xcf2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    130d <main+0x14d>
lea    0xce2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2c80(%rip),%rcx
cmp    (%rcx),%rax
jne    138b <main+0x1cb>
lea    0xcbd(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c54(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xc6e(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    13ba <main+0x1fa>
lea    0xc95(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <shmdt@plt>
mov    -0x1c(%rbp),%edi
mov    0x2c03(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <shmctl@plt>
mov    0x2be9(%rip),%rax
mov    (%rax),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
lea    0xe1a(%rip),%rdi
call   1040 <unlink@plt>
mov    0x2dce(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x162e,%edi
mov    $0x8,%esi
call   10e0 <shmget@plt>
test   %eax,%eax
js     1322 <main+0x152>
mov    %eax,%r14d
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <shmat@plt>
cmp    $0xffffffffffffffff,%rax
je     132b <main+0x15b>
mov    %rax,%r15
movl   $0x0,(%rax)
lea    0xdc8(%rip),%rdi
mov    $0x1ff,%esi
call   1090 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     1334 <main+0x164>
lea    0xdae(%rip),%rdi
lea    0xdc7(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     133d <main+0x16d>
mov    %rax,%r12
lea    0xdb7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdb1(%rip),%rsi
mov    %rsp,%rdx
mov    %r12,%rdi
call   1080 <fscanf@plt>
test   %eax,%eax
jle    12bf <main+0xef>
lea    0xd9b(%rip),%rbx
mov    %rsp,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1080 <fscanf@plt>
test   %eax,%eax
jg     12a0 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    0x2d10(%rip),%rcx
cmp    (%rcx),%rax
je     1346 <main+0x176>
lea    0xd1c(%rip),%rdi
call   1040 <unlink@plt>
cmp    $0xffffffff,%eax
je     134f <main+0x17f>
mov    %r15,%rdi
call   1050 <shmdt@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
xor    %edx,%edx
call   10a0 <shmctl@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xce3(%rip),%rdi
jmp    1356 <main+0x186>
lea    0xce1(%rip),%rdi
jmp    1356 <main+0x186>
lea    0xcde(%rip),%rdi
jmp    1356 <main+0x186>
lea    0xcde(%rip),%rdi
jmp    1356 <main+0x186>
lea    0xce6(%rip),%rdi
jmp    1356 <main+0x186>
lea    0xce4(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"RESULT_FIFO\00"
@IPC_CREAT = global i32 0
@.str.1 = [7 x i8] c"shmget\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [6 x i8] c"shmat\00"
@.str.3 = [7 x i8] c"mkfifo\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [6 x i8] c"fopen\00"
@.str.6 = [8 x i8] c"I got: \00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [2 x i8] c"\0A\00"
@EOF = global i64 0
@.str.9 = [7 x i8] c"fclose\00"
@.str.10 = [7 x i8] c"unlink\00"
@IPC_RMID = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [4096 x i8]
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 5678, i32* %8
%13 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %8
%15 = load i32, i32* @IPC_CREAT
%16 = or i32 %15, 438
%17 = call i32 @shmget(i32 %14, i32 8, i32 %16)
store i32 %17, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i32, i32* %7
%25 = call i64 @shmat(i32 %24, i32* null, i32 0)
%26 = inttoptr i64 %25 to i32*
store i32* %26, i32** %6
%27 = icmp eq i32* %26, inttoptr (i64 -1 to i32*)
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %23
%33 = load i32*, i32** %6
store i32* %33, i32** %12
%34 = load i32*, i32** %12
%35 = getelementptr inbounds i32, i32* %34, i32 1
store i32* %35, i32** %12
store i32 0, i32* %34
%36 = call i32 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 511)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %32
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %32
%43 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %43, i32** %9
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %42
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %51
51: ; preds = %56, %49
%52 = load i32*, i32** %9
%53 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%54 = call i32 @fscanf(i32* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %53)
store i32 %54, i32* %10
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %57)
br label %51
59: ; preds = %51
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%61 = load i32*, i32** %9
%62 = call i64 @fclose(i32* %61)
%63 = load i64, i64* @EOF
%64 = icmp eq i64 %62, %63
br i1 %64, label %65, label %69
65: ; preds = %59
%66 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%67 = load i32, i32* @EXIT_FAILURE
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %59
%70 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %76
72: ; preds = %69
%73 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %69
%77 = load i32*, i32** %6
%78 = call i32 @shmdt(i32* %77)
%79 = load i32, i32* %7
%80 = load i32, i32* @IPC_RMID
%81 = call i32 @shmctl(i32 %79, i32 %80, i32* null)
%82 = load i32, i32* @EXIT_SUCCESS
ret i32 %82
}

LLVM IR (-O2):
@.str = [12 x i8] c"RESULT_FIFO\00"
@IPC_CREAT = global i32 0
@.str.1 = [7 x i8] c"shmget\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [6 x i8] c"shmat\00"
@.str.3 = [7 x i8] c"mkfifo\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [6 x i8] c"fopen\00"
@.str.6 = [8 x i8] c"I got: \00"
@.str.7 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.9 = [7 x i8] c"fclose\00"
@.str.10 = [7 x i8] c"unlink\00"
@IPC_RMID = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @IPC_CREAT
%7 = or i32 %6, 438
%8 = tail call i32 @shmget(i32 5678, i32 8, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = tail call i64 @shmat(i32 %8, i32* null, i32 0)
%16 = inttoptr i64 %15 to i32*
%17 = icmp eq i32* %16, inttoptr (i64 -1 to i32*)
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %14
store i32 0, i32* %16
%23 = tail call i32 @mkfifo(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 511)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %22
%30 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %29
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%38 = call i32 @fscanf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %36, %40
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%42 = call i32 @fscanf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%43 = icmp sgt i32 %42, 0
br i1 %43, label %40, label %44
44: ; preds = %40, %36
%45 = call i32 @putchar(i32 10)
%46 = call i64 @fclose(i32* %30)
%47 = load i64, i64* @EOF
%48 = icmp eq i64 %46, %47
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %44
%54 = call i32 @unlink(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %60
56: ; preds = %53
%57 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %53
%61 = call i32 @shmdt(i32* %16)
%62 = load i32, i32* @IPC_RMID
%63 = call i32 @shmctl(i32 %8, i32 %62, i32* null)
%64 = load i32, i32* @EXIT_SUCCESS
ret i32 %64
}