#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 */
typedef int /*<<< orphan*/ your_adr;
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*/ my_adr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error_handling(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sock;
  char message[30];
  struct sockaddr_in my_adr, your_adr;
  socklen_t adr_sz;
  int str_len, i;
  if (argc != 2) {
    printf("Usage: %s <port>\n", argv[0]);
    exit(1);
  }
  sock = socket(PF_INET, SOCK_DGRAM, 0);
  if (sock == -1)
    error_handling("socket() error");
  memset(&my_adr, 0, sizeof(my_adr));
  my_adr.sin_family = AF_INET;
  my_adr.sin_addr.s_addr = htonl(INADDR_ANY);
  my_adr.sin_port = htons(atoi(argv[1]));
  if (bind(sock, (struct sockaddr *)&my_adr, sizeof(my_adr)) == -1)
    error_handling("bind() error");
  for (i = 0; i < 3; i++) {
    sleep(5);
    adr_sz = sizeof(your_adr);
    str_len =
        recvfrom(sock, message, 30, 0, (struct sockaddr *)&your_adr, &adr_sz);
    printf("Message %d: %s \n", i + 1, message);
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ff <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1231 <main+0x71>
lea    0xde6(%rip),%rdi
call   1080 <error_handling@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,-0x50(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    129b <main+0xdb>
lea    0xd8b(%rip),%rdi
call   1080 <error_handling@plt>
movl   $0x0,-0x6c(%rbp)
cmpl   $0x3,-0x6c(%rbp)
jge    1301 <main+0x141>
mov    $0x5,%edi
call   10d0 <sleep@plt>
movl   $0xc,-0x64(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%r8
mov    $0x1e,%edx
xor    %ecx,%ecx
lea    -0x64(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x68(%rbp)
mov    -0x6c(%rbp),%esi
add    $0x1,%esi
lea    -0x40(%rbp),%rdx
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    12a2 <main+0xe2>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    134a <main+0x18a>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1205 <main+0x45>
lea    0xe12(%rip),%rdi
call   1080 <error_handling@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    0x8(%r14),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    126c <main+0xac>
lea    0xdba(%rip),%rdi
call   1080 <error_handling@plt>
mov    $0x5,%edi
call   10d0 <sleep@plt>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%r14
lea    0x20(%rsp),%r15
lea    0xc(%rsp),%r12
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1e,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1090 <recvfrom@plt>
lea    0xd83(%rip),%r13
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x5,%edi
call   10d0 <sleep@plt>
movl   $0xc,0xc(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1e,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1090 <recvfrom@plt>
mov    %r13,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x5,%edi
call   10d0 <sleep@plt>
movl   $0xc,0xc(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1e,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1090 <recvfrom@plt>
mov    %r13,%rdi
mov    $0x3,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    (%r14),%rsi
lea    0xcac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"Usage: %s <port>\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [13 x i8] c"bind() error\00"
@.str.3 = [17 x i8] c"Message %d: %s \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [30 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* @PF_INET
%23 = load i32, i32* @SOCK_DGRAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %21
%30 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %31, i32* %32
%33 = load i32, i32* @INADDR_ANY
%34 = call i32 @htonl(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
%41 = call i32 @htons(i32 %40)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %41, i32* %42
%43 = load i32, i32* %6
%44 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%45 = call i32 @bind(i32 %43, %struct.sockaddr* %44, i32 12)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %29
%48 = call i32 @error_handling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %49
49: ; preds = %47, %29
store i32 0, i32* %12
br label %50
50: ; preds = %63, %49
%51 = load i32, i32* %12
%52 = icmp slt i32 %51, 3
br i1 %52, label %53, label %66
53: ; preds = %50
%54 = call i32 @sleep(i32 5)
store i32 12, i32* %10
%55 = load i32, i32* %6
%56 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%57 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%58 = call i32 @recvfrom(i32 %55, i8* %56, i32 30, i32 0, %struct.sockaddr* %57, i32* %10)
store i32 %58, i32* %11
%59 = load i32, i32* %12
%60 = add nsw i32 %59, 1
%61 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %60, i8* %61)
br label %63
63: ; preds = %53
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %50
66: ; preds = %50
%67 = load i32, i32* %6
%68 = call i32 @close(i32 %67)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"Usage: %s <port>\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [13 x i8] c"bind() error\00"
@.str.3 = [17 x i8] c"Message %d: %s \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [30 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = icmp eq i32 %0, 2
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @PF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %25, i32* %26
%27 = load i32, i32* @INADDR_ANY
%28 = call i32 @htonl(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %28, i32* %29
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
%33 = call i32 @htons(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %33, i32* %34
%35 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%36 = call i32 @bind(i32 %19, %struct.sockaddr* %35, i32 12)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %23
%39 = call i32 @error_handling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %23
%41 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%42 = call i32 @sleep(i32 5)
store i32 12, i32* %6
%43 = call i32 @recvfrom(i32 %19, i8* %7, i32 30, i32 0, %struct.sockaddr* %41, i32* %6)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 1, i8* %7)
%45 = call i32 @sleep(i32 5)
store i32 12, i32* %6
%46 = call i32 @recvfrom(i32 %19, i8* %7, i32 30, i32 0, %struct.sockaddr* %41, i32* %6)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 2, i8* %7)
%48 = call i32 @sleep(i32 5)
store i32 12, i32* %6
%49 = call i32 @recvfrom(i32 %19, i8* %7, i32 30, i32 0, %struct.sockaddr* %41, i32* %6)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 3, i8* %7)
%51 = call i32 @close(i32 %19)
ret i32 0
}