#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void str_cli(FILE *fp, int sockfd) {
  char sendline[1024], recvline[1024];
  while (fgets(sendline, 1024, fp) != NULL) {
    write(sockfd, sendline, strlen(sendline));
    if (read(sockfd, recvline, 1024) <= 0)
      break;
    fputs(recvline, stdout);
  }
}


x86 assembly (clang, -O0):
<str_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     11f5 <str_cli+0xa5>
mov    -0xc(%rbp),%eax
mov    %eax,-0x81c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x818(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x81c(%rbp),%edi
mov    -0x818(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jg     11db <str_cli+0x8b>
jmp    11f5 <str_cli+0xa5>
lea    -0x810(%rbp),%rdi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
jmp    1162 <str_cli+0x12>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cli>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11d9 <str_cli+0x89>
mov    %rsp,%r15
lea    0x400(%rsp),%r12
mov    0x2e54(%rip),%r13
nopl   0x0(%rax)
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
test   %rax,%rax
jle    11d9 <str_cli+0x89>
mov    0x0(%r13),%esi
mov    %r12,%rdi
call   1050 <fputs@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1190 <str_cli+0x40>
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32 0
define void @str_cli(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
br label %7
7: ; preds = %23, %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = load i32*, i32** %3
%10 = call i32* @fgets(i8* %8, i32 1024, i32* %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %27
12: ; preds = %7
%13 = load i32, i32* %4
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @write(i32 %13, i8* %14, i32 %16)
%18 = load i32, i32* %4
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = call i64 @read(i32 %18, i8* %19, i32 1024)
%21 = icmp sle i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %12
br label %27
23: ; preds = %12
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* @stdout
%26 = call i32 @fputs(i8* %24, i32 %25)
br label %7
27: ; preds = %22, %7
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
define void @str_cli(i32* nocapture %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32* @fgets(i8* %5, i32 1024, i32* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %19, label %9
9: ; preds = %2, %14
%10 = call i32 @strlen(i8* %5)
%11 = call i32 @write(i32 %1, i8* %5, i32 %10)
%12 = call i64 @read(i32 %1, i8* %6, i32 1024)
%13 = icmp slt i64 %12, 1
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = load i32, i32* @stdout
%16 = call i32 @fputs(i8* %6, i32 %15)
%17 = call i32* @fgets(i8* %5, i32 1024, i32* %0)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %9
19: ; preds = %14, %9, %2
ret void
}