#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 /*<<< orphan*/ printf(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void dg_cli(FILE *fp, int sockfd, struct sockaddr *addr, socklen_t len) {
  char sndline[4096] = {0};
  char rcvline[4096 + 1] = {0};
  while (fgets(sndline, 4096, fp) != NULL) {
    sendto(sockfd, sndline, 4096, 0, addr, len);
    int n = recvfrom(sockfd, rcvline, 4096, 0, NULL, NULL);
    rcvline[n] = 0;
    printf("server answer:\n");
    fputs(rcvline, stdout);
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<dg_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%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   1050 <memset@plt>
lea    -0x2030(%rbp),%rdi
xor    %esi,%esi
mov    $0x1001,%edx
call   1050 <memset@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1241 <dg_cli+0xe1>
mov    -0xc(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x18(%rbp),%r8
mov    -0x1c(%rbp),%r9d
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    -0xc(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1080 <recvfrom@plt>
mov    %eax,-0x2034(%rbp)
movslq -0x2034(%rbp),%rax
movb   $0x0,-0x2030(%rbp,%rax,1)
lea    0xdea(%rip),%rdi
call   1030 <printf@plt>
lea    -0x2030(%rbp),%rdi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
lea    0xdd7(%rip),%rdi
call   1030 <printf@plt>
jmp    119f <dg_cli+0x3f>
add    $0x2040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dg_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r12
lea    0x1010(%rsp),%rbx
mov    $0x1000,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %rsp,%rdi
mov    $0x1001,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1250 <dg_cli+0xe0>
lea    0x1010(%rsp),%r13
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r14d,%r9d
call   1070 <sendto@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <recvfrom@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
jne    11e0 <dg_cli+0x70>
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@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 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 0
%9 = call i32* @fgets(i8* %7, i32 4096, i32* %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %22, label %11
11: ; preds = %4, %11
%12 = call i32 @sendto(i32 %1, i8* %7, i32 4096, i32 0, %struct.sockaddr* %2, i32 %3)
%13 = call i32 @recvfrom(i32 %1, i8* %8, i32 4096, i32 0, i32* null, i32* null)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = call i32 @fputs(i8* %8, i32 %17)
%19 = call i32 @putchar(i32 10)
%20 = call i32* @fgets(i8* %7, i32 4096, i32* %0)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %11
22: ; preds = %11, %4
ret void
}