#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*/ 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*/ diep(char *);
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*/ printf(char *, char *, int, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  struct sockaddr_in si_me, si_other;
  int s, i;
  socklen_t slen = sizeof(si_other);
  char buf[512];
  if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
    diep("socket");
  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)
    diep("bind");
  for (i = 0; i < 10; i++) {
    if (recvfrom(s, buf, 512, 0, (struct sockaddr *)&si_other, &slen) == -1)
      diep("recvfrom()");
    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   $0xc,-0x2c(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    1201 <main+0x51>
lea    0xe04(%rip),%rdi
call   1090 <diep@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x26ca,%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0xc(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1261 <main+0xb1>
lea    0xdab(%rip),%rdi
call   1090 <diep@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0xa,-0x28(%rbp)
jge    12e6 <main+0x136>
mov    -0x24(%rbp),%edi
lea    -0x230(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    12a5 <main+0xf5>
lea    0xd6c(%rip),%rdi
call   1090 <diep@plt>
mov    -0x1c(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x238(%rbp)
mov    -0x20(%rbp),%edi
call   10b0 <ntohs@plt>
mov    -0x238(%rbp),%rsi
mov    %eax,%edx
lea    -0x230(%rbp),%rcx
lea    0xd44(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1268 <main+0xb8>
mov    -0x24(%rbp),%edi
call   1080 <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    0x2e18(%rip),%r14
mov    (%r14),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11fd <main+0x4d>
lea    0xe08(%rip),%rdi
call   1090 <diep@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x26ca,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1258 <main+0xa8>
lea    0xdb4(%rip),%rdi
call   1090 <diep@plt>
mov    $0xa,%r14d
lea    0x30(%rsp),%rbx
lea    0xc(%rsp),%r15
lea    0xda8(%rip),%r13
jmp    12ab <main+0xfb>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x24(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%r12
mov    0x20(%rsp),%edi
call   10b0 <ntohs@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
call   1050 <printf@plt>
add    $0xffffffff,%r14d
je     12d7 <main+0x127>
mov    %ebp,%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    1280 <main+0xd0>
lea    0xd3c(%rip),%rdi
call   1090 <diep@plt>
jmp    1280 <main+0xd0>
mov    %ebp,%edi
call   1080 <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
@.str = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [11 x i8] c"recvfrom()\00"
@.str.3 = [38 x i8] c"Received packet from %s:%d\0AData: %s\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [512 x i8]
store i32 0, i32* %1
store i32 12, i32* %6
%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* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @diep(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = bitcast %struct.sockaddr_in* %2 to i8*
%17 = call i32 @memset(i8* %16, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 9930)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
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* %2, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* %4
%27 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%28 = call i32 @bind(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %15
%31 = call i32 @diep(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %15
store i32 0, i32* %5
br label %33
33: ; preds = %54, %32
%34 = load i32, i32* %5
%35 = icmp slt i32 %34, 10
br i1 %35, label %36, label %57
36: ; preds = %33
%37 = load i32, i32* %4
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%39 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%40 = call i32 @recvfrom(i32 %37, i8* %38, i32 512, i32 0, %struct.sockaddr* %39, i32* %6)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @diep(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %42, %36
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%46 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i8* @inet_ntoa(i32 %47)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @ntohs(i32 %50)
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%53 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %48, i32 %51, i8* %52)
br label %54
54: ; preds = %44
%55 = load i32, i32* %5
%56 = add nsw i32 %55, 1
store i32 %56, i32* %5
br label %33
57: ; preds = %33
%58 = load i32, i32* %4
%59 = call i32 @close(i32 %58)
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
@.str = [7 x i8] c"socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [11 x i8] c"recvfrom()\00"
@.str.3 = [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 %16
14: ; preds = %0
%15 = tail call i32 @diep(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %0
%17 = call i32 @memset(i8* %5, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 9930)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
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* %1, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%26 = call i32 @bind(i32 %12, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = call i32 @diep(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %16
%31 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
br label %34
34: ; preds = %30, %40
%35 = phi i32 [ 0, %30 ], [ %46, %40 ]
%36 = call i32 @recvfrom(i32 %12, i8* %8, i32 512, i32 0, %struct.sockaddr* %31, i32* %3)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @diep(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %34
%41 = load i32, i32* %32
%42 = call i8* @inet_ntoa(i32 %41)
%43 = load i32, i32* %33
%44 = call i32 @ntohs(i32 %43)
%45 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %42, i32 %44, i8* %8)
%46 = add nuw nsw i32 %35, 1
%47 = icmp eq i32 %46, 10
br i1 %47, label %48, label %34
48: ; preds = %40
%49 = call i32 @close(i32 %12)
ret i32 0
}