#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 */
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ bufsize;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ connect(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void dg_cli(FILE *fp, int sockfd, struct sockaddr *addr, socklen_t len) {
  char sndline[4096] = {0};
  char rcvline[4096 + 1] = {0};
  connect(sockfd, addr, len);
  int bufsize = 220 * 1024;
  setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize));
  while (fgets(sndline, 4096, fp) != NULL) {
    write(sockfd, sndline, strlen(sndline));
    int n = read(sockfd, rcvline, 4096);
    rcvline[n] = 0;
    printf("server answer:\n");
    fputs(rcvline, stdout);
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<dg_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1080 <memset@plt>
lea    -0x2030(%rbp),%rdi
xor    %esi,%esi
mov    $0x1001,%edx
call   1080 <memset@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10b0 <connect@plt>
movl   $0x37000,-0x2034(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
lea    -0x2034(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1000,%esi
call   10a0 <fgets@plt>
cmp    $0x0,%rax
je     12c0 <dg_cli+0x130>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2044(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x2040(%rbp)
lea    -0x1020(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2044(%rbp),%edi
mov    -0x2040(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
mov    %eax,-0x2038(%rbp)
movslq -0x2038(%rbp),%rax
movb   $0x0,-0x2030(%rbp,%rax,1)
lea    0xd6b(%rip),%rdi
call   1060 <printf@plt>
lea    -0x2030(%rbp),%rdi
mov    0x2d28(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
lea    0xd58(%rip),%rdi
call   1060 <printf@plt>
jmp    120f <dg_cli+0x7f>
add    $0x2050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dg_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2028,%rsp
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x1020(%rsp),%r15
mov    $0x1000,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0x1001,%edx
xor    %esi,%esi
call   1090 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   10c0 <connect@plt>
movl   $0x37000,0xc(%rsp)
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %r14,%rdx
call   10b0 <fgets@plt>
test   %rax,%rax
je     12ad <dg_cli+0x10d>
lea    0x1020(%rsp),%rbx
lea    0x10(%rsp),%r15
lea    0xdba(%rip),%r12
mov    0x2d83(%rip),%r13
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <write@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1000,%edx
call   10a0 <read@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r12,%rdi
call   1040 <puts@plt>
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1080 <fputs@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r14,%rdx
call   10b0 <fgets@plt>
test   %rax,%rax
jne    1250 <dg_cli+0xb0>
add    $0x2028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@.str = [16 x i8] c"server answer:\0A\00"
@stdout = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define void @dg_cli(i32* %0, i32 %1, %struct.sockaddr* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca %struct.sockaddr*
%8 = alloca i32
%9 = alloca [4096 x i8]
%10 = alloca [4097 x i8]
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store %struct.sockaddr* %2, %struct.sockaddr** %7
store i32 %3, i32* %8
%13 = bitcast [4096 x i8]* %9 to i8*
%14 = bitcast [4097 x i8]* %10 to i8*
%15 = load i32, i32* %6
%16 = load %struct.sockaddr*, %struct.sockaddr** %7
%17 = load i32, i32* %8
%18 = call i32 @connect(i32 %15, %struct.sockaddr* %16, i32 %17)
store i32 225280, i32* %11
%19 = load i32, i32* %6
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_RCVBUF
%22 = call i32 @setsockopt(i32 %19, i32 %20, i32 %21, i32* %11, i32 4)
br label %23
23: ; preds = %28, %4
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%25 = load i32*, i32** %5
%26 = call i32* @fgets(i8* %24, i32 4096, i32* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %45
28: ; preds = %23
%29 = load i32, i32* %6
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @write(i32 %29, i8* %30, i32 %32)
%34 = load i32, i32* %6
%35 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%36 = call i32 @read(i32 %34, i8* %35, i32 4096)
store i32 %36, i32* %12
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 %38
store i8 0, i8* %39
%40 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%41 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%42 = load i32, i32* @stdout
%43 = call i32 @fputs(i8* %41, i32 %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %23
45: ; preds = %23
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@stdout = global i32 0
@str = [15 x i8] c"server answer:\00"
define void @dg_cli(i32* nocapture %0, i32 %1, %struct.sockaddr* %2, i32 %3) {
%5 = alloca [4096 x i8]
%6 = alloca [4097 x i8]
%7 = alloca i32
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 0
%10 = tail call i32 @connect(i32 %1, %struct.sockaddr* %2, i32 %3)
%11 = bitcast i32* %7 to i8*
store i32 225280, i32* %7
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_RCVBUF
%14 = call i32 @setsockopt(i32 %1, i32 %12, i32 %13, i32* %7, i32 4)
%15 = call i32* @fgets(i8* %8, i32 4096, i32* %0)
%16 = icmp eq i32* %15, null
br i1 %16, label %29, label %17
17: ; preds = %4, %17
%18 = call i32 @strlen(i8* %8)
%19 = call i32 @write(i32 %1, i8* %8, i32 %18)
%20 = call i32 @read(i32 %1, i8* %9, i32 4096)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%24 = load i32, i32* @stdout
%25 = call i32 @fputs(i8* %9, i32 %24)
%26 = call i32 @putchar(i32 10)
%27 = call i32* @fgets(i8* %8, i32 4096, i32* %0)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %17
29: ; preds = %17, %4
ret void
}