#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 scalar_t__ u_int8_t;
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 size_t ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ server_address;
typedef int /*<<< orphan*/ sender_ip_str;
typedef int /*<<< orphan*/ sender;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IP_MAXPACKET;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int bswap_32(int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, TYPE_1__ *, char *, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
size_t recvfrom(int, scalar_t__ *, int /*<<< orphan*/, int /*<<< orphan*/,
                struct sockaddr *, int *);
size_t sendto(int, char *, size_t, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
size_t strlen(char *);
int main() {
  int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    fprintf(stderr, "socket error: %s\n", strerror(errno));
    return EXIT_FAILURE;
  }
  struct sockaddr_in server_address;
  bzero(&server_address, sizeof(server_address));
  server_address.sin_family = AF_INET;
  server_address.sin_port = htons(54321);
  server_address.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(sockfd, (struct sockaddr *)&server_address, sizeof(server_address)) <
      0) {
    fprintf(stderr, "bind error: %s\n", strerror(errno));
    return EXIT_FAILURE;
  }
  for (;;) {
    struct sockaddr_in sender;
    socklen_t sender_len = sizeof(sender);
    u_int8_t buffer[IP_MAXPACKET + 1];
    ssize_t datagram_len = recvfrom(sockfd, buffer, IP_MAXPACKET, 0,
                                    (struct sockaddr *)&sender, &sender_len);
    if (datagram_len < 0) {
      fprintf(stderr, "recvfrom error: %s\n", strerror(errno));
      return EXIT_FAILURE;
    }
    char sender_ip_str[20];
    inet_ntop(AF_INET, &(sender.sin_addr), sender_ip_str,
              sizeof(sender_ip_str));
    printf("Received UDP packet from IP address: %s, port: %d\n", sender_ip_str,
           ntohs(sender.sin_port));
    buffer[datagram_len] = 0;
    char *b1 = (char *)&(buffer[5]);
    int distance = bswap_32(*((int *)b1));
    printf("%ld-byte message: +%d.%d.%d.%d/%d distance %d+\n", datagram_len,
           buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], distance);
    char *reply = "Thank you!";
    ssize_t reply_len = strlen(reply);
    if (sendto(sockfd, reply, reply_len, 0, (struct sockaddr *)&sender,
               sender_len) != reply_len) {
      fprintf(stderr, "sendto error: %s\n", strerror(errno));
      return EXIT_FAILURE;
    }
    fflush(stdout);
  }
  close(sockfd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    126b <main+0x7b>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    %rax,%rdx
lea    0xdab(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1523 <main+0x333>
lea    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0xd431,%edi
call   1050 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d3f(%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   10e0 <bind@plt>
cmp    $0x0,%rax
jge    1301 <main+0x111>
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rdx
lea    0xd27(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1523 <main+0x333>
jmp    1306 <main+0x116>
movl   $0xc,-0x2c(%rbp)
mov    0x2ce4(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x90(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2cae(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   10c0 <recvfrom@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jae    13b4 <main+0x1c4>
mov    0x2c4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rdx
lea    0xc8b(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2c0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1502 <main+0x312>
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
lea    -0x60(%rbp),%rdx
mov    $0x14,%ecx
call   1030 <inet_ntop@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x28(%rbp),%edi
call   10d0 <ntohs@plt>
mov    -0xa0(%rbp),%rsi
mov    %eax,%edx
lea    0xc40(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x90(%rbp),%rax
mov    -0x48(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
add    $0x28,%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
mov    (%rax),%edi
call   10b0 <bswap_32@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
mov    %ecx,-0x6c(%rbp)
mov    -0x48(%rbp),%rsi
mov    (%rax),%rdx
mov    0x8(%rax),%rcx
mov    0x10(%rax),%r8
mov    0x18(%rax),%r9
mov    0x20(%rax),%r10
mov    -0x6c(%rbp),%eax
lea    0xc19(%rip),%rdi
sub    $0x10,%rsp
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x10,%rsp
lea    0xc2b(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rdx
lea    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
cmp    -0x80(%rbp),%rax
je     14ed <main+0x2fd>
mov    0x2b16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2aff(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0xa4(%rbp),%edi
mov    %rax,%rdx
lea    0xbd4(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2ad4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1502 <main+0x312>
mov    0x2ab4(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4c(%rbp),%eax
test   %eax,%eax
je     151e <main+0x32e>
jmp    1519 <main+0x329>
jmp    1523 <main+0x333>
jmp    1306 <main+0x116>
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    0x2de8(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     13ad <main+0x1cd>
lea    -0x58(%rbp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
mov    %eax,%r15d
call   10e0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,-0x50(%rbp)
mov    $0xd431,%edi
call   1040 <htons@plt>
mov    %eax,-0x58(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x54(%rbp)
mov    %r15d,-0x2c(%rbp)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
test   %rax,%rax
js     13cd <main+0x1ed>
cs nopw 0x0(%rax,%rax,1)
mov    %rsp,-0x38(%rbp)
movl   $0xc,-0x30(%rbp)
mov    0x2d76(%rip),%rcx
mov    (%rcx),%eax
add    $0x1,%eax
mov    %rsp,%r12
mov    %r12,-0x60(%rbp)
lea    0xf(,%rax,8),%r13
and    $0xfffffffffffffff0,%r13
sub    %r13,%r12
mov    %r12,%rsp
mov    (%rcx),%edx
mov    -0x2c(%rbp),%edi
mov    %r12,%rsi
xor    %ecx,%ecx
lea    -0x48(%rbp),%r8
lea    -0x30(%rbp),%r9
call   10b0 <recvfrom@plt>
mov    %rax,%r14
mov    %rbx,%r15
mov    (%rbx),%edi
lea    -0x44(%rbp),%rsi
lea    -0x80(%rbp),%rbx
mov    %rbx,%rdx
mov    $0x14,%ecx
call   1030 <inet_ntop@plt>
mov    -0x48(%rbp),%edi
call   10c0 <ntohs@plt>
lea    0xd3f(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movq   $0x0,(%r12,%r14,8)
mov    0x28(%r12),%edi
call   10a0 <bswap_32@plt>
mov    %eax,%ebx
mov    (%r12),%rdx
mov    0x8(%r12),%rcx
mov    0x10(%r12),%r8
mov    0x18(%r12),%r9
neg    %r13
lea    0xd35(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
push   %rbx
mov    -0x60(%rbp),%rbx
push   0x20(%rbx,%r13,1)
call   1050 <printf@plt>
add    $0x10,%rsp
mov    -0x30(%rbp),%r9d
mov    $0xa,%edx
mov    -0x2c(%rbp),%edi
lea    0xd3a(%rip),%rsi
xor    %ecx,%ecx
lea    -0x48(%rbp),%r8
call   1070 <sendto@plt>
cmp    $0xa,%rax
jne    1376 <main+0x196>
mov    0x2c45(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    -0x38(%rbp),%rsp
mov    %r15,%rbx
jmp    1270 <main+0x90>
mov    0x2c43(%rip),%rax
mov    (%rax),%ebx
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xcfc(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2c0b(%rip),%rax
mov    (%rax),%eax
mov    -0x38(%rbp),%rsp
jmp    13fe <main+0x21e>
mov    0x2c0c(%rip),%rax
mov    (%rax),%ebx
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xc35(%rip),%rsi
jmp    13eb <main+0x20b>
mov    0x2bec(%rip),%rax
mov    (%rax),%ebx
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xc27(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2bb4(%rip),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%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
@stderr = global i32 0
@.str = [18 x i8] c"socket error: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [16 x i8] c"bind error: %s\0A\00"
@IP_MAXPACKET = global i32 0
@.str.2 = [20 x i8] c"recvfrom error: %s\0A\00"
@.str.3 = [51 x i8] c"Received UDP packet from IP address: %s, port: %d\0A\00"
@.str.4 = [48 x i8] c"%ld-byte message: +%d.%d.%d.%d/%d distance %d+\0A\00"
@.str.5 = [11 x i8] c"Thank you!\00"
@.str.6 = [18 x i8] c"sendto error: %s\0A\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca [20 x i8]
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
store i32 0, i32* %1
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %0
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
store i32 %25, i32* %1
br label %119
26: ; preds = %0
%27 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %28, i32* %29
%30 = call i32 @htons(i32 54321)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %30, i32* %31
%32 = load i32, i32* @INADDR_ANY
%33 = call i32 @htonl(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
store i32 %33, i32* %35
%36 = load i32, i32* %2
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i64 @bind(i32 %36, %struct.sockaddr* %37, i32 12)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %26
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @EXIT_FAILURE
store i32 %45, i32* %1
br label %119
46: ; preds = %26
br label %47
47: ; preds = %118, %46
store i32 12, i32* %5
%48 = load i32, i32* @IP_MAXPACKET
%49 = add nsw i32 %48, 1
%50 = zext i32 %49 to i64
%51 = call i8* @llvm.stacksave()
store i8* %51, i8** %6
%52 = alloca i64, i64 %50
store i64 %50, i64* %7
%53 = load i32, i32* %2
%54 = load i32, i32* @IP_MAXPACKET
%55 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%56 = call i64 @recvfrom(i32 %53, i64* %52, i32 %54, i32 0, %struct.sockaddr* %55, i32* %5)
store i64 %56, i64* %8
%57 = load i64, i64* %8
%58 = icmp ult i64 %57, 0
br i1 %58, label %59, label %65
59: ; preds = %47
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %62)
%64 = load i32, i32* @EXIT_FAILURE
store i32 %64, i32* %1
store i32 1, i32* %9
br label %115
65: ; preds = %47
%66 = load i32, i32* @AF_INET
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%68 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%69 = call i32 @inet_ntop(i32 %66, %struct.TYPE_2__* %67, i8* %68, i32 20)
%70 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%72 = load i32, i32* %71
%73 = call i32 @ntohs(i32 %72)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i8* %70, i32 %73)
%75 = load i64, i64* %8
%76 = getelementptr inbounds i64, i64* %52, i64 %75
store i64 0, i64* %76
%77 = getelementptr inbounds i64, i64* %52, i64 5
%78 = bitcast i64* %77 to i8*
store i8* %78, i8** %11
%79 = load i8*, i8** %11
%80 = bitcast i8* %79 to i32*
%81 = load i32, i32* %80
%82 = call i32 @bswap_32(i32 %81)
store i32 %82, i32* %12
%83 = load i64, i64* %8
%84 = getelementptr inbounds i64, i64* %52, i64 0
%85 = load i64, i64* %84
%86 = getelementptr inbounds i64, i64* %52, i64 1
%87 = load i64, i64* %86
%88 = getelementptr inbounds i64, i64* %52, i64 2
%89 = load i64, i64* %88
%90 = getelementptr inbounds i64, i64* %52, i64 3
%91 = load i64, i64* %90
%92 = getelementptr inbounds i64, i64* %52, i64 4
%93 = load i64, i64* %92
%94 = load i32, i32* %12
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i64 %83, i64 %85, i64 %87, i64 %89, i64 %91, i64 %93, i32 %94)
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8** %13
%96 = load i8*, i8** %13
%97 = call i64 @strlen(i8* %96)
store i64 %97, i64* %14
%98 = load i32, i32* %2
%99 = load i8*, i8** %13
%100 = load i64, i64* %14
%101 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%102 = load i32, i32* %5
%103 = call i64 @sendto(i32 %98, i8* %99, i64 %100, i32 0, %struct.sockaddr* %101, i32 %102)
%104 = load i64, i64* %14
%105 = icmp ne i64 %103, %104
br i1 %105, label %106, label %112
106: ; preds = %65
%107 = load i32, i32* @stderr
%108 = load i32, i32* @errno
%109 = call i8* @strerror(i32 %108)
%110 = call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %109)
%111 = load i32, i32* @EXIT_FAILURE
store i32 %111, i32* %1
store i32 1, i32* %9
br label %115
112: ; preds = %65
%113 = load i32, i32* @stdout
%114 = call i32 @fflush(i32 %113)
store i32 0, i32* %9
br label %115
115: ; preds = %112, %106, %59
%116 = load i8*, i8** %6
%117 = load i32, i32* %9
switch i32 %117, label %121 [
i32 0, label %118
i32 1, label %119
]
118: ; preds = %115
br label %47
119: ; preds = %115, %40, %20
%120 = load i32, i32* %1
ret i32 %120
121: ; preds = %115
unreachable
}

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
@stderr = global i32 0
@.str = [18 x i8] c"socket error: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [16 x i8] c"bind error: %s\0A\00"
@IP_MAXPACKET = global i32 0
@.str.3 = [51 x i8] c"Received UDP packet from IP address: %s, port: %d\0A\00"
@.str.4 = [48 x i8] c"%ld-byte message: +%d.%d.%d.%d/%d distance %d+\0A\00"
@.str.5 = [11 x i8] c"Thank you!\00"
@.str.6 = [18 x i8] c"sendto error: %s\0A\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [20 x i8]
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
br label %83
15: ; preds = %0
%16 = bitcast %struct.sockaddr_in* %1 to i8*
%17 = call i32 @bzero(%struct.sockaddr_in* %1, 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 = tail call i32 @htons(i32 54321)
%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 = tail 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 i64 @bind(i32 %7, %struct.sockaddr* %25, i32 12)
%27 = icmp slt i64 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %15
%29 = bitcast %struct.sockaddr_in* %2 to i8*
%30 = bitcast i32* %3 to i8*
%31 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
br label %41
35: ; preds = %15
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
br label %81
41: ; preds = %28, %78
store i32 12, i32* %3
%42 = load i32, i32* @IP_MAXPACKET
%43 = add nsw i32 %42, 1
%44 = zext i32 %43 to i64
%45 = call i8* @llvm.stacksave()
%46 = alloca i64, i64 %44
%47 = load i32, i32* @IP_MAXPACKET
%48 = call i64 @recvfrom(i32 %7, i64* %46, i32 %47, i32 0, %struct.sockaddr* %31, i32* %3)
%49 = load i32, i32* @AF_INET
%50 = call i32 @inet_ntop(i32 %49, %struct.TYPE_2__* %33, i8* %32, i32 20)
%51 = load i32, i32* %34
%52 = call i32 @ntohs(i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i8* %32, i32 %52)
%54 = getelementptr inbounds i64, i64* %46, i64 %48
store i64 0, i64* %54
%55 = getelementptr inbounds i64, i64* %46, i64 5
%56 = bitcast i64* %55 to i32*
%57 = load i32, i32* %56
%58 = call i32 @bswap_32(i32 %57)
%59 = load i64, i64* %46
%60 = getelementptr inbounds i64, i64* %46, i64 1
%61 = load i64, i64* %60
%62 = getelementptr inbounds i64, i64* %46, i64 2
%63 = load i64, i64* %62
%64 = getelementptr inbounds i64, i64* %46, i64 3
%65 = load i64, i64* %64
%66 = getelementptr inbounds i64, i64* %46, i64 4
%67 = load i64, i64* %66
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i64 %48, i64 %59, i64 %61, i64 %63, i64 %65, i64 %67, i32 %58)
%69 = load i32, i32* %3
%70 = call i64 @sendto(i32 %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i64 10, i32 0, %struct.sockaddr* %31, i32 %69)
%71 = icmp eq i64 %70, 10
br i1 %71, label %78, label %72
72: ; preds = %41
%73 = load i32, i32* @stderr
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %75)
%77 = load i32, i32* @EXIT_FAILURE
br label %81
78: ; preds = %41
%79 = load i32, i32* @stdout
%80 = call i32 @fflush(i32 %79)
br label %41
81: ; preds = %72, %35
%82 = phi i32 [ %40, %35 ], [ %77, %72 ]
br label %83
83: ; preds = %81, %9
%84 = phi i32 [ %14, %9 ], [ %82, %81 ]
ret i32 %84
}