#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*/ close(int);
int /*<<< orphan*/ exit(int);
int init_sockconnect(char const *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int recv_fd(int);
int /*<<< orphan*/ scanf(char *, int *);
scalar_t__ send_fd(int, int);
int main(int argc, char const *argv[]) {
  if (argc < 2) {
    printf("Usage: ./server <temperory_sock_path>\n");
    exit(1);
  }
  int usfd = init_sockconnect(argv[1]);
  if (usfd < 0) {
    printf("sock() error\n");
    exit(1);
  }
  int fd, n;
  char buf[1024];
  printf("Process 2 Started !!\n");
  while (1) {
    fd = recv_fd(usfd);
    if (fd < 0) {
      perror("recv_fd() ");
      exit(1);
    }
    printf("Number of bytes to print: ");
    scanf("%d", &n);
    read(fd, buf, n);
    printf("%s\n", buf);
    memset(buf, 0, n);
    if (send_fd(usfd, fd) < 0) {
      perror("send_fd() ");
      exit(1);
    }
    close(fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11db <main+0x3b>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <init_sockconnect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    120d <main+0x6d>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <recv_fd@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1246 <main+0xa6>
lea    0xe14(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe16(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <read@plt>
lea    -0x420(%rbp),%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <send_fd@plt>
cmp    $0x0,%rax
jge    12c7 <main+0x127>
lea    0xdc0(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
jmp    121b <main+0x7b>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
cmp    $0x1,%edi
jg     11cf <main+0x1f>
lea    0xe89(%rip),%rdi
jmp    11e3 <main+0x33>
mov    0x8(%rsi),%rdi
call   1040 <init_sockconnect@plt>
test   %eax,%eax
jns    11f2 <main+0x42>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %eax,%ebx
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   10a0 <recv_fd@plt>
test   %eax,%eax
js     128b <main+0xdb>
mov    %eax,%ebp
lea    0xdf3(%rip),%r14
lea    0xe07(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%r13
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   10b0 <scanf@plt>
mov    0xc(%rsp),%edx
mov    %ebp,%edi
mov    %r13,%rsi
call   1090 <read@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <send_fd@plt>
test   %rax,%rax
js     1294 <main+0xe4>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %ebx,%edi
call   10a0 <recv_fd@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1230 <main+0x80>
lea    0xd6e(%rip),%rdi
jmp    129b <main+0xeb>
lea    0xd8e(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"Usage: ./server <temperory_sock_path>\0A\00"
@.str.1 = [14 x i8] c"sock() error\0A\00"
@.str.2 = [22 x i8] c"Process 2 Started !!\0A\00"
@.str.3 = [11 x i8] c"recv_fd() \00"
@.str.4 = [27 x i8] c"Number of bytes to print: \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [11 x i8] c"send_fd() \00"
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 [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @init_sockconnect(i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %15
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %54
%28 = load i32, i32* %6
%29 = call i32 @recv_fd(i32 %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %27
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %8)
%38 = load i32, i32* %7
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%40 = load i32, i32* %8
%41 = call i32 @read(i32 %38, i8* %39, i32 %40)
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %42)
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%45 = load i32, i32* %8
%46 = call i32 @memset(i8* %44, i32 0, i32 %45)
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = call i64 @send_fd(i32 %47, i32 %48)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %35
%52 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %35
%55 = load i32, i32* %7
%56 = call i32 @close(i32 %55)
br label %27
}

LLVM IR (-O2):
@.str.3 = [11 x i8] c"recv_fd() \00"
@.str.4 = [27 x i8] c"Number of bytes to print: \00"
@.str.5 = [3 x i8] c"%d\00"
@.str.7 = [11 x i8] c"send_fd() \00"
@str = [21 x i8] c"Process 2 Started !!\00"
@str.8 = [13 x i8] c"sock() error\00"
@str.9 = [38 x i8] c"Usage: ./server <temperory_sock_path>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.9, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @init_sockconnect(i8* %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = bitcast i32* %3 to i8*
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%21 = call i32 @recv_fd(i32 %12)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %40, %17
%24 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17, %40
%27 = phi i32 [ %42, %40 ], [ %21, %17 ]
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%30 = load i32, i32* %3
%31 = call i32 @read(i32 %27, i8* %19, i32 %30)
%32 = call i32 @puts(i8* %19)
%33 = load i32, i32* %3
%34 = call i32 @memset(i8* %19, i32 0, i32 %33)
%35 = call i64 @send_fd(i32 %12, i32 %27)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %26
%38 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %26
%41 = call i32 @close(i32 %27)
%42 = call i32 @recv_fd(i32 %12)
%43 = icmp slt i32 %42, 0
br i1 %43, label %23, label %26
}