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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char, char *);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int server, j;
  socklen_t addrSize;
  struct sockaddr_in serverAddr, clientAddr;
  char data;
  memset(&serverAddr, 0, sizeof(serverAddr));
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  serverAddr.sin_port = htons(9998);
  addrSize = sizeof(clientAddr);
  server = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  bind(server, (struct sockaddr *)&serverAddr, sizeof(serverAddr));
  for (j = 5; (--j) >= 0;) {
    recvfrom(server, &data, 1, 0, (struct sockaddr *)&clientAddr, &addrSize);
    printf("New message %d from %s\n", data, inet_ntoa(clientAddr.sin_addr));
  }
  close(server);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x28(%rbp)
mov    $0x270e,%edi
call   1040 <htons@plt>
mov    %eax,-0x24(%rbp)
movl   $0xc,-0x1c(%rbp)
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
movl   $0x5,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jl     1277 <main+0xe7>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%r8
lea    -0x39(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1090 <recvfrom@plt>
mov    -0x39(%rbp),%al
mov    %al,-0x3a(%rbp)
mov    -0x38(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rdx
mov    -0x3a(%rbp),%al
lea    0xd96(%rip),%rdi
movsbl %al,%esi
call   1050 <printf@plt>
jmp    1222 <main+0x92>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x18(%rsp)
mov    $0x270e,%edi
call   1040 <htons@plt>
mov    %eax,0x1c(%rsp)
movl   $0xc,0x14(%rsp)
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
lea    0x7(%rsp),%r12
lea    0x8(%rsp),%r14
lea    0x14(%rsp),%r15
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1090 <recvfrom@plt>
movsbl 0x7(%rsp),%ebp
mov    0x8(%rsp),%edi
call   1030 <inet_ntoa@plt>
lea    0xdad(%rip),%r13
mov    %r13,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1090 <recvfrom@plt>
movsbl 0x7(%rsp),%ebp
mov    0x8(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1090 <recvfrom@plt>
movsbl 0x7(%rsp),%ebp
mov    0x8(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1090 <recvfrom@plt>
movsbl 0x7(%rsp),%ebp
mov    0x8(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1090 <recvfrom@plt>
movsbl 0x7(%rsp),%ebp
mov    0x8(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1050 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [24 x i8] c"New message %d from %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, 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* %9, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 @htons(i32 9998)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %19, i32* %20
store i32 12, i32* %8
%21 = load i32, i32* @PF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = load i32, i32* @IPPROTO_UDP
%24 = call i32 @socket(i32 %21, i32 %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%27 = call i32 @bind(i32 %25, %struct.sockaddr* %26, i32 12)
store i32 5, i32* %7
br label %28
28: ; preds = %32, %2
%29 = load i32, i32* %7
%30 = add nsw i32 %29, -1
store i32 %30, i32* %7
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i32, i32* %6
%34 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%35 = call i32 @recvfrom(i32 %33, i8* %11, i32 1, i32 0, %struct.sockaddr* %34, i32* %8)
%36 = load i8, i8* %11
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i8* @inet_ntoa(i32 %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8 signext %36, i8* %40)
br label %28
42: ; preds = %28
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [24 x i8] c"New message %d from %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i8
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %11, i32* %12
%13 = load i32, i32* @INADDR_ANY
%14 = call i32 @htonl(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %14, i32* %15
%16 = call i32 @htons(i32 9998)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %16, i32* %17
store i32 12, i32* %3
%18 = load i32, i32* @PF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = load i32, i32* @IPPROTO_UDP
%21 = call i32 @socket(i32 %18, i32 %19, i32 %20)
%22 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%23 = call i32 @bind(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
%26 = call i32 @recvfrom(i32 %21, i8* %6, i32 1, i32 0, %struct.sockaddr* %24, i32* %3)
%27 = load i8, i8* %6
%28 = load i32, i32* %25
%29 = call i8* @inet_ntoa(i32 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8 signext %27, i8* %29)
%31 = call i32 @recvfrom(i32 %21, i8* %6, i32 1, i32 0, %struct.sockaddr* %24, i32* %3)
%32 = load i8, i8* %6
%33 = load i32, i32* %25
%34 = call i8* @inet_ntoa(i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8 signext %32, i8* %34)
%36 = call i32 @recvfrom(i32 %21, i8* %6, i32 1, i32 0, %struct.sockaddr* %24, i32* %3)
%37 = load i8, i8* %6
%38 = load i32, i32* %25
%39 = call i8* @inet_ntoa(i32 %38)
%40 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8 signext %37, i8* %39)
%41 = call i32 @recvfrom(i32 %21, i8* %6, i32 1, i32 0, %struct.sockaddr* %24, i32* %3)
%42 = load i8, i8* %6
%43 = load i32, i32* %25
%44 = call i8* @inet_ntoa(i32 %43)
%45 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8 signext %42, i8* %44)
%46 = call i32 @recvfrom(i32 %21, i8* %6, i32 1, i32 0, %struct.sockaddr* %24, i32* %3)
%47 = load i8, i8* %6
%48 = load i32, i32* %25
%49 = call i8* @inet_ntoa(i32 %48)
%50 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8 signext %47, i8* %49)
%51 = call i32 @close(i32 %21)
ret i32 0
}