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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int server_fd;
  struct sockaddr_in myaddr;
  char buf[100];
  myaddr.sin_family = AF_INET;
  myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  myaddr.sin_port = htons(8080);
  int addr_len = sizeof(myaddr);
  server_fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (server_fd == -1) {
    perror("socket error");
    exit(1);
  }
  if (bind(server_fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) == -1) {
    perror("bind error");
    exit(1);
  }
  recvfrom(server_fd, buf, 100, 0, (struct sockaddr *)&myaddr, &addr_len);
  printf("get from client:%s\n", buf);
  close(server_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),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1f90,%edi
call   1030 <htons@plt>
mov    %eax,-0x18(%rbp)
movl   $0xc,-0x84(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1212 <main+0x82>
lea    0xdfd(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
jne    1242 <main+0xb2>
lea    0xdda(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
lea    -0x84(%rbp),%r9
call   1070 <recvfrom@plt>
lea    -0x80(%rbp),%rsi
lea    0xdad(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    0x2e47(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x1f90,%edi
call   1030 <htons@plt>
mov    %eax,0x10(%rsp)
movl   $0xc,0xc(%rsp)
mov    (%rbx),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1241 <main+0xb1>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
je     124a <main+0xba>
lea    0x20(%rsp),%r14
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1070 <recvfrom@plt>
lea    0xdf3(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdb8(%rip),%rdi
jmp    1251 <main+0xc1>
lea    0xdbc(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"socket error\00"
@.str.1 = [11 x i8] c"bind error\00"
@.str.2 = [20 x i8] c"get from client:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [100 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %6, i32* %7
%8 = load i32, i32* @INADDR_ANY
%9 = call i32 @htonl(i32 %8)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%11 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %10, i32 0, i32 0
store i32 %9, i32* %11
%12 = call i32 @htons(i32 8080)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %12, i32* %13
store i32 12, i32* %5
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %0
%23 = load i32, i32* %2
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i32 @bind(i32 %23, %struct.sockaddr* %24, i32 12)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22
%31 = load i32, i32* %2
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%34 = call i32 @recvfrom(i32 %31, i8* %32, i32 100, i32 0, %struct.sockaddr* %33, i32* %5)
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%36 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i32, i32* %2
%38 = call i32 @close(i32 %37)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"socket error\00"
@.str.1 = [11 x i8] c"bind error\00"
@.str.2 = [20 x i8] c"get from client:%s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %6, i32* %7
%8 = load i32, i32* @INADDR_ANY
%9 = tail call i32 @htonl(i32 %8)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %9, i32* %10
%11 = tail call i32 @htons(i32 8080)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %11, i32* %12
%13 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %0
%19 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %0
%22 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%23 = call i32 @bind(i32 %16, %struct.sockaddr* %22, i32 12)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = call i32 @recvfrom(i32 %16, i8* %5, i32 100, i32 0, %struct.sockaddr* %22, i32* %3)
%30 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%31 = call i32 @close(i32 %16)
ret i32 0
}