#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*/ buf;
typedef int /*<<< orphan*/ ad;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int /*<<< orphan*/, char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int fd;
  struct sockaddr_in ad;
  char buf[102];
  int r;
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  ad.sin_family = AF_INET;
  ad.sin_port = htons(8888);
  ad.sin_addr.s_addr = inet_addr("192.168.137.3");
  while (1) {
    r = read(0, buf, sizeof(buf) - 1);
    if (r <= 0) {
      break;
    }
    buf[r] = 0;
    r = sendto(fd, buf, r, 0, (struct sockaddr *)&ad, sizeof(ad));
    bzero(buf, sizeof(buf));
    r = recv(fd, buf, sizeof(buf), 0);
    buf[r] = 0;
    printf("--->%s\n", buf);
    if (r == -1) {
      break;
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    0xe22(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
lea    -0x80(%rbp),%rsi
xor    %edi,%edi
mov    $0x65,%edx
call   1080 <read@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jg     120e <main+0x7e>
jmp    1298 <main+0x108>
movslq -0x84(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0x84(%rbp),%edx
lea    -0x18(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %eax,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
mov    $0x66,%esi
call   10a0 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x66,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x84(%rbp)
movslq -0x84(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xd92(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0xffffffff,-0x84(%rbp)
jne    1293 <main+0x103>
jmp    1298 <main+0x108>
jmp    11e6 <main+0x56>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    0x2e42(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r12d
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe2a(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,(%rsp)
lea    0x10(%rsp),%rbx
mov    %rsp,%r14
lea    0xe21(%rip),%r15
nopl   (%rax)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x65,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    1259 <main+0xc9>
mov    %eax,%ecx
movb   $0x0,0x10(%rsp,%rcx,1)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %rbx,%rdi
mov    $0x66,%esi
call   10a0 <bzero@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x66,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movslq %eax,%rbp
movb   $0x0,0x10(%rsp,%rbp,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
cmp    $0xffffffff,%ebp
jne    11f0 <main+0x60>
mov    %r12d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
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"192.168.137.3\00"
@.str.1 = [8 x i8] c"--->%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [102 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %2
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %9, i32* %10
%11 = call i32 @htons(i32 8888)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %11, i32* %12
%13 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
store i32 %13, i32* %15
br label %16
16: ; preds = %0, %44
%17 = getelementptr inbounds [102 x i8], [102 x i8]* %4, i64 0, i64 0
%18 = call i32 @read(i32 0, i8* %17, i32 101)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp sle i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
br label %45
22: ; preds = %16
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [102 x i8], [102 x i8]* %4, i64 0, i64 %24
store i8 0, i8* %25
%26 = load i32, i32* %2
%27 = getelementptr inbounds [102 x i8], [102 x i8]* %4, i64 0, i64 0
%28 = load i32, i32* %5
%29 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%30 = call i32 @sendto(i32 %26, i8* %27, i32 %28, i32 0, %struct.sockaddr* %29, i32 12)
store i32 %30, i32* %5
%31 = getelementptr inbounds [102 x i8], [102 x i8]* %4, i64 0, i64 0
%32 = call i32 @bzero(i8* %31, i32 102)
%33 = load i32, i32* %2
%34 = getelementptr inbounds [102 x i8], [102 x i8]* %4, i64 0, i64 0
%35 = call i32 @recv(i32 %33, i8* %34, i32 102, i32 0)
store i32 %35, i32* %5
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [102 x i8], [102 x i8]* %4, i64 0, i64 %37
store i8 0, i8* %38
%39 = getelementptr inbounds [102 x i8], [102 x i8]* %4, i64 0, i64 0
%40 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = load i32, i32* %5
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %44
43: ; preds = %22
br label %45
44: ; preds = %22
br label %16
45: ; preds = %43, %21
%46 = load i32, i32* %2
%47 = call i32 @close(i32 %46)
ret i32 0
}

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"192.168.137.3\00"
@.str.1 = [8 x i8] c"--->%s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [102 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = getelementptr inbounds [102 x i8], [102 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %8, i32* %9
%10 = tail call i32 @htons(i32 8888)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %10, i32* %11
%12 = tail call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %12, i32* %13
%14 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %15
15: ; preds = %18, %0
%16 = call i32 @read(i32 0, i8* %4, i32 101)
%17 = icmp slt i32 %16, 1
br i1 %17, label %28, label %18
18: ; preds = %15
%19 = zext i32 %16 to i64
%20 = getelementptr inbounds [102 x i8], [102 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i32 @sendto(i32 %7, i8* %4, i32 %16, i32 0, %struct.sockaddr* %14, i32 12)
%22 = call i32 @bzero(i8* %4, i32 102)
%23 = call i32 @recv(i32 %7, i8* %4, i32 102, i32 0)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [102 x i8], [102 x i8]* %2, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%27 = icmp eq i32 %23, -1
br i1 %27, label %28, label %15
28: ; preds = %18, %15
%29 = call i32 @close(i32 %7)
ret i32 0
}