#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*/);
int /*<<< orphan*/ printf(char *);
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[100], recvline[100];
  while (fgets(sendline, 100, fp) != NULL) {
    write(sockfd, sendline, strlen(sendline));
    if (read(sockfd, recvline, 100) == 0) {
      printf("server terminated\n");
    }
    fputs(recvline, stdout);
  }
}


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   1080 <fgets@plt>
cmp    $0x0,%rax
je     1203 <str_cli+0xa3>
mov    -0xc(%rbp),%eax
mov    %eax,-0xec(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xec(%rbp),%edi
mov    -0xe8(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0x64,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
jne    11e9 <str_cli+0x89>
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
lea    -0xe0(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
jmp    1172 <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,%ebx
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1202 <str_cli+0xa2>
mov    %rsp,%r15
lea    0x70(%rsp),%r12
lea    0xe66(%rip),%r13
mov    0x2e3f(%rip),%rbp
jmp    11d0 <str_cli+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%rbp),%esi
mov    %r12,%rdi
call   1060 <fputs@plt>
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1202 <str_cli+0xa2>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
test   %rax,%rax
jne    11b0 <str_cli+0x50>
mov    %r13,%rdi
call   1030 <puts@plt>
jmp    11b0 <str_cli+0x50>
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"server terminated\0A\00"
@stdout = 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]
store i32* %0, i32** %3
store i32 %1, i32* %4
br label %7
7: ; preds = %24, %2
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%9 = load i32*, i32** %3
%10 = call i32* @fgets(i8* %8, i32 100, 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 [100 x i8], [100 x i8]* %5, i64 0, i64 0
%15 = getelementptr inbounds [100 x i8], [100 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 [100 x i8], [100 x i8]* %6, i64 0, i64 0
%20 = call i64 @read(i32 %18, i8* %19, i32 100)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %12
%25 = getelementptr inbounds [100 x i8], [100 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):
@stdout = global i32 0
@str = [18 x i8] c"server terminated\00"
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, %16
%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 100)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 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 100, i32* %0)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %9
21: ; preds = %16, %2
ret void
}