#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);
int /*<<< orphan*/ err_quit(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int strlen(char *);
void str_cli(FILE *fp, int fd) {
  char sendline[1024], recvline[1024];
  while (Fgets(sendline, 1024, fp) != NULL) {
    Writen(fd, sendline, 1);
    sleep(1);
    Writen(fd, sendline + 1, strlen(sendline) - 1);
    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     1241 <str_cli+0xd1>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x1,%edx
call   1080 <Writen@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x81c(%rbp)
lea    -0x410(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x818(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x81c(%rbp),%edi
mov    -0x818(%rbp),%rsi
mov    %eax,%edx
sub    $0x1,%edx
call   1080 <Writen@plt>
mov    -0xc(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
call   1070 <Readline@plt>
cmp    $0x0,%rax
jne    1227 <str_cli+0xb7>
lea    0xdde(%rip),%rdi
call   1060 <err_quit@plt>
lea    -0x810(%rbp),%rdi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
call   1030 <Fputs@plt>
jmp    1182 <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     1230 <str_cli+0xc0>
lea    0x1(%rsp),%r15
mov    %rsp,%r12
lea    0x400(%rsp),%r13
mov    0x2e2a(%rip),%rbp
jmp    11e0 <str_cli+0x70>
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%esi
mov    %r13,%rdi
call   1030 <Fputs@plt>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <Fgets@plt>
test   %rax,%rax
je     1230 <str_cli+0xc0>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1080 <Writen@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    -0x1(%rax),%edx
mov    %ebx,%edi
mov    %r15,%rsi
call   1080 <Writen@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x400,%edx
call   1070 <Readline@plt>
test   %rax,%rax
jne    11c0 <str_cli+0x50>
lea    0xdd7(%rip),%rdi
call   1060 <err_quit@plt>
jmp    11c0 <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 = %30, %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 %34
12: ; preds = %7
%13 = load i32, i32* %4
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = call i32 @Writen(i32 %13, i8* %14, i32 1)
%16 = call i32 @sleep(i32 1)
%17 = load i32, i32* %4
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %21, 1
%23 = call i32 @Writen(i32 %17, i8* %19, i32 %22)
%24 = load i32, i32* %4
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i64 @Readline(i32 %24, i8* %25, i32 1024)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %12
%29 = call i32 @err_quit(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %12
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%32 = load i32, i32* @stdout
%33 = call i32 @Fputs(i8* %31, i32 %32)
br label %7
34: ; 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 %26, label %9
9: ; preds = %2
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1
br label %11
11: ; preds = %9, %21
%12 = call i32 @Writen(i32 %1, i8* %5, i32 1)
%13 = call i32 @sleep(i32 1)
%14 = call i32 @strlen(i8* %5)
%15 = add nsw i32 %14, -1
%16 = call i32 @Writen(i32 %1, i8* %10, i32 %15)
%17 = call i64 @Readline(i32 %1, i8* %6, i32 1024)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 @err_quit(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %11
%22 = load i32, i32* @stdout
%23 = call i32 @Fputs(i8* %6, i32 %22)
%24 = call i32* @Fgets(i8* %5, i32 1024, i32* %0)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %11
26: ; preds = %21, %2
ret void
}