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

/* Variables and functions */
int /*<<< orphan*/ FD_CLR(int, int /*<<< orphan*/ *);
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHUT_WR;
int STDOUT_FILENO;
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
void str_cli(FILE *fp, int sockfd) {
  int filefd = fileno(fp);
  int maxfdp1 = (filefd > sockfd ? filefd : sockfd) + 1;
  int stdineof = 0;
  fd_set rset;
  char buf[100];
  int n;
  FD_ZERO(&rset);
  for (;;) {
    if (stdineof == 0)
      FD_SET(filefd, &rset);
    FD_SET(sockfd, &rset);
    select(maxfdp1, &rset, NULL, NULL, NULL);
    if (FD_ISSET(sockfd, &rset)) {
      if ((n = read(sockfd, buf, 100)) == 0) {
        if (stdineof == 1) {
          printf("client will exist\n");
        } else {
          printf("server is crashed.\n");
        }
        return;
      }
      write(STDOUT_FILENO, "|", 1);
      write(STDOUT_FILENO, buf, n);
    }
    if (FD_ISSET(filefd, &rset)) {
      if ((n = read(filefd, buf, 100)) == 1) {
        stdineof = 1;
        shutdown(sockfd, SHUT_WR);
        FD_CLR(filefd, &rset);
        continue;
      }
      write(sockfd, buf, n);
    }
  }
}


x86 assembly (clang, -O0):
<str_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <fileno@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11d8 <str_cli+0x38>
mov    -0x10(%rbp),%eax
mov    %eax,-0x88(%rbp)
jmp    11e1 <str_cli+0x41>
mov    -0xc(%rbp),%eax
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
call   1090 <FD_ZERO@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1213 <str_cli+0x73>
mov    -0x10(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0xc(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10a0 <select@plt>
mov    -0xc(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12ce <str_cli+0x12e>
mov    -0xc(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %eax,-0x84(%rbp)
cmp    $0x0,%eax
jne    129c <str_cli+0xfc>
cmpl   $0x1,-0x18(%rbp)
jne    1287 <str_cli+0xe7>
lea    0xd83(%rip),%rdi
call   1060 <printf@plt>
jmp    1293 <str_cli+0xf3>
lea    0xd85(%rip),%rdi
call   1060 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    -0x84(%rbp),%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     133f <str_cli+0x19f>
mov    -0x10(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %eax,-0x84(%rbp)
cmp    $0x1,%eax
jne    132d <str_cli+0x18d>
movl   $0x1,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2ccb(%rip),%rax
mov    (%rax),%esi
call   1050 <shutdown@plt>
mov    -0x10(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   10b0 <FD_CLR@plt>
jmp    11fd <str_cli+0x5d>
mov    -0xc(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0x84(%rbp),%edx
call   1030 <write@plt>
jmp    11fd <str_cli+0x5d>

x86 assembly (clang, -O2):
<str_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %esi,%ebx
call   1080 <fileno@plt>
mov    %eax,%r15d
cmp    %ebx,%eax
cmovle %ebx,%eax
add    $0x1,%eax
mov    %eax,0xc(%rsp)
lea    0x1c(%rsp),%rbp
mov    %rbp,%rdi
call   1090 <FD_ZERO@plt>
lea    0xe27(%rip),%rax
mov    %rax,0x10(%rsp)
mov    $0x1,%al
mov    %eax,0x8(%rsp)
lea    0x20(%rsp),%r12
nopl   0x0(%rax,%rax,1)
testb  $0x1,0x8(%rsp)
je     1202 <str_cli+0x62>
mov    %r15d,%edi
mov    %rbp,%rsi
call   10c0 <FD_SET@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10c0 <FD_SET@plt>
mov    0xc(%rsp),%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10a0 <select@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     1271 <str_cli+0xd1>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
test   %eax,%eax
je     12df <str_cli+0x13f>
mov    %eax,%r13d
mov    0x2da1(%rip),%r14
mov    (%r14),%edi
lea    0xda7(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    (%r14),%edi
mov    %r12,%rsi
mov    %r13d,%edx
call   1040 <write@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1050 <FD_ISSET@plt>
test   %rax,%rax
je     11f0 <str_cli+0x50>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
cmp    $0x1,%eax
je     12ab <str_cli+0x10b>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    11f0 <str_cli+0x50>
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <shutdown@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   10b0 <FD_CLR@plt>
movl   $0x0,0x8(%rsp)
lea    0xd40(%rip),%rax
mov    %rax,0x10(%rsp)
jmp    11f0 <str_cli+0x50>
mov    0x10(%rsp),%rdi
call   1030 <puts@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"client will exist\0A\00"
@.str.1 = [20 x i8] c"server is crashed.\0A\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [2 x i8] c"|\00"
@SHUT_WR = global i32 0
define void @str_cli(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [100 x i8]
%10 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%11 = load i32*, i32** %3
%12 = call i32 @fileno(i32* %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp sgt i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i32, i32* %5
br label %20
18: ; preds = %2
%19 = load i32, i32* %4
br label %20
20: ; preds = %18, %16
%21 = phi i32 [ %17, %16 ], [ %19, %18 ]
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
store i32 0, i32* %7
%23 = call i32 @FD_ZERO(i32* %8)
br label %24
24: ; preds = %78, %67, %20
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %5
%29 = call i32 @FD_SET(i32 %28, i32* %8)
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %4
%32 = call i32 @FD_SET(i32 %31, i32* %8)
%33 = load i32, i32* %6
%34 = call i32 @select(i32 %33, i32* %8, i32* null, i32* null, i32* null)
%35 = load i32, i32* %4
%36 = call i64 @FD_ISSET(i32 %35, i32* %8)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %58
38: ; preds = %30
%39 = load i32, i32* %4
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%41 = call i32 @read(i32 %39, i8* %40, i32 100)
store i32 %41, i32* %10
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %51
43: ; preds = %38
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %50
48: ; preds = %43
%49 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
ret void
51: ; preds = %38
%52 = load i32, i32* @STDOUT_FILENO
%53 = call i32 @write(i32 %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%54 = load i32, i32* @STDOUT_FILENO
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%56 = load i32, i32* %10
%57 = call i32 @write(i32 %54, i8* %55, i32 %56)
br label %58
58: ; preds = %51, %30
%59 = load i32, i32* %5
%60 = call i64 @FD_ISSET(i32 %59, i32* %8)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %78
62: ; preds = %58
%63 = load i32, i32* %5
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%65 = call i32 @read(i32 %63, i8* %64, i32 100)
store i32 %65, i32* %10
%66 = icmp eq i32 %65, 1
br i1 %66, label %67, label %73
67: ; preds = %62
store i32 1, i32* %7
%68 = load i32, i32* %4
%69 = load i32, i32* @SHUT_WR
%70 = call i32 @shutdown(i32 %68, i32 %69)
%71 = load i32, i32* %5
%72 = call i32 @FD_CLR(i32 %71, i32* %8)
br label %24
73: ; preds = %62
%74 = load i32, i32* %4
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%76 = load i32, i32* %10
%77 = call i32 @write(i32 %74, i8* %75, i32 %76)
br label %78
78: ; preds = %73, %58
br label %24
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str.2 = [2 x i8] c"|\00"
@SHUT_WR = global i32 0
@str = [19 x i8] c"server is crashed.\00"
@str.3 = [18 x i8] c"client will exist\00"
define void @str_cli(i32* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = tail call i32 @fileno(i32* %0)
%6 = icmp sgt i32 %5, %1
%7 = select i1 %6, i32 %5, i32 %1
%8 = add nsw i32 %7, 1
%9 = bitcast i32* %3 to i8*
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%11 = call i32 @FD_ZERO(i32* %3)
br label %12
12: ; preds = %39, %2
%13 = phi i1 [ false, %39 ], [ true, %2 ]
%14 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0), %39 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), %2 ]
br label %15
15: ; preds = %45, %12
br i1 %13, label %16, label %18
16: ; preds = %15
%17 = call i32 @FD_SET(i32 %5, i32* %3)
br label %18
18: ; preds = %16, %15
%19 = call i32 @FD_SET(i32 %1, i32* %3)
%20 = call i32 @select(i32 %8, i32* %3, i32* null, i32* null, i32* null)
%21 = call i64 @FD_ISSET(i32 %1, i32* %3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %33, label %23
23: ; preds = %18
%24 = call i32 @read(i32 %1, i8* %10, i32 100)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @puts(i8* dereferenceable(1) %14)
ret void
28: ; preds = %23
%29 = load i32, i32* @STDOUT_FILENO
%30 = call i32 @write(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%31 = load i32, i32* @STDOUT_FILENO
%32 = call i32 @write(i32 %31, i8* %10, i32 %24)
br label %33
33: ; preds = %28, %18
%34 = call i64 @FD_ISSET(i32 %5, i32* %3)
%35 = icmp eq i64 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %33
%37 = call i32 @read(i32 %5, i8* %10, i32 100)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* @SHUT_WR
%41 = call i32 @shutdown(i32 %1, i32 %40)
%42 = call i32 @FD_CLR(i32 %5, i32* %3)
br label %12
43: ; preds = %36
%44 = call i32 @write(i32 %1, i8* %10, i32 %37)
br label %45
45: ; preds = %43, %33
br label %15
}