#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_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
size_t read(int, char *, int);
int /*<<< orphan*/ sleep(int);
size_t write(int, char *, int);
int main() {
  size_t size;
  char string[] = "Hello, Kitty!";
  char st[50];
  int sz = 14;
  int fd = open("Fifo.txt", O_RDWR);
  size = read(fd, st, sz);
  printf("Prog3 read - |%s|\n", st);
  sleep(3);
  size = write(fd, string, sz);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x1e(%rbp)
mov    0xe88(%rip),%eax
mov    %eax,-0x16(%rbp)
mov    0xe82(%rip),%ax
mov    %ax,-0x12(%rbp)
movl   $0xe,-0x54(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1060 <read@plt>
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3,%edi
call   1080 <sleep@plt>
mov    -0x58(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1030 <write@plt>
mov    %rax,-0x10(%rbp)
mov    -0x58(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
movabs $0x21797474694b20,%rax
mov    %rax,0x6(%rsp)
movabs $0x4b202c6f6c6c6548,%rax
2c 20 4b
mov    %rax,(%rsp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xe,%edx
call   1060 <read@plt>
lea    0xe61(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    $0x3,%edi
call   1080 <sleep@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.string = [14 x i8] c"Hello, Kitty!\00"
@.str = [9 x i8] c"Fifo.txt\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"Prog3 read - |%s|\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [14 x i8]
%4 = alloca [50 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [14 x i8]* %3 to i8*
store i32 14, i32* %5
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* %5
%13 = call i64 @read(i32 %10, i8* %11, i32 %12)
store i64 %13, i64* %2
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @sleep(i32 3)
%17 = load i32, i32* %6
%18 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%19 = load i32, i32* %5
%20 = call i64 @write(i32 %17, i8* %18, i32 %19)
store i64 %20, i64* %2
%21 = load i32, i32* %6
%22 = call i32 @close(i32 %21)
ret i32 0
}

LLVM IR (-O2):
@__const.main.string = [14 x i8] c"Hello, Kitty!\00"
@.str = [9 x i8] c"Fifo.txt\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"Prog3 read - |%s|\0A\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i64 @read(i32 %6, i8* %4, i32 14)
%8 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%9 = call i32 @sleep(i32 3)
%10 = call i64 @write(i32 %6, i8* %3, i32 14)
%11 = call i32 @close(i32 %6)
ret i32 0
}