#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ connect(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void dg_cli(FILE *fp, int sockfd, const struct sockaddr *psa, socklen_t slen) {
  int n;
  char s[80], r[81];
  connect(sockfd, (struct sockaddr *)psa, slen);
  while (fgets(s, 80, fp) != NULL) {
    write(sockfd, s, strlen(s));
    n = read(sockfd, r, 80);
    r[n] = 0;
    fputs(r, stdout);
  }
}


x86 assembly (clang, -O0):
<dg_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <connect@plt>
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x50,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1212 <dg_cli+0xb2>
mov    -0xc(%rbp),%eax
mov    %eax,-0xdc(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xdc(%rbp),%edi
mov    -0xd8(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    $0x50,%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
movb   $0x0,-0xd0(%rbp,%rax,1)
lea    -0xd0(%rbp),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
jmp    1188 <dg_cli+0x28>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dg_cli>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb0,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%edi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1080 <connect@plt>
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11fb <dg_cli+0x9b>
mov    %rsp,%r15
lea    0x50(%rsp),%r12
mov    0x2e3b(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x50,%edx
call   1060 <read@plt>
cltq
movb   $0x0,0x50(%rsp,%rax,1)
mov    0x0(%r13),%esi
mov    %r12,%rdi
call   1050 <fputs@plt>
mov    %r15,%rdi
mov    $0x50,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    11b0 <dg_cli+0x50>
add    $0xb0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@stdout = global i32 0
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 i32
%10 = alloca [80 x i8]
%11 = alloca [81 x i8]
store i32* %0, i32** %5
store i32 %1, i32* %6
store %struct.sockaddr* %2, %struct.sockaddr** %7
store i32 %3, i32* %8
%12 = load i32, i32* %6
%13 = load %struct.sockaddr*, %struct.sockaddr** %7
%14 = load i32, i32* %8
%15 = call i32 @connect(i32 %12, %struct.sockaddr* %13, i32 %14)
br label %16
16: ; preds = %21, %4
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%18 = load i32*, i32** %5
%19 = call i32* @fgets(i8* %17, i32 80, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %36
21: ; preds = %16
%22 = load i32, i32* %6
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @write(i32 %22, i8* %23, i32 %25)
%27 = load i32, i32* %6
%28 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 80)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 %31
store i8 0, i8* %32
%33 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%34 = load i32, i32* @stdout
%35 = call i32 @fputs(i8* %33, i32 %34)
br label %16
36: ; preds = %16
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@stdout = global i32 0
define void @dg_cli(i32* nocapture %0, i32 %1, %struct.sockaddr* %2, i32 %3) {
%5 = alloca [80 x i8]
%6 = alloca [81 x i8]
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%9 = tail call i32 @connect(i32 %1, %struct.sockaddr* %2, i32 %3)
%10 = call i32* @fgets(i8* %7, i32 80, i32* %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %22, label %12
12: ; preds = %4, %12
%13 = call i32 @strlen(i8* %7)
%14 = call i32 @write(i32 %1, i8* %7, i32 %13)
%15 = call i32 @read(i32 %1, i8* %8, i32 80)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 %16
store i8 0, i8* %17
%18 = load i32, i32* @stdout
%19 = call i32 @fputs(i8* %8, i32 %18)
%20 = call i32* @fgets(i8* %7, i32 80, i32* %0)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %12
22: ; preds = %12, %4
ret void
}