#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int S_IFIFO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int reader, writer, fd, i;
  char p[100], c[1000];
  for (i = 0; i < 100; i++)
    c[i] = p[i] = '\0';
  mknod("/tmp/fifo1", S_IFIFO | 777, 0);
  mknod("/tmp/fifo2", S_IFIFO | 777, 0);
  printf(" Status: Waiting for client... \n ");
  reader = open("/tmp/fifo1", O_RDONLY);
  read(reader, p, 100);
  printf(" Status: Recieved Request from client. \n");
  printf("%s", p);
  if ((fd = open(p, O_RDONLY)) < 0) {
    writer = open("/tmp/fifo2", O_WRONLY);
    write(writer, "404 file not found.", 20);
    exit(0);
  }
  read(fd, c, 1000);
  printf(" server:%s found! \n transfering the content \n ", p);
  writer = open("/tmp/fifo2", O_WRONLY);
  write(writer, c, strlen(c));
  printf("Server:transfer completed\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11b6 <main+0x46>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
movslq -0x14(%rbp),%rax
movb   $0x0,-0x470(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1189 <main+0x19>
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
or     $0x309,%esi
lea    0xe34(%rip),%rdi
xor    %edx,%edx
call   1070 <mknod@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
or     $0x309,%esi
lea    0xe22(%rip),%rdi
xor    %edx,%edx
call   1070 <mknod@plt>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
lea    0xdf2(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1060 <read@plt>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    1298 <main+0x128>
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
lea    0xd96(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xddd(%rip),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%edi
lea    -0x470(%rbp),%rsi
mov    $0x3e8,%edx
call   1060 <read@plt>
lea    -0x80(%rbp),%rsi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%esi
lea    0xd3d(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x47c(%rbp)
lea    -0x470(%rbp),%rax
mov    %rax,-0x478(%rbp)
lea    -0x470(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x47c(%rbp),%edi
mov    -0x478(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x460,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
movl   $0x0,0x60(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xc0(%rsp)
movl   $0x0,0xd0(%rsp)
mov    0x2de6(%rip),%rbp
mov    $0x309,%ebx
mov    0x0(%rbp),%esi
or     %ebx,%esi
lea    0xdfd(%rip),%r14
mov    %r14,%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
or     0x0(%rbp),%ebx
lea    0xdf4(%rip),%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1080 <mknod@plt>
lea    0xdef(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2db3(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %r14,%rdi
call   1090 <open@plt>
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
lea    0xe25(%rip),%rdi
call   1030 <puts@plt>
lea    0xdd3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     12e8 <main+0x168>
lea    0x70(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1070 <read@plt>
lea    0xdb6(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
lea    0xd58(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xdd1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2cd9(%rip),%rax
mov    (%rax),%esi
lea    0xd13(%rip),%rdi
call   1090 <open@plt>
lea    0xd37(%rip),%rsi
mov    %eax,%edi
mov    $0x14,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/tmp/fifo1\00"
@S_IFIFO = global i32 0
@.str.1 = [11 x i8] c"/tmp/fifo2\00"
@.str.2 = [34 x i8] c" Status: Waiting for client... \0A \00"
@O_RDONLY = global i32 0
@.str.3 = [41 x i8] c" Status: Recieved Request from client. \0A\00"
@.str.4 = [3 x i8] c"%s\00"
@O_WRONLY = global i32 0
@.str.5 = [20 x i8] c"404 file not found.\00"
@.str.6 = [47 x i8] c" server:%s found! \0A transfering the content \0A \00"
@.str.7 = [27 x i8] c"Server:transfer completed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 0, i32* %5
br label %8
8: ; preds = %18, %0
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 100
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %13
store i8 0, i8* %14
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %11
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %8
21: ; preds = %8
%22 = load i32, i32* @S_IFIFO
%23 = or i32 %22, 777
%24 = call i32 @mknod(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %23, i32 0)
%25 = load i32, i32* @S_IFIFO
%26 = or i32 %25, 777
%27 = call i32 @mknod(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 0)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @O_RDONLY
%30 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %29)
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%33 = call i32 @read(i32 %31, i8* %32, i32 100)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%38 = load i32, i32* @O_RDONLY
%39 = call i32 @open(i8* %37, i32 %38)
store i32 %39, i32* %4
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %21
%42 = load i32, i32* @O_WRONLY
%43 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %42)
store i32 %43, i32* %3
%44 = load i32, i32* %3
%45 = call i32 @write(i32 %44, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 20)
%46 = call i32 @exit(i32 0)
unreachable
47: ; preds = %21
%48 = load i32, i32* %4
%49 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%50 = call i32 @read(i32 %48, i8* %49, i32 1000)
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @O_WRONLY
%54 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %53)
store i32 %54, i32* %3
%55 = load i32, i32* %3
%56 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%57 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%58 = call i32 @strlen(i8* %57)
%59 = call i32 @write(i32 %55, i8* %56, i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/tmp/fifo1\00"
@S_IFIFO = global i32 0
@.str.1 = [11 x i8] c"/tmp/fifo2\00"
@.str.2 = [34 x i8] c" Status: Waiting for client... \0A \00"
@O_RDONLY = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@O_WRONLY = global i32 0
@.str.5 = [20 x i8] c"404 file not found.\00"
@.str.6 = [47 x i8] c" server:%s found! \0A transfering the content \0A \00"
@str = [40 x i8] c" Status: Recieved Request from client. \00"
@str.8 = [26 x i8] c"Server:transfer completed\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @S_IFIFO
%8 = or i32 %7, 777
%9 = tail call i32 @mknod(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8, i32 0)
%10 = load i32, i32* @S_IFIFO
%11 = or i32 %10, 777
%12 = tail call i32 @mknod(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32 @read(i32 %15, i8* %5, i32 100)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %5, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %0
%23 = load i32, i32* @O_WRONLY
%24 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i32 @write(i32 %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 20)
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %0
%28 = call i32 @read(i32 %20, i8* %6, i32 1000)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%30 = load i32, i32* @O_WRONLY
%31 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = call i32 @strlen(i8* %6)
%33 = call i32 @write(i32 %31, i8* %6, i32 %32)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.8, i64 0, i64 0))
ret i32 0
}