#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*/ sendline;
typedef int /*<<< orphan*/ recvline;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
void str_cli(FILE *fp, int sockfd) {
  char sendline[256] = {'\0'};
  char recvline[256] = {'\0'};
  while (NULL != fgets(sendline, sizeof(sendline), fp)) {
    if (write(sockfd, sendline, strlen(sendline)) < 0) {
      if (EINTR == errno) {
        continue;
      }
      perror("write");
      exit(EXIT_FAILURE);
    }
    bzero(recvline, sizeof(recvline));
    if (read(sockfd, recvline, sizeof(recvline)) < 0) {
      if (EINTR == errno) {
        continue;
      }
      perror("read");
      exit(EXIT_FAILURE);
    }
    fputs(recvline, stdout);
  }
}


x86 assembly (clang, -O0):
<str_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1080 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12e7 <str_cli+0x157>
mov    -0xc(%rbp),%eax
mov    %eax,-0x21c(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x218(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x21c(%rbp),%edi
mov    -0x218(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1265 <str_cli+0xd5>
mov    0x2d9d(%rip),%rax
mov    (%rax),%rax
mov    0x2da3(%rip),%rcx
cmp    (%rcx),%rax
jne    124b <str_cli+0xbb>
jmp    11c8 <str_cli+0x38>
lea    0xdae(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    -0x210(%rbp),%rdi
mov    $0x100,%esi
call   10a0 <bzero@plt>
mov    -0xc(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
jge    12cd <str_cli+0x13d>
mov    0x2d35(%rip),%rax
mov    (%rax),%rax
mov    0x2d3b(%rip),%rcx
cmp    (%rcx),%rax
jne    12b3 <str_cli+0x123>
jmp    11c8 <str_cli+0x38>
lea    0xd4c(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    -0x210(%rbp),%rdi
mov    0x2ced(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
jmp    11c8 <str_cli+0x38>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1343 <str_cli+0x1c3>
mov    %rsp,%rbx
mov    0x2d2d(%rip),%r12
mov    0x2d36(%rip),%r13
lea    0x100(%rsp),%r15
jmp    12e3 <str_cli+0x163>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%rax
cmp    0x0(%r13),%rax
jne    1355 <str_cli+0x1d5>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1343 <str_cli+0x1c3>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     12c0 <str_cli+0x140>
mov    %r15,%rdi
mov    $0x100,%esi
call   1090 <bzero@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
test   %rax,%rax
js     1330 <str_cli+0x1b0>
mov    0x2ca4(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1050 <fputs@plt>
jmp    12ce <str_cli+0x14e>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     12ce <str_cli+0x14e>
lea    0xcc5(%rip),%rdi
jmp    135c <str_cli+0x1dc>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xca4(%rip),%rdi
call   1080 <perror@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@EINTR = global i64 0
@errno = global i64 0
@.str = [6 x i8] c"write\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"read\00"
@stdout = global i32 0
define void @str_cli(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = bitcast [256 x i8]* %5 to i8*
%8 = bitcast [256 x i8]* %6 to i8*
br label %9
9: ; preds = %46, %41, %25, %2
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i32* @fgets(i8* %10, i32 256, i32* %11)
%13 = icmp ne i32* null, %12
br i1 %13, label %14, label %50
14: ; preds = %9
%15 = load i32, i32* %4
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = call i64 @write(i32 %15, i8* %16, i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %14
%22 = load i64, i64* @EINTR
%23 = load i64, i64* @errno
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
br label %9
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %14
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%32 = call i32 @bzero(i8* %31, i32 256)
%33 = load i32, i32* %4
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%35 = call i64 @read(i32 %33, i8* %34, i32 256)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %30
%38 = load i64, i64* @EINTR
%39 = load i64, i64* @errno
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %37
br label %9
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %30
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%48 = load i32, i32* @stdout
%49 = call i32 @fputs(i8* %47, i32 %48)
br label %9
50: ; preds = %9
ret void
}

LLVM IR (-O2):
@EINTR = global i64 0
@errno = global i64 0
@.str = [6 x i8] c"write\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"read\00"
@stdout = global i32 0
define void @str_cli(i32* nocapture %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32* @fgets(i8* %5, i32 256, i32* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %39, label %9
9: ; preds = %2, %36
%10 = call i32 @strlen(i8* %5)
%11 = call i64 @write(i32 %1, i8* %5, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = load i64, i64* @EINTR
%15 = load i64, i64* @errno
%16 = icmp eq i64 %14, %15
br i1 %16, label %36, label %17
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %9
%22 = call i32 @bzero(i8* %6, i32 256)
%23 = call i64 @read(i32 %1, i8* %6, i32 256)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = load i64, i64* @EINTR
%27 = load i64, i64* @errno
%28 = icmp eq i64 %26, %27
br i1 %28, label %36, label %29
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %21
%34 = load i32, i32* @stdout
%35 = call i32 @fputs(i8* %6, i32 %34)
br label %36
36: ; preds = %33, %13, %25
%37 = call i32* @fgets(i8* %5, i32 256, i32* %0)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %9
39: ; preds = %36, %2
ret void
}