#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ client_buf;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int main(void) {
  int cnt = -1;
  int sfd = -1;
  int len = -1;
  struct sockaddr_in ser_addr;
  char buf[128] = {0};
  char client_buf[128] = {0};
  sfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (0 > sfd) {
    perror("socket error:");
    goto _out;
  }
  ser_addr.sin_family = AF_INET;
  ser_addr.sin_port = htons(6666);
  ser_addr.sin_addr.s_addr = inet_addr("192.168.1.222");
  while (1) {
    len = sizeof(struct sockaddr);
    { fgets(client_buf, sizeof(client_buf), stdin); }
    cnt = sendto(sfd, client_buf, sizeof(client_buf), 0,
                 (struct sockaddr *)&ser_addr, len);
    if (0 > cnt) {
      perror("sendto error:");
      goto _out;
    }
    cnt =
        recvfrom(sfd, buf, sizeof(buf), 0, (struct sockaddr *)&ser_addr, &len);
    if (0 > cnt) {
      perror("received error:");
      goto _out;
    }
    printf("buf = %s\n", buf);
  }
  close(sfd);
  return 0;
_out:
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jle    1215 <main+0x85>
lea    0xdf5(%rip),%rdi
call   10a0 <perror@plt>
jmp    12f0 <main+0x160>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1a0a,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    0xdd9(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
movl   $0x4,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1070 <fgets@plt>
mov    -0xc(%rbp),%edi
lea    -0x120(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    -0x10(%rbp),%r9d
mov    $0x80,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jle    129b <main+0x10b>
lea    0xd8b(%rip),%rdi
call   10a0 <perror@plt>
jmp    12f0 <main+0x160>
mov    -0xc(%rbp),%edi
lea    -0xa0(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x80,%edx
xor    %ecx,%ecx
lea    -0x10(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jle    12d8 <main+0x148>
lea    0xd5c(%rip),%rdi
call   10a0 <perror@plt>
jmp    12f0 <main+0x160>
lea    -0xa0(%rbp),%rsi
lea    0xd54(%rip),%rdi
call   1040 <printf@plt>
jmp    123d <main+0xad>
mov    $0xffffffff,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
xorps  %xmm0,%xmm0
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)
mov    0x2ddf(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
jns    122c <main+0xac>
lea    0xdd9(%rip),%rdi
jmp    1331 <main+0x1b1>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x1a0a,%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xdc4(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x10(%rsp)
movl   $0x4,0xc(%rsp)
mov    0x2d7e(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x80,%esi
call   1060 <fgets@plt>
lea    0x10(%rsp),%r8
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1050 <sendto@plt>
test   %eax,%eax
js     1321 <main+0x1a1>
lea    0xa0(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0xd87(%rip),%r13
lea    0x20(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1080 <recvfrom@plt>
test   %eax,%eax
js     132a <main+0x1aa>
mov    %r13,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
movl   $0x4,0xc(%rsp)
mov    0x2ceb(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0x80,%esi
call   1060 <fgets@plt>
mov    0xc(%rsp),%r9d
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1050 <sendto@plt>
test   %eax,%eax
jns    12c0 <main+0x140>
lea    0xcf4(%rip),%rdi
jmp    1331 <main+0x1b1>
lea    0xcf9(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [14 x i8] c"socket error:\00"
@.str.1 = [14 x i8] c"192.168.1.222\00"
@stdin = global i32 0
@.str.2 = [14 x i8] c"sendto error:\00"
@.str.3 = [16 x i8] c"received error:\00"
@.str.4 = [10 x i8] c"buf = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca [128 x i8]
%7 = alloca [128 x i8]
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 -1, i32* %3
store i32 -1, i32* %4
%8 = bitcast [128 x i8]* %6 to i8*
%9 = bitcast [128 x i8]* %7 to i8*
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp sgt i32 0, %13
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %50
17: ; preds = %0
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 6666)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %20, i32* %21
%22 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
store i32 %22, i32* %24
br label %25
25: ; preds = %17, %47
store i32 4, i32* %4
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%27 = load i32, i32* @stdin
%28 = call i32 @fgets(i8* %26, i32 128, i32 %27)
%29 = load i32, i32* %3
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%31 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%32 = load i32, i32* %4
%33 = call i32 @sendto(i32 %29, i8* %30, i32 128, i32 0, %struct.sockaddr* %31, i32 %32)
store i32 %33, i32* %2
%34 = load i32, i32* %2
%35 = icmp sgt i32 0, %34
br i1 %35, label %36, label %38
36: ; preds = %25
%37 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %50
38: ; preds = %25
%39 = load i32, i32* %3
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%41 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%42 = call i32 @recvfrom(i32 %39, i8* %40, i32 128, i32 0, %struct.sockaddr* %41, i32* %4)
store i32 %42, i32* %2
%43 = load i32, i32* %2
%44 = icmp sgt i32 0, %43
br i1 %44, label %45, label %47
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %50
47: ; preds = %38
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%49 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %48)
br label %25
50: ; preds = %45, %36, %15
ret i32 -1
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [14 x i8] c"socket error:\00"
@.str.1 = [14 x i8] c"192.168.1.222\00"
@stdin = global i32 0
@.str.2 = [14 x i8] c"sendto error:\00"
@.str.3 = [16 x i8] c"received error:\00"
@.str.4 = [10 x i8] c"buf = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = bitcast i32* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %41
15: ; preds = %0
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 6666)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %18, i32* %19
%20 = tail call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %20, i32* %21
store i32 4, i32* %1
%22 = load i32, i32* @stdin
%23 = call i32 @fgets(i8* %8, i32 128, i32 %22)
%24 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%25 = call i32 @sendto(i32 %11, i8* %8, i32 128, i32 0, %struct.sockaddr* %24, i32 4)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %34, %15
%28 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %41
29: ; preds = %15, %34
%30 = call i32 @recvfrom(i32 %11, i8* %7, i32 128, i32 0, %struct.sockaddr* %24, i32* %1)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %41
34: ; preds = %29
%35 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %7)
store i32 4, i32* %1
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %8, i32 128, i32 %36)
%38 = load i32, i32* %1
%39 = call i32 @sendto(i32 %11, i8* %8, i32 128, i32 0, %struct.sockaddr* %24, i32 %38)
%40 = icmp slt i32 %39, 0
br i1 %40, label %27, label %29
41: ; preds = %32, %27, %13
ret i32 -1
}