#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*/ send_msg;
typedef int /*<<< orphan*/ recv_msg;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
void dg_cli(FILE *fp, int sockfd, struct sockaddr *pservaddr,
            socklen_t servlen) {
  int n;
  char recv_msg[256] = {'\0'};
  char send_msg[256] = {'\0'};
  while (NULL != fgets(send_msg, sizeof(send_msg), fp)) {
    n = sendto(sockfd, send_msg, strlen(send_msg), 0, pservaddr, servlen);
    if (n < 0) {
      if (EINTR == errno) {
        continue;
      }
      perror("sendto");
      close(sockfd);
      exit(EXIT_FAILURE);
    }
    bzero(recv_msg, sizeof(recv_msg));
    n = recvfrom(sockfd, recv_msg, sizeof(recv_msg), 0, NULL, NULL);
    if (n < 0) {
      if (EINTR == errno) {
        continue;
      }
      perror("recvfrom");
      close(sockfd);
      exit(EXIT_FAILURE);
    }
    printf("%s.\n", recv_msg);
  }
}


x86 assembly (clang, -O0):
<dg_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1080 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1326 <dg_cli+0x186>
mov    -0xc(%rbp),%eax
mov    %eax,-0x22c(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x228(%rbp)
lea    -0x220(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x22c(%rbp),%edi
mov    -0x228(%rbp),%rsi
mov    %eax,%edx
mov    -0x18(%rbp),%r8
mov    -0x1c(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1291 <dg_cli+0xf1>
mov    0x2d79(%rip),%rax
mov    (%rax),%rax
mov    0x2d7f(%rip),%rcx
cmp    (%rcx),%rax
jne    126f <dg_cli+0xcf>
jmp    11df <dg_cli+0x3f>
lea    0xd8a(%rip),%rdi
call   10a0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   10b0 <bzero@plt>
mov    -0xc(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1090 <recvfrom@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    130e <dg_cli+0x16e>
mov    0x2cfc(%rip),%rax
mov    (%rax),%rax
mov    0x2d02(%rip),%rcx
cmp    (%rcx),%rax
jne    12ec <dg_cli+0x14c>
jmp    11df <dg_cli+0x3f>
lea    0xd14(%rip),%rdi
call   10a0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x120(%rbp),%rsi
lea    0xcf4(%rip),%rdi
call   1040 <printf@plt>
jmp    11df <dg_cli+0x3f>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dg_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r12
xorps  %xmm0,%xmm0
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1373 <dg_cli+0x1e3>
mov    %rsp,%rbp
lea    0x100(%rsp),%r13
jmp    12f3 <dg_cli+0x163>
nopl   0x0(%rax)
mov    0x2d09(%rip),%rax
mov    (%rax),%rax
mov    0x2d0f(%rip),%rcx
cmp    (%rcx),%rax
jne    1385 <dg_cli+0x1f5>
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1373 <dg_cli+0x1e3>
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r14d,%r9d
call   1050 <sendto@plt>
test   %eax,%eax
js     12c0 <dg_cli+0x130>
mov    %r13,%rdi
mov    $0x100,%esi
call   10a0 <bzero@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1080 <recvfrom@plt>
test   %eax,%eax
js     1350 <dg_cli+0x1c0>
lea    0xcce(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
jmp    12da <dg_cli+0x14a>
nopl   0x0(%rax)
mov    0x2c79(%rip),%rax
mov    (%rax),%rax
mov    0x2c7f(%rip),%rcx
cmp    (%rcx),%rax
je     12da <dg_cli+0x14a>
lea    0xc96(%rip),%rdi
jmp    138c <dg_cli+0x1fc>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc74(%rip),%rdi
call   1090 <perror@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2c39(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@EINTR = global i64 0
@errno = global i64 0
@.str = [7 x i8] c"sendto\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"recvfrom\00"
@.str.2 = [5 x i8] c"%s.\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 i32
%10 = alloca [256 x i8]
%11 = alloca [256 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 = bitcast [256 x i8]* %10 to i8*
%13 = bitcast [256 x i8]* %11 to i8*
br label %14
14: ; preds = %59, %52, %33, %4
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i32* @fgets(i8* %15, i32 256, i32* %16)
%18 = icmp ne i32* null, %17
br i1 %18, label %19, label %62
19: ; preds = %14
%20 = load i32, i32* %6
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = load %struct.sockaddr*, %struct.sockaddr** %7
%25 = load i32, i32* %8
%26 = call i32 @sendto(i32 %20, i8* %21, i32 %23, i32 0, %struct.sockaddr* %24, i32 %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %19
%30 = load i64, i64* @EINTR
%31 = load i64, i64* @errno
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
br label %14
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %19
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%42 = call i32 @bzero(i8* %41, i32 256)
%43 = load i32, i32* %6
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%45 = call i32 @recvfrom(i32 %43, i8* %44, i32 256, i32 0, i32* null, i32* null)
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %59
48: ; preds = %40
%49 = load i64, i64* @EINTR
%50 = load i64, i64* @errno
%51 = icmp eq i64 %49, %50
br i1 %51, label %52, label %53
52: ; preds = %48
br label %14
53: ; preds = %48
%54 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%55 = load i32, i32* %6
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %40
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%61 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %60)
br label %14
62: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@EINTR = global i64 0
@errno = global i64 0
@.str = [7 x i8] c"sendto\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"recvfrom\00"
@.str.2 = [5 x i8] c"%s.\0A\00"
define void @dg_cli(i32* nocapture %0, i32 %1, %struct.sockaddr* %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = call i32* @fgets(i8* %8, i32 256, i32* %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %42, label %11
11: ; preds = %4, %39
%12 = call i32 @strlen(i8* %8)
%13 = call i32 @sendto(i32 %1, i8* %8, i32 %12, i32 0, %struct.sockaddr* %2, i32 %3)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load i64, i64* @EINTR
%17 = load i64, i64* @errno
%18 = icmp eq i64 %16, %17
br i1 %18, label %39, label %19
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @close(i32 %1)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %11
%25 = call i32 @bzero(i8* %7, i32 256)
%26 = call i32 @recvfrom(i32 %1, i8* %7, i32 256, i32 0, i32* null, i32* null)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load i64, i64* @EINTR
%30 = load i64, i64* @errno
%31 = icmp eq i64 %29, %30
br i1 %31, label %39, label %32
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @close(i32 %1)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %24
%38 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %39
39: ; preds = %37, %15, %28
%40 = call i32* @fgets(i8* %8, i32 256, i32* %0)
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %11
42: ; preds = %39, %4
ret void
}