#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__ Readline(int, char *, int);
int /*<<< orphan*/ Writen(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ err_quit(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
void str_cli(FILE *fp, int fd) {
  char sendline[1024], recvline[1024];
  while (Fgets(sendline, 1024, fp) != NULL) {
    Writen(fd, sendline, strlen(sendline));
    if (Readline(fd, recvline, 1024) == 0)
      err_quit("str_cli: server terminated prematurely");
    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   1050 <Fgets@plt>
cmp    $0x0,%rax
je     120c <str_cli+0xac>
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   1080 <Writen@plt>
mov    -0xc(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
call   1070 <Readline@plt>
cmp    $0x0,%rax
jne    11f2 <str_cli+0x92>
lea    0xe13(%rip),%rdi
call   1060 <err_quit@plt>
lea    -0x810(%rbp),%rdi
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
call   1030 <Fputs@plt>
jmp    1172 <str_cli+0x12>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <Fgets@plt>
test   %rax,%rax
je     1202 <str_cli+0xa2>
mov    %rsp,%r15
lea    0x400(%rsp),%r12
lea    0xe63(%rip),%r13
mov    0x2e3c(%rip),%rbp
jmp    11d0 <str_cli+0x70>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%rbp),%esi
mov    %r12,%rdi
call   1030 <Fputs@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <Fgets@plt>
test   %rax,%rax
je     1202 <str_cli+0xa2>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1080 <Writen@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1070 <Readline@plt>
test   %rax,%rax
jne    11b0 <str_cli+0x50>
mov    %r13,%rdi
call   1060 <err_quit@plt>
jmp    11b0 <str_cli+0x50>
add    $0x808,%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 [1024 x i8]
%6 = alloca [1024 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
br label %7
7: ; preds = %24, %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 %28
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 @Writen(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 @Readline(i32 %18, i8* %19, i32 1024)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = call i32 @err_quit(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %12
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = load i32, i32* @stdout
%27 = call i32 @Fputs(i8* %25, i32 %26)
br label %7
28: ; preds = %7
ret void
}

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 [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 %21, label %9
9: ; preds = %2, %16
%10 = call i32 @strlen(i8* %5)
%11 = call i32 @Writen(i32 %1, i8* %5, i32 %10)
%12 = call i64 @Readline(i32 %1, i8* %6, i32 1024)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @err_quit(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
%17 = load i32, i32* @stdout
%18 = call i32 @Fputs(i8* %6, i32 %17)
%19 = call i32* @Fgets(i8* %5, i32 1024, i32* %0)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %9
21: ; preds = %16, %2
ret void
}