#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
void dg_cli(FILE *fp, int sockfd, struct sockaddr *psa, socklen_t slen) {
  int n;
  char s[80], r[80];
  while (fgets(s, 80, fp) != NULL) {
    sendto(sockfd, s, strlen(s), 0, psa, slen);
    n = recvfrom(sockfd, r, 80, 0, NULL, NULL);
    r[n] = 0;
    fputs(r, stdout);
  }
}


x86 assembly (clang, -O0):
<dg_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1207 <dg_cli+0xb7>
mov    -0xc(%rbp),%eax
mov    %eax,-0xcc(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xcc(%rbp),%edi
mov    -0xc8(%rbp),%rsi
mov    %eax,%edx
mov    -0x18(%rbp),%r8
mov    -0x1c(%rbp),%r9d
xor    %ecx,%ecx
call   1050 <sendto@plt>
mov    -0xc(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1070 <recvfrom@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
movb   $0x0,-0xc0(%rbp,%rax,1)
lea    -0xc0(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
jmp    1169 <dg_cli+0x19>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dg_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r12
lea    0x50(%rsp),%rdi
mov    $0x50,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11ef <dg_cli+0x9f>
lea    0x50(%rsp),%rbx
mov    %rsp,%r13
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r14d,%r9d
call   1050 <sendto@plt>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1070 <recvfrom@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1040 <fputs@plt>
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1190 <dg_cli+0x40>
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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 [80 x i8]
store i32* %0, i32** %5
store i32 %1, i32* %6
store %struct.sockaddr* %2, %struct.sockaddr** %7
store i32 %3, i32* %8
br label %12
12: ; preds = %17, %4
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%14 = load i32*, i32** %5
%15 = call i32* @fgets(i8* %13, i32 80, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %34
17: ; preds = %12
%18 = load i32, i32* %6
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = load %struct.sockaddr*, %struct.sockaddr** %7
%23 = load i32, i32* %8
%24 = call i32 @sendto(i32 %18, i8* %19, i32 %21, i32 0, %struct.sockaddr* %22, i32 %23)
%25 = load i32, i32* %6
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%27 = call i32 @recvfrom(i32 %25, i8* %26, i32 80, i32 0, i32* null, i32* null)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%32 = load i32, i32* @stdout
%33 = call i32 @fputs(i8* %31, i32 %32)
br label %12
34: ; preds = %12
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 [80 x i8]
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%9 = call i32* @fgets(i8* %7, i32 80, i32* %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %21, label %11
11: ; preds = %4, %11
%12 = call i32 @strlen(i8* %7)
%13 = call i32 @sendto(i32 %1, i8* %7, i32 %12, i32 0, %struct.sockaddr* %2, i32 %3)
%14 = call i32 @recvfrom(i32 %1, i8* %8, i32 80, i32 0, i32* null, i32* null)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 %15
store i8 0, i8* %16
%17 = load i32, i32* @stdout
%18 = call i32 @fputs(i8* %8, i32 %17)
%19 = call i32* @fgets(i8* %7, i32 80, i32* %0)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %11
21: ; preds = %11, %4
ret void
}