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

/* Variables and functions */
int STDIN_FILENO;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ print(char *, size_t);
size_t read(int, char *, int);
size_t strlen(char *);
int /*<<< orphan*/ write(int, char *, size_t);
void str_cli(FILE *fp, int sockfd) {
  char sendline[100];
  char recvline[100];
  while (fgets(sendline, 100, fp) != NULL) {
    size_t len = strlen(sendline);
    if (len == 1)
      break;
    print(sendline, len);
    write(sockfd, sendline, len);
    ssize_t n = read(sockfd, recvline, 100);
    print(recvline, n);
    write(STDIN_FILENO, recvline, n);
  }
}


x86 assembly (clang, -O0):
<str_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1213 <str_cli+0xc3>
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0xe8(%rbp)
cmpq   $0x1,-0xe8(%rbp)
01
jne    11a1 <str_cli+0x51>
jmp    1213 <str_cli+0xc3>
lea    -0x70(%rbp),%rdi
mov    -0xe8(%rbp),%rsi
call   1050 <print@plt>
mov    -0xc(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    -0xe8(%rbp),%rdx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0x64,%edx
call   1060 <read@plt>
mov    %rax,-0xf0(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0xf0(%rbp),%rsi
call   1050 <print@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    -0xe0(%rbp),%rsi
mov    -0xf0(%rbp),%rdx
call   1030 <write@plt>
jmp    1162 <str_cli+0x12>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %esi,%r12d
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11fc <str_cli+0xac>
mov    %rsp,%rbx
lea    0x70(%rsp),%r15
mov    0x2e51(%rip),%r13
nop
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%rax
je     11fc <str_cli+0xac>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <print@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <write@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x64,%edx
call   1060 <read@plt>
mov    %rax,%rbp
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <print@plt>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1030 <write@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1190 <str_cli+0x40>
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
define void @str_cli(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
%7 = alloca i64
%8 = alloca i64
store i32* %0, i32** %3
store i32 %1, i32* %4
br label %9
9: ; preds = %20, %2
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%11 = load i32*, i32** %3
%12 = call i32* @fgets(i8* %10, i32 100, i32* %11)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %38
14: ; preds = %9
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %7
%17 = load i64, i64* %7
%18 = icmp eq i64 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %14
br label %38
20: ; preds = %14
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%22 = load i64, i64* %7
%23 = call i32 @print(i8* %21, i64 %22)
%24 = load i32, i32* %4
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%26 = load i64, i64* %7
%27 = call i32 @write(i32 %24, i8* %25, i64 %26)
%28 = load i32, i32* %4
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%30 = call i64 @read(i32 %28, i8* %29, i32 100)
store i64 %30, i64* %8
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%32 = load i64, i64* %8
%33 = call i32 @print(i8* %31, i64 %32)
%34 = load i32, i32* @STDIN_FILENO
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%36 = load i64, i64* %8
%37 = call i32 @write(i32 %34, i8* %35, i64 %36)
br label %9
38: ; preds = %19, %9
ret void
}

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