#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, int *, int);
int main() {
  char *buf;
  int choice = 1;
  int fifo_server, fifo_client;
  printf("Chose one of following options to send to the server\n");
  printf("\t\t 1 for the name of the OS \n 	         2 for the name of "
         "distribution \n 	         3 for the version of Kernel \n");
  printf("Your choice: ");
  scanf("%d", &choice);
  fifo_server = open("FIFO-server", O_RDWR);
  if (fifo_server < 0) {
    fprintf(stderr, "Error in opening file");
    exit(-1);
  }
  write(fifo_server, &choice, sizeof(int));
  fifo_client = open("FIFO-client", O_RDWR);
  if (fifo_client < 0) {
    fprintf(stderr, "Error in opening file");
    exit(-1);
  }
  buf = malloc(10 * sizeof(char));
  read(fifo_client, buf, 10 * sizeof(char));
  printf("\n ### Server replied with %s ###\n", buf);
  close(fifo_server);
  close(fifo_client);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x14(%rbp)
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xede(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1090 <scanf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
lea    0xec8(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1221 <main+0x91>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1273 <main+0xe3>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    $0xa,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    -0x10(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x1,0xc(%rsp)
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe31(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe31(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <scanf@plt>
mov    0x2dfa(%rip),%rbx
mov    (%rbx),%esi
lea    0xe1a(%rip),%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     126f <main+0xcf>
mov    %eax,%r14d
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1040 <write@plt>
mov    (%rbx),%esi
lea    0xe16(%rip),%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     126f <main+0xcf>
mov    %eax,%ebp
mov    $0xa,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
mov    $0xa,%edx
call   1070 <read@plt>
lea    0xdf4(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"Chose one of following options to send to the server\0A\00"
@.str.1 = [113 x i8] c"\09\09 1 for the name of the OS \0A \09 2 for the name of distribution \0A \09 3 for the version of Kernel \0A\00"
@.str.2 = [14 x i8] c"Your choice: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [12 x i8] c"FIFO-server\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.5 = [22 x i8] c"Error in opening file\00"
@.str.6 = [12 x i8] c"FIFO-client\00"
@.str.7 = [34 x i8] c"\0A ### Server replied with %s ###\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([113 x i8], [113 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %0
%19 = load i32, i32* %4
%20 = call i32 @write(i32 %19, i32* %3, i32 4)
%21 = load i32, i32* @O_RDWR
%22 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %18
%30 = call i8* @malloc(i32 10)
store i8* %30, i8** %2
%31 = load i32, i32* %5
%32 = load i8*, i8** %2
%33 = call i32 @read(i32 %31, i8* %32, i32 10)
%34 = load i8*, i8** %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %4
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %5
%39 = call i32 @close(i32 %38)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [14 x i8] c"Your choice: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [12 x i8] c"FIFO-server\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.5 = [22 x i8] c"Error in opening file\00"
@.str.6 = [12 x i8] c"FIFO-client\00"
@.str.7 = [34 x i8] c"\0A ### Server replied with %s ###\0A\00"
@str = [53 x i8] c"Chose one of following options to send to the server\00"
@str.8 = [112 x i8] c"\09\09 1 for the name of the OS \0A \09 2 for the name of distribution \0A \09 3 for the version of Kernel \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([112 x i8], [112 x i8]* @str.8, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = call i32 @write(i32 %8, i32* %1, i32 4)
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %14
%24 = call dereferenceable_or_null(10) i8* @malloc(i32 10)
%25 = call i32 @read(i32 %17, i8* %24, i32 10)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %24)
%27 = call i32 @close(i32 %8)
%28 = call i32 @close(i32 %17)
ret i32 0
}