#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*/ server;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ 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 strlen(char *);
int main() {
  int sock = socket(AF_INET, SOCK_DGRAM, 0);
  struct sockaddr_in server;
  server.sin_family = AF_INET;
  server.sin_port = htons(8000);
  inet_pton(AF_INET, "127.0.0.1", &server.sin_addr);
  char *buf = "Client sends a Message to the Server, please confirm?";
  int len = strlen(buf);
  int ret =
      sendto(sock, buf, len, 0, (struct sockaddr *)&server, sizeof(server));
  printf("ret = %d\n", ret);
  char recv_buf[100];
  recvfrom(sock, recv_buf, 100, 0, (struct sockaddr *)&server, &len);
  sendto(sock, buf, len, 0, (struct sockaddr *)&server, sizeof(server));
  printf("buf = %s\n", recv_buf);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x1f40,%edi
call   1040 <htons@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1070 <inet_pton@plt>
lea    0xe3a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x10(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x90(%rbp),%rsi
lea    -0x10(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1080 <recvfrom@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x10(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
lea    -0x90(%rbp),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    0x2e63(%rip),%r14
mov    (%r14),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x1f40,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r14),%edi
lea    0xe47(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdx
call   1070 <inet_pton@plt>
lea    0xe3d(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
lea    0xe49(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x20(%rsp),%r12
lea    0xc(%rsp),%r9
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1080 <recvfrom@plt>
mov    0xc(%rsp),%edx
mov    %ebx,%edi
mov    %r15,%rsi
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
lea    0xe0c(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [54 x i8] c"Client sends a Message to the Server, please confirm?\00"
@.str.2 = [10 x i8] c"ret = %d\0A\00"
@.str.3 = [10 x i8] c"buf = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %1
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %10, i32* %11
%12 = call i32 @htons(i32 8000)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%16 = call i32 @inet_pton(i32 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %15)
store i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8** %3
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %4
%19 = load i32, i32* %1
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%23 = call i32 @sendto(i32 %19, i8* %20, i32 %21, i32 0, %struct.sockaddr* %22, i32 12)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %1
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%28 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%29 = call i32 @recvfrom(i32 %26, i8* %27, i32 100, i32 0, %struct.sockaddr* %28, i32* %4)
%30 = load i32, i32* %1
%31 = load i8*, i8** %3
%32 = load i32, i32* %4
%33 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%34 = call i32 @sendto(i32 %30, i8* %31, i32 %32, i32 0, %struct.sockaddr* %33, i32 12)
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %35)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [54 x i8] c"Client sends a Message to the Server, please confirm?\00"
@.str.2 = [10 x i8] c"ret = %d\0A\00"
@.str.3 = [10 x i8] c"buf = %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = bitcast %struct.sockaddr_in* %1 to i8*
%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 8000)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%14 = call i32 @inet_pton(i32 %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %13)
%15 = bitcast i32* %2 to i8*
%16 = call i32 @strlen(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
store i32 %16, i32* %2
%17 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%18 = call i32 @sendto(i32 %6, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 0, %struct.sockaddr* %17, i32 12)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%21 = call i32 @recvfrom(i32 %6, i8* %20, i32 100, i32 0, %struct.sockaddr* %17, i32* %2)
%22 = load i32, i32* %2
%23 = call i32 @sendto(i32 %6, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 0, %struct.sockaddr* %17, i32 12)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %20)
ret i32 0
}