#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 socklen_t;
typedef int /*<<< orphan*/ saddr;
typedef int int16_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int, int);
scalar_t__ recvfrom(int, int **, int, int /*<<< orphan*/, struct sockaddr *,
                    int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sock;
  struct sockaddr_in saddr, caddr;
  socklen_t addrlen = sizeof(struct sockaddr_in);
  int16_t buf[4];
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0) {
    perror("ERROR:");
    exit(-1);
  }
  saddr.sin_family = AF_INET;
  saddr.sin_addr.s_addr = htonl(INADDR_ANY);
  saddr.sin_port = htons(25000);
  if (bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
    perror("ERROR:");
    exit(-1);
  }
  while (1) {
    memset(buf, 0, sizeof(buf));
    if (recvfrom(sock, &buf, sizeof(buf), 0, (struct sockaddr *)&caddr,
                 &addrlen) < 0) {
      perror("ERROR:");
      exit(-1);
    }
    printf("%d %d %d %d\n", buf[0], buf[1], buf[2], buf[3]);
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xc,-0x34(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11e9 <main+0x59>
lea    0xe26(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x61a8,%edi
call   1030 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    1244 <main+0xb4>
lea    0xdcb(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    1249 <main+0xb9>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
lea    -0x30(%rbp),%r8
mov    $0x10,%edx
xor    %ecx,%ecx
lea    -0x34(%rbp),%r9
call   1070 <recvfrom@plt>
cmp    $0x0,%rax
jge    1294 <main+0x104>
lea    0xd7b(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x50(%rbp),%esi
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%ecx
mov    -0x44(%rbp),%r8d
lea    0xd5f(%rip),%rdi
call   1040 <printf@plt>
jmp    1249 <main+0xb9>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
movl   $0xc,0xc(%rsp)
mov    0x2e3d(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     12a5 <main+0x115>
mov    %eax,%r15d
mov    (%rbx),%eax
mov    %eax,0x28(%rsp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x24(%rsp)
mov    $0x61a8,%edi
call   1030 <htons@plt>
mov    %eax,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
js     12a5 <main+0x115>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0x30(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1070 <recvfrom@plt>
test   %rax,%rax
js     12a5 <main+0x115>
lea    0xdc2(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0x30(%rsp),%r12
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x1c(%rsp),%r8d
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %rbp,%r9
call   1070 <recvfrom@plt>
test   %rax,%rax
jns    1260 <main+0xd0>
lea    0xd54(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%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
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"ERROR:\00"
@INADDR_ANY = global i32 0
@.str.1 = [13 x i8] c"%d %d %d %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca [4 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 12, i32* %9
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = call i32 @htons(i32 25000)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* %6
%29 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%30 = call i64 @bind(i32 %28, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %19
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %19
br label %36
36: ; preds = %35, %47
%37 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 0
%38 = call i32 @memset(i32* %37, i32 0, i32 16)
%39 = load i32, i32* %6
%40 = bitcast [4 x i32]* %10 to i32**
%41 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%42 = call i64 @recvfrom(i32 %39, i32** %40, i32 16, i32 0, %struct.sockaddr* %41, i32* %9)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %36
%45 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%46 = call i32 @exit(i32 -1)
unreachable
47: ; preds = %36
%48 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 0
%49 = load i32, i32* %48
%50 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 1
%51 = load i32, i32* %50
%52 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 2
%53 = load i32, i32* %52
%54 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 3
%55 = load i32, i32* %54
%56 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %49, i32 %51, i32 %53, i32 %55)
br label %36
}

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
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"ERROR:\00"
@INADDR_ANY = global i32 0
@.str.1 = [13 x i8] c"%d %d %d %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [4 x i32]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%10 = bitcast [4 x i32]* %6 to i8*
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = tail call i32 @htonl(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 25000)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %24, i32* %25
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%27 = call i64 @bind(i32 %13, %struct.sockaddr* %26, i32 12)
%28 = icmp slt i64 %27, 0
br i1 %28, label %40, label %29
29: ; preds = %18
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%31 = call i32 @memset(i32* %30, i32 0, i32 16)
%32 = bitcast [4 x i32]* %6 to i32**
%33 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%34 = call i64 @recvfrom(i32 %13, i32** %32, i32 16, i32 0, %struct.sockaddr* %33, i32* %5)
%35 = icmp slt i64 %34, 0
br i1 %35, label %43, label %36
36: ; preds = %29
%37 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 1
%38 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 2
%39 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 3
br label %46
40: ; preds = %18
%41 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%42 = call i32 @exit(i32 -1)
unreachable
43: ; preds = %46, %29
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%45 = call i32 @exit(i32 -1)
unreachable
46: ; preds = %36, %46
%47 = load i32, i32* %30
%48 = load i32, i32* %37
%49 = load i32, i32* %38
%50 = load i32, i32* %39
%51 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %47, i32 %48, i32 %49, i32 %50)
%52 = call i32 @memset(i32* %30, i32 0, i32 16)
%53 = call i64 @recvfrom(i32 %13, i32** %32, i32 16, i32 0, %struct.sockaddr* %33, i32* %5)
%54 = icmp slt i64 %53, 0
br i1 %54, label %43, label %46
}