#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*/ exit(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
void str_cli(FILE *fp, int sockfd) {
  char buffer[4096];
  while (Fgets(buffer, 4096, fp) != NULL) {
    Writen(sockfd, buffer, strlen(buffer));
    if (Readline(sockfd, buffer, 4096) == 0) {
      printf("server terminated prematurely\n");
      exit(1);
    }
    Fputs(buffer, stdout);
  }
}


x86 assembly (clang, -O0):
<str_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1000,%esi
call   1060 <Fgets@plt>
cmp    $0x0,%rax
je     1226 <str_cli+0xb6>
mov    -0xc(%rbp),%eax
mov    %eax,-0x101c(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1018(%rbp)
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x101c(%rbp),%edi
mov    -0x1018(%rbp),%rsi
mov    %eax,%edx
call   1080 <Writen@plt>
mov    -0xc(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <Readline@plt>
cmp    $0x0,%rax
jne    120c <str_cli+0x9c>
lea    0xe03(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x1010(%rbp),%rdi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
call   1030 <Fputs@plt>
jmp    1182 <str_cli+0x12>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cli>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %r14,%rdx
call   1060 <Fgets@plt>
test   %rax,%rax
je     11f8 <str_cli+0x88>
mov    %rsp,%rbx
mov    0x2e3f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1080 <Writen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <Readline@plt>
test   %rax,%rax
je     1206 <str_cli+0x96>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1030 <Fputs@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r14,%rdx
call   1060 <Fgets@plt>
test   %rax,%rax
jne    11b0 <str_cli+0x40>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf3(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"server terminated prematurely\0A\00"
@stdout = global i32 0
define void @str_cli(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [4096 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
br label %6
6: ; preds = %24, %2
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%8 = load i32*, i32** %3
%9 = call i32* @Fgets(i8* %7, i32 4096, i32* %8)
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %28
11: ; preds = %6
%12 = load i32, i32* %4
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @Writen(i32 %12, i8* %13, i32 %15)
%17 = load i32, i32* %4
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%19 = call i64 @Readline(i32 %17, i8* %18, i32 4096)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %11
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%26 = load i32, i32* @stdout
%27 = call i32 @Fputs(i8* %25, i32 %26)
br label %6
28: ; preds = %6
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@str = [30 x i8] c"server terminated prematurely\00"
define void @str_cli(i32* %0, i32 %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i32* @Fgets(i8* %4, i32 4096, i32* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %20, label %7
7: ; preds = %2, %15
%8 = call i32 @strlen(i8* %4)
%9 = call i32 @Writen(i32 %1, i8* %4, i32 %8)
%10 = call i64 @Readline(i32 %1, i8* %4, i32 4096)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %7
%16 = load i32, i32* @stdout
%17 = call i32 @Fputs(i8* %4, i32 %16)
%18 = call i32* @Fgets(i8* %4, i32 4096, i32* %0)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %7
20: ; preds = %15, %2
ret void
}