#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*/ si_other;
typedef int /*<<< orphan*/ si_me;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ on_err(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int main(void) {
  int s = -1;
  struct sockaddr_in si_me, si_other;
  int slen = sizeof(si_other);
  char buf[512];
  if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
    on_err(strerror(errno));
  memset((char *)&si_me, 0, sizeof(si_me));
  si_me.sin_family = AF_INET;
  si_me.sin_port = htons(9930);
  si_me.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(s, (struct sockaddr *)&si_me, sizeof(si_me)) == -1)
    on_err(strerror(errno));
  for (int i = 0; i < 10; i++) {
    if (recvfrom(s, buf, 512, 0, (struct sockaddr *)&si_other, &slen) == -1)
      on_err(strerror(errno));
    printf("Received packet from %s:%d\nData: %s\n\n",
           inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port), buf);
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0xc,-0x2c(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1221 <main+0x61>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   1060 <on_err@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x26ca,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    128a <main+0xca>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   1060 <on_err@plt>
movl   $0x0,-0x234(%rbp)
cmpl   $0xa,-0x234(%rbp)
jge    1324 <main+0x164>
mov    -0x8(%rbp),%edi
lea    -0x230(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    12dd <main+0x11d>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   1060 <on_err@plt>
mov    -0x24(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x240(%rbp)
mov    -0x28(%rbp),%edi
call   10b0 <ntohs@plt>
mov    -0x240(%rbp),%rsi
mov    %eax,%edx
lea    -0x230(%rbp),%rcx
lea    0xcf5(%rip),%rdi
call   1050 <printf@plt>
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
jmp    1294 <main+0xd4>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
movl   $0xc,0xc(%rsp)
mov    0x2e08(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    1217 <main+0x57>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   1060 <on_err@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x26ca,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    127c <main+0xbc>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   1060 <on_err@plt>
mov    $0xa,%r14d
lea    0x30(%rsp),%rbx
lea    0xc(%rsp),%r15
lea    0xd6d(%rip),%r12
jmp    12cb <main+0x10b>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x24(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rbp
mov    0x20(%rsp),%edi
call   10b0 <ntohs@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
call   1050 <printf@plt>
add    $0xffffffff,%r14d
je     1301 <main+0x141>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
mov    %r15,%r9
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    12a0 <main+0xe0>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   1060 <on_err@plt>
jmp    12a0 <main+0xe0>
mov    %r13d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x238,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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
@IPPROTO_UDP = global i32 0
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str = [38 x i8] c"Received packet from %s:%d\0AData: %s\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 12, i32* %5
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = load i32, i32* @IPPROTO_UDP
%11 = call i32 @socket(i32 %8, i32 %9, i32 %10)
store i32 %11, i32* %2
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* @errno
%15 = call i32 @strerror(i32 %14)
%16 = call i32 @on_err(i32 %15)
br label %17
17: ; preds = %13, %0
%18 = bitcast %struct.sockaddr_in* %3 to i8*
%19 = call i32 @memset(i8* %18, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 9930)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %22, i32* %23
%24 = load i32, i32* @INADDR_ANY
%25 = call i32 @htonl(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = load i32, i32* %2
%29 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%30 = call i32 @bind(i32 %28, %struct.sockaddr* %29, i32 12)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %17
%33 = load i32, i32* @errno
%34 = call i32 @strerror(i32 %33)
%35 = call i32 @on_err(i32 %34)
br label %36
36: ; preds = %32, %17
store i32 0, i32* %7
br label %37
37: ; preds = %60, %36
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 10
br i1 %39, label %40, label %63
40: ; preds = %37
%41 = load i32, i32* %2
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%43 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%44 = call i32 @recvfrom(i32 %41, i8* %42, i32 512, i32 0, %struct.sockaddr* %43, i32* %5)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %50
46: ; preds = %40
%47 = load i32, i32* @errno
%48 = call i32 @strerror(i32 %47)
%49 = call i32 @on_err(i32 %48)
br label %50
50: ; preds = %46, %40
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%52 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i8* @inet_ntoa(i32 %53)
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @ntohs(i32 %56)
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%59 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %54, i32 %57, i8* %58)
br label %60
60: ; preds = %50
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %37
63: ; preds = %37
%64 = load i32, i32* %2
%65 = call i32 @close(i32 %64)
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
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str = [38 x i8] c"Received packet from %s:%d\0AData: %s\0A\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [512 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = load i32, i32* @IPPROTO_UDP
%12 = tail call i32 @socket(i32 %9, i32 %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = load i32, i32* @errno
%16 = tail call i32 @strerror(i32 %15)
%17 = tail call i32 @on_err(i32 %16)
br label %18
18: ; preds = %14, %0
%19 = call i32 @memset(i8* %5, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 9930)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %22, i32* %23
%24 = load i32, i32* @INADDR_ANY
%25 = call i32 @htonl(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%28 = call i32 @bind(i32 %12, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %18
%31 = load i32, i32* @errno
%32 = call i32 @strerror(i32 %31)
%33 = call i32 @on_err(i32 %32)
br label %34
34: ; preds = %30, %18
%35 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
br label %40
38: ; preds = %48
%39 = call i32 @close(i32 %12)
ret i32 0
40: ; preds = %34, %48
%41 = phi i32 [ 0, %34 ], [ %54, %48 ]
%42 = call i32 @recvfrom(i32 %12, i8* %8, i32 512, i32 0, %struct.sockaddr* %35, i32* %3)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i32, i32* @errno
%46 = call i32 @strerror(i32 %45)
%47 = call i32 @on_err(i32 %46)
br label %48
48: ; preds = %44, %40
%49 = load i32, i32* %36
%50 = call i8* @inet_ntoa(i32 %49)
%51 = load i32, i32* %37
%52 = call i32 @ntohs(i32 %51)
%53 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %50, i32 %52, i8* %8)
%54 = add nuw nsw i32 %41, 1
%55 = icmp eq i32 %54, 10
br i1 %55, label %38, label %40
}