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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int htonl(int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int, int);
int ntohl(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int sd, size, bits;
  int num = 0;
  struct sockaddr_in to;
  sd = socket(PF_INET, SOCK_DGRAM, 0);
  memset(&to, 0x00, size);
  to.sin_family = AF_INET;
  to.sin_port = htons((ushort)5000);
  inet_pton(PF_INET, "153.19.1.202", &to.sin_addr);
  size = sizeof(struct sockaddr_in);
  bind(sd, (struct sockaddr *)&to, size);
  printf("Enter a number:");
  scanf("%d", &num);
  num = htonl(num);
  sendto(sd, (char *)&num, sizeof(int), 0, (struct sockaddr *)&to, size);
  recvfrom(sd, (char *)&num, sizeof(int), 0, (struct sockaddr *)&to, &size);
  num = ntohl(num);
  printf("Server answered with: %d\n", num);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x10(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%edx
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1388,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
lea    0xdea(%rip),%rsi
call   1080 <inet_pton@plt>
movl   $0xc,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   10b0 <bind@plt>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdd7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x10(%rbp),%edi
call   1050 <htonl@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    -0x8(%rbp),%r9d
mov    $0x4,%edx
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x4,%edx
xor    %ecx,%ecx
lea    -0x8(%rbp),%r9
call   1090 <recvfrom@plt>
mov    -0x10(%rbp),%edi
call   10c0 <ntohl@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movl   $0x0,0x8(%rsp)
mov    0x2e09(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x1388,%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%rbx),%edi
lea    0xdf2(%rip),%rsi
mov    %r14,%rdx
call   1080 <inet_pton@plt>
movl   $0xc,0xc(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
lea    0xdd9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xddb(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   10a0 <scanf@plt>
mov    0x8(%rsp),%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1090 <recvfrom@plt>
mov    0x8(%rsp),%edi
call   10c0 <ntohl@plt>
mov    %eax,0x8(%rsp)
lea    0xd7d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str = [13 x i8] c"153.19.1.202\00"
@.str.1 = [16 x i8] c"Enter a number:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [26 x i8] c"Server answered with: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
store i32 0, i32* %4
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %1
%9 = load i32, i32* %2
%10 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 %9)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %11, i32* %12
%13 = call i32 @htons(i32 5000)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* @PF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%17 = call i32 @inet_pton(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %16)
store i32 12, i32* %2
%18 = load i32, i32* %1
%19 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%20 = load i32, i32* %2
%21 = call i32 @bind(i32 %18, %struct.sockaddr* %19, i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%24 = load i32, i32* %4
%25 = call i32 @htonl(i32 %24)
store i32 %25, i32* %4
%26 = load i32, i32* %1
%27 = bitcast i32* %4 to i8*
%28 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%29 = load i32, i32* %2
%30 = call i32 @sendto(i32 %26, i8* %27, i32 4, i32 0, %struct.sockaddr* %28, i32 %29)
%31 = load i32, i32* %1
%32 = bitcast i32* %4 to i8*
%33 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%34 = call i32 @recvfrom(i32 %31, i8* %32, i32 4, i32 0, %struct.sockaddr* %33, i32* %2)
%35 = load i32, i32* %4
%36 = call i32 @ntohl(i32 %35)
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %37)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str = [13 x i8] c"153.19.1.202\00"
@.str.1 = [16 x i8] c"Enter a number:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [26 x i8] c"Server answered with: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 undef)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %11, i32* %12
%13 = call i32 @htons(i32 5000)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* @PF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%17 = call i32 @inet_pton(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %16)
store i32 12, i32* %1
%18 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%19 = call i32 @bind(i32 %9, %struct.sockaddr* %18, i32 12)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%22 = load i32, i32* %2
%23 = call i32 @htonl(i32 %22)
store i32 %23, i32* %2
%24 = call i32 @sendto(i32 %9, i8* %5, i32 4, i32 0, %struct.sockaddr* %18, i32 12)
%25 = call i32 @recvfrom(i32 %9, i8* %5, i32 4, i32 0, %struct.sockaddr* %18, i32* %1)
%26 = load i32, i32* %2
%27 = call i32 @ntohl(i32 %26)
store i32 %27, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %27)
ret i32 0
}