#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, 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, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(void) {
  struct sockaddr_in si_other;
  int s, slen = sizeof(si_other), index;
  char buf[64];
  char message[64];
  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(1999);
  if (inet_aton("192.168.1.122", &si_other.sin_addr) == 0) {
    fprintf(stderr, "inet_aton() failed\n");
    exit(1);
  }
  while (1) {
    printf("Enter message : ");
    fgets(message, (64 - 2), stdin);
    index = strlen(message);
    message[index++] = '\n';
    message[index++] = '\0';
    if (sendto(s, message, strlen(message), 0, (struct sockaddr *)&si_other,
               slen) == -1) {
      die("sendto()");
    }
    memset(buf, '\0', 64);
    if (recvfrom(s, buf, 64, 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    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc,-0x18(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    0x2db6(%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    $0x7cf,%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    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    1288 <main+0xb8>
lea    0xd9a(%rip),%rdi
call   1060 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2d3e(%rip),%rax
mov    (%rax),%edx
mov    $0x3e,%esi
call   1090 <fgets@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
cltq
movb   $0xa,-0xa0(%rbp,%rax,1)
0a
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
cltq
movb   $0x0,-0xa0(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
mov    %eax,-0xac(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
lea    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
jne    133d <main+0x16d>
lea    0xd02(%rip),%rdi
call   10d0 <die@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
lea    -0x10(%rbp),%r8
mov    $0x40,%edx
xor    %ecx,%ecx
lea    -0x18(%rbp),%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    137d <main+0x1ad>
lea    0xccb(%rip),%rdi
call   10d0 <die@plt>
lea    -0x60(%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    $0xa8,%rsp
movl   $0xc,0xc(%rsp)
mov    0x2df8(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
mov    0x2db5(%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    $0x7cf,%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     1328 <main+0x158>
lea    0xdc3(%rip),%r14
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r15
lea    0x60(%rsp),%rbp
lea    0xc(%rsp),%r12
jmp    1288 <main+0xb8>
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1060 <printf@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x3e,%esi
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movw   $0xa,0x20(%rsp,%rax,1)
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    12e7 <main+0x117>
lea    0xd58(%rip),%rdi
call   10d0 <die@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    1280 <main+0xb0>
lea    0xd25(%rip),%rdi
call   10d0 <die@plt>
jmp    1280 <main+0xb0>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
lea    0xcdd(%rip),%rsi
call   10a0 <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 = [14 x i8] c"192.168.1.122\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"
@stdin = global i32 0
@.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 [64 x i8]
%7 = alloca [64 x i8]
store i32 0, i32* %1
store i32 12, i32* %4
%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 1999)
%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 ([14 x i8], [14 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, %65
%31 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%33 = load i32, i32* @stdin
%34 = call i32 @fgets(i8* %32, i32 62, i32 %33)
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
store i32 %36, i32* %5
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %39
store i8 10, i8* %40
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %43
store i8 0, i8* %44
%45 = load i32, i32* %3
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%50 = load i32, i32* %4
%51 = call i32 @sendto(i32 %45, i8* %46, i32 %48, i32 0, %struct.sockaddr* %49, i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %30
%54 = call i32 @die(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %53, %30
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%57 = call i32 @memset(i8* %56, i8 signext 0, i32 64)
%58 = load i32, i32* %3
%59 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%60 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%61 = call i32 @recvfrom(i32 %58, i8* %59, i32 64, i32 0, %struct.sockaddr* %60, i32* %4)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %65
63: ; preds = %55
%64 = call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %65
65: ; preds = %63, %55
%66 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%67 = call i32 @puts(i8* %66)
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 = [14 x i8] c"192.168.1.122\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"
@stdin = global i32 0
@.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 [64 x i8]
%4 = alloca [64 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast i32* %2 to i8*
store i32 12, i32* %2
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 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 1999)
%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 ([14 x i8], [14 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, %53
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @stdin
%34 = call i32 @fgets(i8* %8, i32 62, i32 %33)
%35 = call i32 @strlen(i8* %8)
%36 = add nsw i32 %35, 1
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %37
store i8 10, i8* %38
%39 = sext i32 %36 to i64
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %39
store i8 0, i8* %40
%41 = call i32 @strlen(i8* %8)
%42 = load i32, i32* %2
%43 = call i32 @sendto(i32 %12, i8* %8, i32 %41, i32 0, %struct.sockaddr* %26, i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %31
%46 = call i32 @die(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45, %31
%48 = call i32 @memset(i8* %7, i8 signext 0, i32 64)
%49 = call i32 @recvfrom(i32 %12, i8* %7, i32 64, i32 0, %struct.sockaddr* %26, i32* %2)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %51, %47
%54 = call i32 @puts(i8* %7)
br label %31
}