#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 */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ *Fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ Fputs(char *, int /*<<< orphan*/);
scalar_t__ Readline(int, char *, int);
int /*<<< orphan*/ Select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ Writen(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ err_quit(char *);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
void str_cli(FILE *fp, int sockfd) {
  int maxfdp1;
  fd_set rset;
  char sendline[1024], recvline[1024];
  FD_ZERO(&rset);
  for (;;) {
    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 (Readline(sockfd, recvline, 1024) == 0)
        err_quit("str_cli: server terminated prematurely");
      Fputs(recvline, stdout);
    }
    if (FD_ISSET(fileno(fp), &rset)) {
      if (Fgets(sendline, 1024, fp) == NULL)
        return;
      Writen(sockfd, sendline, strlen(sendline));
    }
  }
}


x86 assembly (clang, -O0):
<str_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x14(%rbp),%rdi
call   10a0 <FD_ZERO@plt>
mov    -0x8(%rbp),%rdi
call   1090 <fileno@plt>
mov    %eax,%edi
lea    -0x14(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   10d0 <FD_SET@plt>
mov    -0x8(%rbp),%rdi
call   1090 <fileno@plt>
cmp    -0xc(%rbp),%eax
jle    1211 <str_cli+0x61>
mov    -0x8(%rbp),%rdi
call   1090 <fileno@plt>
mov    %eax,-0x824(%rbp)
jmp    121a <str_cli+0x6a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x824(%rbp)
mov    -0x824(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10b0 <Select@plt>
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1292 <str_cli+0xe2>
mov    -0xc(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x400,%edx
call   1080 <Readline@plt>
cmp    $0x0,%rax
jne    127d <str_cli+0xcd>
lea    0xd88(%rip),%rdi
call   1070 <err_quit@plt>
lea    -0x820(%rbp),%rdi
mov    0x2d55(%rip),%rax
mov    (%rax),%esi
call   1030 <Fputs@plt>
mov    -0x8(%rbp),%rdi
call   1090 <fileno@plt>
mov    %eax,%edi
lea    -0x14(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     130f <str_cli+0x15f>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1060 <Fgets@plt>
cmp    $0x0,%rax
jne    12d8 <str_cli+0x128>
add    $0x840,%rsp
pop    %rbp
ret
mov    -0xc(%rbp),%eax
mov    %eax,-0x834(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x830(%rbp)
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x834(%rbp),%edi
mov    -0x830(%rbp),%rsi
mov    %eax,%edx
call   10c0 <Writen@plt>
jmp    11cb <str_cli+0x1b>

x86 assembly (clang, -O2):
<str_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   10a0 <FD_ZERO@plt>
lea    0x410(%rsp),%r12
lea    0x10(%rsp),%r13
mov    0x2df9(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1090 <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   1090 <fileno@plt>
mov    %ebx,%edi
cmp    %ebx,%eax
jle    1224 <str_cli+0x74>
mov    %r14,%rdi
call   1090 <fileno@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <Select@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1270 <str_cli+0xc0>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x400,%edx
call   1080 <Readline@plt>
test   %rax,%rax
jne    1265 <str_cli+0xb5>
lea    0xda0(%rip),%rdi
call   1070 <err_quit@plt>
mov    0x0(%rbp),%esi
mov    %r13,%rdi
call   1030 <Fputs@plt>
mov    %r14,%rdi
call   1090 <fileno@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     11f0 <str_cli+0x40>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <Fgets@plt>
test   %rax,%rax
je     12b9 <str_cli+0x109>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   10c0 <Writen@plt>
jmp    11f0 <str_cli+0x40>
add    $0x818,%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 0
define void @str_cli(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = call i32 @FD_ZERO(i32* %6)
br label %10
10: ; preds = %61, %2
%11 = load i32*, i32** %3
%12 = call i32 @fileno(i32* %11)
%13 = call i32 @FD_SET(i32 %12, i32* %6)
%14 = load i32, i32* %4
%15 = call i32 @FD_SET(i32 %14, i32* %6)
%16 = load i32*, i32** %3
%17 = call i32 @fileno(i32* %16)
%18 = load i32, i32* %4
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %10
%21 = load i32*, i32** %3
%22 = call i32 @fileno(i32* %21)
br label %25
23: ; preds = %10
%24 = load i32, i32* %4
br label %25
25: ; preds = %23, %20
%26 = phi i32 [ %22, %20 ], [ %24, %23 ]
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = call i32 @Select(i32 %28, i32* %6, i32* null, i32* null, i32* null)
%30 = load i32, i32* %4
%31 = call i64 @FD_ISSET(i32 %30, i32* %6)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %44
33: ; preds = %25
%34 = load i32, i32* %4
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%36 = call i64 @Readline(i32 %34, i8* %35, i32 1024)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @err_quit(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%42 = load i32, i32* @stdout
%43 = call i32 @Fputs(i8* %41, i32 %42)
br label %44
44: ; preds = %40, %25
%45 = load i32*, i32** %3
%46 = call i32 @fileno(i32* %45)
%47 = call i64 @FD_ISSET(i32 %46, i32* %6)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %61
49: ; preds = %44
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%51 = load i32*, i32** %3
%52 = call i32* @Fgets(i8* %50, i32 1024, i32* %51)
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %55
54: ; preds = %49
ret void
55: ; preds = %49
%56 = load i32, i32* %4
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%59 = call i32 @strlen(i8* %58)
%60 = call i32 @Writen(i32 %56, i8* %57, i32 %59)
br label %61
61: ; preds = %55, %44
br label %10
}

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