#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*/ ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ cli_addr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(void) {
  int sock;
  struct sockaddr_in serv_addr, cli_addr;
  char buf[256];
  ssize_t n;
  socklen_t len;
  puts("starting server");
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  serv_addr.sin_port = htons(31337);
  bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  len = sizeof(cli_addr);
  while (1) {
    n = recvfrom(sock, buf, sizeof(buf), 0, (struct sockaddr *)&cli_addr, &len);
    fputs(buf, stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    $0x7a69,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
movl   $0xc,-0x138(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x130(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x100,%edx
xor    %ecx,%ecx
lea    -0x138(%rbp),%r9
call   1080 <recvfrom@plt>
mov    %eax,-0x134(%rbp)
lea    -0x130(%rbp),%rdi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
jmp    120f <main+0x8f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x130,%rsp
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e46(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x7a69,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%rbx
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%r15
mov    0x2dab(%rip),%r12
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1080 <recvfrom@plt>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
jmp    1220 <main+0xa0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"starting server\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 @htons(i32 31337)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i32 @bind(i32 %21, %struct.sockaddr* %22, i32 12)
store i32 12, i32* %7
br label %24
24: ; preds = %0, %24
%25 = load i32, i32* %2
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%27 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%28 = call i32 @recvfrom(i32 %25, i8* %26, i32 256, i32 0, %struct.sockaddr* %27, i32* %7)
store i32 %28, i32* %6
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%30 = load i32, i32* @stdout
%31 = call i32 @fputs(i8* %29, i32 %30)
br label %24
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"starting server\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = call i32 @htonl(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %17, i32* %18
%19 = call i32 @htons(i32 31337)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%22 = call i32 @bind(i32 %12, %struct.sockaddr* %21, i32 12)
store i32 12, i32* %4
%23 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %24
24: ; preds = %24, %0
%25 = call i32 @recvfrom(i32 %12, i8* %7, i32 256, i32 0, %struct.sockaddr* %23, i32* %4)
%26 = load i32, i32* @stdout
%27 = call i32 @fputs(i8* %7, i32 %26)
br label %24
}