#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_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ si_other;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
             int /*<<< orphan*/ *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(void) {
  struct sockaddr_in si_other;
  int s, i, slen = sizeof(si_other);
  char buf[(512)];
  char message[(512)];
  if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
    die("socket");
  }
  memset((char *)&si_other, 0, sizeof(si_other));
  si_other.sin_family = AF_INET;
  si_other.sin_port = htons((8888));
  if (inet_aton("127.0.0.1", &si_other.sin_addr) == 0) {
    fprintf(stderr, "inet_aton() failed\n");
    exit(1);
  }
  while (1) {
    printf("Enter message : ");
    gets(message);
    if (sendto(s, message, strlen(message), 0, (struct sockaddr *)&si_other,
               slen) == -1) {
      die("sendto()");
    }
    memset(buf, '\0', (512));
    if (recvfrom(s, buf, (512), 0, (struct sockaddr *)&si_other,
                 (socklen_t *)&slen) == -1) {
      die("recvfrom()");
    }
    puts(buf);
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc,-0x1c(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1221 <main+0x51>
lea    0xde4(%rip),%rdi
call   10d0 <die@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rsi
lea    0xdb2(%rip),%rdi
call   10b0 <inet_aton@plt>
cmp    $0x0,%rax
jne    1283 <main+0xb3>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    1288 <main+0xb8>
lea    0xd96(%rip),%rdi
call   1060 <printf@plt>
lea    -0x420(%rbp),%rdi
call   10a0 <gets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x42c(%rbp),%edi
mov    -0x428(%rbp),%rsi
mov    %eax,%edx
lea    -0x10(%rbp),%r8
mov    -0x1c(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
jne    12f6 <main+0x126>
lea    0xd45(%rip),%rdi
call   10d0 <die@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
lea    -0x10(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    133c <main+0x16c>
lea    0xd08(%rip),%rdi
call   10d0 <die@plt>
lea    -0x220(%rbp),%rdi
call   1030 <puts@plt>
jmp    1288 <main+0xb8>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
movl   $0xc,0xc(%rsp)
mov    0x2df8(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    121e <main+0x4e>
lea    0xde7(%rip),%rdi
call   10d0 <die@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xdb9(%rip),%rdi
mov    %rbx,%rsi
call   10b0 <inet_aton@plt>
test   %rax,%rax
je     1305 <main+0x135>
lea    0xdbf(%rip),%r14
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r15
lea    0x220(%rsp),%rbp
lea    0xc(%rsp),%r12
jmp    1288 <main+0xb8>
nop
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   10a0 <gets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    0xc(%rsp),%r9d
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
jne    12c8 <main+0xf8>
lea    0xd73(%rip),%rdi
call   10d0 <die@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    1280 <main+0xb0>
lea    0xd44(%rip),%rdi
call   10d0 <die@plt>
jmp    1280 <main+0xb0>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
lea    0xcfc(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"inet_aton() failed\0A\00"
@.str.3 = [17 x i8] c"Enter message : \00"
@.str.4 = [9 x i8] c"sendto()\00"
@.str.5 = [11 x i8] c"recvfrom()\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
store i32 0, i32* %1
store i32 12, i32* %5
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = load i32, i32* @IPPROTO_UDP
%11 = call i32 @socket(i32 %8, i32 %9, i32 %10)
store i32 %11, i32* %3
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = bitcast %struct.sockaddr_in* %2 to i8*
%17 = call i32 @memset(i8* %16, i8 signext 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 8888)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%23 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %15
br label %30
30: ; preds = %29, %54
%31 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%33 = call i32 @gets(i8* %32)
%34 = load i32, i32* %3
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%39 = load i32, i32* %5
%40 = call i32 @sendto(i32 %34, i8* %35, i32 %37, i32 0, %struct.sockaddr* %38, i32 %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %30
%43 = call i32 @die(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %30
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%46 = call i32 @memset(i8* %45, i8 signext 0, i32 512)
%47 = load i32, i32* %3
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%49 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%50 = call i32 @recvfrom(i32 %47, i8* %48, i32 512, i32 0, %struct.sockaddr* %49, i32* %5)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %44
%53 = call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %52, %44
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%56 = call i32 @puts(i8* %55)
br label %30
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.2 = [20 x i8] c"inet_aton() failed\0A\00"
@.str.3 = [17 x i8] c"Enter message : \00"
@.str.4 = [9 x i8] c"sendto()\00"
@.str.5 = [11 x i8] c"recvfrom()\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast i32* %2 to i8*
store i32 12, i32* %2
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = load i32, i32* @IPPROTO_UDP
%12 = tail call i32 @socket(i32 %9, i32 %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = tail call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %0
%17 = call i32 @memset(i8* %5, i8 signext 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 8888)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%23 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %16
%26 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %31
27: ; preds = %16
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25, %46
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @gets(i8* %8)
%34 = call i32 @strlen(i8* %8)
%35 = load i32, i32* %2
%36 = call i32 @sendto(i32 %12, i8* %8, i32 %34, i32 0, %struct.sockaddr* %26, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 @die(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %31
%41 = call i32 @memset(i8* %7, i8 signext 0, i32 512)
%42 = call i32 @recvfrom(i32 %12, i8* %7, i32 512, i32 0, %struct.sockaddr* %26, i32* %2)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
%47 = call i32 @puts(i8* %7)
br label %31
}