#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*/ ssize_t;
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*/ Read(int, char *, int);
int /*<<< orphan*/ SHUT_WR;
int /*<<< orphan*/ Select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ Shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ Write(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ Writen(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ err_quit(char *);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdout;
void str_cli(FILE *fp, int sockfd) {
  int maxfdp1, stdineof;
  fd_set rset;
  char buf[1024];
  ssize_t n;
  stdineof = 0;
  FD_ZERO(&rset);
  for (;;) {
    if (stdineof == 0)
      FD_SET(fileno(fp), &rset);
    FD_SET(sockfd, &rset);
    maxfdp1 = ((fileno(fp)) > (sockfd) ? (fileno(fp)) : (sockfd)) + 1;
    Select(maxfdp1, &rset, NULL, NULL, NULL);
    if (FD_ISSET(sockfd, &rset)) {
      if ((n = Read(sockfd, buf, 1024)) == 0) {
        if (stdineof == 1)
          return;
        else
          err_quit("str_cli: server terminated prematurely");
      }
      Write(fileno(stdout), buf, n);
    }
    if (FD_ISSET(fileno(fp), &rset)) {
      if ((n = Read(fileno(fp), buf, 1024)) == 0) {
        stdineof = 1;
        Shutdown(sockfd, SHUT_WR);
        FD_CLR(fileno(fp), &rset);
        continue;
      }
      Writen(sockfd, buf, n);
    }
  }
}


x86 assembly (clang, -O0):
<str_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
call   1080 <FD_ZERO@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11f0 <str_cli+0x40>
mov    -0x8(%rbp),%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0x8(%rbp),%rdi
call   1070 <fileno@plt>
cmp    -0xc(%rbp),%eax
jle    1222 <str_cli+0x72>
mov    -0x8(%rbp),%rdi
call   1070 <fileno@plt>
mov    %eax,-0x428(%rbp)
jmp    122b <str_cli+0x7b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x428(%rbp)
mov    -0x428(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10a0 <Select@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12ce <str_cli+0x11e>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1030 <Read@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jne    12ab <str_cli+0xfb>
cmpl   $0x1,-0x14(%rbp)
jne    129a <str_cli+0xea>
add    $0x430,%rsp
pop    %rbp
ret
lea    0xd5f(%rip),%rdi
call   1060 <err_quit@plt>
jmp    12ab <str_cli+0xfb>
mov    0x2d26(%rip),%rax
mov    (%rax),%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
lea    -0x420(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1050 <Write@plt>
mov    -0x8(%rbp),%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     135d <str_cli+0x1ad>
mov    -0x8(%rbp),%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1030 <Read@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jne    1348 <str_cli+0x198>
movl   $0x1,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2cc0(%rip),%rax
mov    (%rax),%esi
call   1090 <Shutdown@plt>
mov    -0x8(%rbp),%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   10c0 <FD_CLR@plt>
jmp    11d2 <str_cli+0x22>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   10b0 <Writen@plt>
jmp    11d2 <str_cli+0x22>

x86 assembly (clang, -O2):
<str_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1080 <FD_ZERO@plt>
mov    $0x1,%r13b
xor    %eax,%eax
mov    %rax,(%rsp)
lea    0x10(%rsp),%r12
jmp    121b <str_cli+0x6b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1030 <Read@plt>
test   %eax,%eax
je     12d8 <str_cli+0x128>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   10b0 <Writen@plt>
test   $0x1,%r13b
je     1233 <str_cli+0x83>
mov    %r14,%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   10d0 <FD_SET@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   10d0 <FD_SET@plt>
mov    %r14,%rdi
call   1070 <fileno@plt>
mov    %ebx,%edi
cmp    %ebx,%eax
jle    1255 <str_cli+0xa5>
mov    %r14,%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10a0 <Select@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     12b8 <str_cli+0x108>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1030 <Read@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    129d <str_cli+0xed>
testb  $0x1,(%rsp)
jne    1308 <str_cli+0x158>
lea    0xd68(%rip),%rdi
call   1060 <err_quit@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <Write@plt>
mov    %r14,%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
jne    11f0 <str_cli+0x40>
jmp    121b <str_cli+0x6b>
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1090 <Shutdown@plt>
mov    %r14,%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   10c0 <FD_CLR@plt>
mov    $0x1,%al
mov    %rax,(%rsp)
xor    %r13d,%r13d
jmp    121b <str_cli+0x6b>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [39 x i8] c"str_cli: server terminated prematurely\00"
@stdout = global i32* null
@SHUT_WR = global i32 0
define void @str_cli(i32* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @FD_ZERO(i32* %3)
br label %8
8: ; preds = %46, %2
%9 = phi i1 [ false, %46 ], [ true, %2 ]
%10 = phi i1 [ true, %46 ], [ false, %2 ]
br label %11
11: ; preds = %53, %8
br i1 %9, label %12, label %15
12: ; preds = %11
%13 = call i32 @fileno(i32* %0)
%14 = call i32 @FD_SET(i32 %13, i32* %3)
br label %15
15: ; preds = %12, %11
%16 = call i32 @FD_SET(i32 %1, i32* %3)
%17 = call i32 @fileno(i32* %0)
%18 = icmp sgt i32 %17, %1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @fileno(i32* %0)
br label %21
21: ; preds = %15, %19
%22 = phi i32 [ %20, %19 ], [ %1, %15 ]
%23 = add nsw i32 %22, 1
%24 = call i32 @Select(i32 %23, i32* %3, i32* null, i32* null, i32* null)
%25 = call i64 @FD_ISSET(i32 %1, i32* %3)
%26 = icmp eq i64 %25, 0
br i1 %26, label %38, label %27
27: ; preds = %21
%28 = call i32 @Read(i32 %1, i8* %6, i32 1024)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
br i1 %10, label %31, label %32
31: ; preds = %30
ret void
32: ; preds = %30
%33 = call i32 @err_quit(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = load i32*, i32** @stdout
%36 = call i32 @fileno(i32* %35)
%37 = call i32 @Write(i32 %36, i8* %6, i32 %28)
br label %38
38: ; preds = %34, %21
%39 = call i32 @fileno(i32* %0)
%40 = call i64 @FD_ISSET(i32 %39, i32* %3)
%41 = icmp eq i64 %40, 0
br i1 %41, label %53, label %42
42: ; preds = %38
%43 = call i32 @fileno(i32* %0)
%44 = call i32 @Read(i32 %43, i8* %6, i32 1024)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %42
%47 = load i32, i32* @SHUT_WR
%48 = call i32 @Shutdown(i32 %1, i32 %47)
%49 = call i32 @fileno(i32* %0)
%50 = call i32 @FD_CLR(i32 %49, i32* %3)
br label %8
51: ; preds = %42
%52 = call i32 @Writen(i32 %1, i8* %6, i32 %44)
br label %53
53: ; preds = %51, %38
br label %11
}