#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ si_other;
typedef int /*<<< orphan*/ si_me;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char const *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ diep(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ inet_aton(char const *, TYPE_1__ *);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int ntohs(void *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
             int /*<<< orphan*/ *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(int);
int main(int argc, char **argv) {
  int runServer = 0;
  int udpPort = 7000;
  int useLocal = 0;
  int address = htonl(INADDR_ANY);
  struct sockaddr_in si_me, si_other;
  int s, i, slen = sizeof(si_other);
  char buf[512];
  while (argc > 1 && argv[1][0] == '-') {
    const char *optName = argv[1] + 1;
    argc--;
    argv++;
    switch (optName[0]) {
    case 'p':
      udpPort = atoi(optName + 1);
      if (udpPort < 1024 || udpPort > 65535) {
        fprintf(stderr, "UDP port must be between 1024 and 65535\n");
        exit(1);
      }
      break;
    case 's':
      runServer = 1;
      break;
    case 'a':
      if (inet_aton(optName + 1, &si_other.sin_addr) == 0)
        diep("inet_aton");
      address = si_other.sin_addr.s_addr;
      break;
    default:
      usage(1);
    }
  }
  if (runServer) {
    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(udpPort);
    si_me.sin_addr.s_addr = address;
    if (bind(s, (struct sockaddr *)&si_me, sizeof(si_me)) == -1)
      diep("bind");
    printf("UDP server listening on %s:%d\n", inet_ntoa(si_me.sin_addr),
           udpPort);
    for (i = 0; i < 10; i++) {
      if (recvfrom(s, buf, 512, 0, (struct sockaddr *)&si_other,
                   (socklen_t *)&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);
    }
    printf("UDP server closing\n");
    close(s);
  } else {
    if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
      diep("socket");
    memset((char *)&si_other, 0, sizeof(si_other));
    si_other.sin_family = AF_INET;
    si_other.sin_port = htons(udpPort);
    si_other.sin_addr.s_addr = address;
    printf("UDP client sending packets to %s:%d\n",
           inet_ntoa(si_other.sin_addr), udpPort);
    for (i = 0; i < 10; i++) {
      printf("Sending packet %d\n", i);
      sprintf(buf, "This is packet %d\n", i);
      if (sendto(s, buf, 512, 0, (struct sockaddr *)&si_other, slen) == -1)
        diep("sendto()");
    }
    close(s);
    printf("UDP client closing\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1b58,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x20(%rbp)
movl   $0x18,-0x5c(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x8(%rbp)
mov    %al,-0x269(%rbp)
jle    128f <main+0x6f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x269(%rbp)
mov    -0x269(%rbp),%al
test   $0x1,%al
jne    12a2 <main+0x82>
jmp    13b0 <main+0x190>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
add    $0x1,%rax
mov    %rax,-0x268(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x268(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x270(%rbp)
sub    $0x61,%eax
je     136d <main+0x14d>
jmp    12e8 <main+0xc8>
mov    -0x270(%rbp),%eax
sub    $0x70,%eax
je     1310 <main+0xf0>
jmp    12fc <main+0xdc>
mov    -0x270(%rbp),%eax
sub    $0x73,%eax
je     1361 <main+0x141>
jmp    13a1 <main+0x181>
mov    -0x268(%rbp),%rdi
add    $0x1,%rdi
call   1110 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x400,-0x18(%rbp)
jl     133d <main+0x11d>
cmpl   $0xffff,-0x18(%rbp)
jle    135c <main+0x13c>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
lea    0xcb3(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    13ab <main+0x18b>
movl   $0x1,-0x14(%rbp)
jmp    13ab <main+0x18b>
mov    -0x268(%rbp),%rdi
add    $0x1,%rdi
lea    -0x50(%rbp),%rsi
call   10c0 <inet_aton@plt>
cmp    $0x0,%eax
jne    1396 <main+0x176>
lea    0xc98(%rip),%rdi
call   10a0 <diep@plt>
mov    -0x50(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    13ab <main+0x18b>
mov    $0x1,%edi
call   10f0 <usage@plt>
jmp    1266 <main+0x46>
cmpl   $0x0,-0x14(%rbp)
je     1508 <main+0x2e8>
mov    0x2c27(%rip),%rax
mov    (%rax),%rdi
mov    0x2c0d(%rip),%rax
mov    (%rax),%esi
mov    0x2be4(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
mov    %eax,-0x54(%rbp)
cmp    $0xffffffff,%eax
jne    13f3 <main+0x1d3>
lea    0xc45(%rip),%rdi
call   10a0 <diep@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2bde(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x54(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x18,%edx
call   1100 <bind@plt>
cmp    $0xffffffff,%eax
jne    1449 <main+0x229>
lea    0xbf6(%rip),%rdi
call   10a0 <diep@plt>
mov    -0x38(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
mov    -0x18(%rbp),%edx
lea    0xbe1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x58(%rbp)
cmpl   $0xa,-0x58(%rbp)
jge    14ed <main+0x2cd>
mov    -0x54(%rbp),%edi
lea    -0x260(%rbp),%rsi
lea    -0x50(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x5c(%rbp),%r9
call   10d0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    14a9 <main+0x289>
lea    0xbba(%rip),%rdi
call   10a0 <diep@plt>
mov    -0x50(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x278(%rbp)
mov    -0x48(%rbp),%rdi
call   10e0 <ntohs@plt>
mov    -0x278(%rbp),%rsi
mov    %eax,%edx
lea    -0x260(%rbp),%rcx
lea    0xb91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    146c <main+0x24c>
lea    0xb9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x54(%rbp),%edi
call   1090 <close@plt>
jmp    1621 <main+0x401>
mov    0x2ad9(%rip),%rax
mov    (%rax),%rdi
mov    0x2abf(%rip),%rax
mov    (%rax),%esi
mov    0x2a96(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
mov    %eax,-0x54(%rbp)
cmp    $0xffffffff,%eax
jne    1541 <main+0x321>
lea    0xaf7(%rip),%rdi
call   10a0 <diep@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2a90(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
mov    -0x18(%rbp),%edx
lea    0xb1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x58(%rbp)
cmpl   $0xa,-0x58(%rbp)
jge    160b <main+0x3eb>
mov    -0x58(%rbp),%esi
lea    0xb20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x260(%rbp),%rdi
mov    -0x58(%rbp),%edx
lea    0xb1b(%rip),%rsi
call   1120 <sprintf@plt>
mov    -0x54(%rbp),%edi
lea    -0x260(%rbp),%rsi
lea    -0x50(%rbp),%r8
mov    -0x5c(%rbp),%r9d
mov    $0x200,%edx
xor    %ecx,%ecx
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
jne    15f8 <main+0x3d8>
lea    0xafb(%rip),%rdi
call   10a0 <diep@plt>
jmp    15fd <main+0x3dd>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1594 <main+0x374>
mov    -0x54(%rbp),%edi
call   1090 <close@plt>
lea    0xadd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x248,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,%r14d
movl   $0x18,0xc(%rsp)
mov    $0x1b58,%r15d
cmp    $0x2,%ebx
jl     143e <main+0x20e>
add    $0x1,%ebx
add    $0x8,%rbp
xor    %r13d,%r13d
mov    $0x1b58,%r15d
lea    0x10(%rsp),%r12
jmp    12a6 <main+0x76>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
call   1100 <usage@plt>
add    $0xffffffff,%ebx
add    $0x8,%rbp
cmp    $0x2,%ebx
jbe    1318 <main+0xe8>
mov    0x0(%rbp),%rdi
cmpb   $0x2d,(%rdi)
jne    1318 <main+0xe8>
movsbl 0x1(%rdi),%eax
cmp    $0x61,%eax
je     12e0 <main+0xb0>
cmp    $0x73,%eax
je     1310 <main+0xe0>
cmp    $0x70,%eax
jne    1290 <main+0x60>
add    $0x2,%rdi
call   1120 <atoi@plt>
mov    %eax,%r15d
add    $0xffff0000,%eax
cmp    $0xffff03ff,%eax
ja     129a <main+0x6a>
jmp    156e <main+0x33e>
nop
add    $0x2,%rdi
mov    %r12,%rsi
call   10d0 <inet_aton@plt>
test   %eax,%eax
jne    12fc <main+0xcc>
lea    0xd32(%rip),%rdi
call   10b0 <diep@plt>
mov    0x10(%rsp),%r14d
jmp    129a <main+0x6a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%r13d
jmp    129a <main+0x6a>
test   %r13d,%r13d
je     143e <main+0x20e>
mov    0x2cc0(%rip),%r12
mov    (%r12),%rdi
mov    0x2ca5(%rip),%rax
mov    (%rax),%esi
mov    0x2c7c(%rip),%rax
mov    (%rax),%edx
call   1150 <socket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1356 <main+0x126>
lea    0xce2(%rip),%rdi
call   10b0 <diep@plt>
lea    0x28(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x38(%rsp)
mov    %r15d,%edi
call   1050 <htons@plt>
mov    %rax,0x30(%rsp)
mov    %r14d,0x28(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   1110 <bind@plt>
cmp    $0xffffffff,%eax
jne    13a5 <main+0x175>
lea    0xc9a(%rip),%rdi
call   10b0 <diep@plt>
mov    0x28(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xc8a(%rip),%rdi
mov    %rax,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%r14d
lea    0x40(%rsp),%rbx
lea    0xc(%rsp),%r15
lea    0xc90(%rip),%r13
jmp    1412 <main+0x1e2>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%r12
mov    0x18(%rsp),%rdi
call   10f0 <ntohs@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xffffffff,%r14d
je     1547 <main+0x317>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
lea    0x10(%rsp),%r8
mov    %r15,%r9
call   10e0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    13e0 <main+0x1b0>
lea    0xc27(%rip),%rdi
call   10b0 <diep@plt>
jmp    13e0 <main+0x1b0>
mov    0x2ba3(%rip),%rbp
mov    0x0(%rbp),%rdi
mov    0x2b88(%rip),%rax
mov    (%rax),%esi
mov    0x2b5f(%rip),%rax
mov    (%rax),%edx
call   1150 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1473 <main+0x243>
lea    0xbc5(%rip),%rdi
call   10b0 <diep@plt>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x0(%rbp),%rax
mov    %rax,0x20(%rsp)
mov    %r15d,%edi
call   1050 <htons@plt>
mov    %rax,0x18(%rsp)
mov    %r14d,0x10(%rsp)
mov    %r14d,%edi
call   1040 <inet_ntoa@plt>
lea    0xbde(%rip),%rdi
mov    %rax,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xbef(%rip),%r14
lea    0xbfb(%rip),%r15
lea    0x40(%rsp),%rbp
xor    %r13d,%r13d
jmp    14ea <main+0x2ba>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r13d
cmp    $0xa,%r13d
je     1532 <main+0x302>
mov    %r14,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1130 <sprintf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0x18,%r9d
call   1090 <sendto@plt>
cmp    $0xffffffff,%eax
jne    14e0 <main+0x2b0>
lea    0xbaf(%rip),%rdi
call   10b0 <diep@plt>
jmp    14e0 <main+0x2b0>
mov    %ebx,%edi
call   10a0 <close@plt>
lea    0xba3(%rip),%rdi
call   1030 <puts@plt>
jmp    155a <main+0x32a>
lea    0xba8(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x248,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a53(%rip),%rax
mov    (%rax),%edi
lea    0xa82(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_3__, i8*, i8* }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@INADDR_ANY = global i32 0
@stderr = global i32 0
@.str = [41 x i8] c"UDP port must be between 1024 and 65535\0A\00"
@.str.1 = [10 x i8] c"inet_aton\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [31 x i8] c"UDP server listening on %s:%d\0A\00"
@.str.5 = [11 x i8] c"recvfrom()\00"
@.str.6 = [38 x i8] c"Received packet from %s:%d\0AData: %s\0A\0A\00"
@.str.7 = [20 x i8] c"UDP server closing\0A\00"
@.str.8 = [37 x i8] c"UDP client sending packets to %s:%d\0A\00"
@.str.9 = [19 x i8] c"Sending packet %d\0A\00"
@.str.10 = [19 x i8] c"This is packet %d\0A\00"
@.str.11 = [9 x i8] c"sendto()\00"
@.str.12 = [20 x i8] c"UDP client closing\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 i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [512 x i8]
%16 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 7000, i32* %7
store i32 0, i32* %8
%17 = load i32, i32* @INADDR_ANY
%18 = call i32 @htonl(i32 %17)
store i32 %18, i32* %9
store i32 24, i32* %14
br label %19
19: ; preds = %74, %2
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 45
br label %30
30: ; preds = %22, %19
%31 = phi i1 [ false, %19 ], [ %29, %22 ]
br i1 %31, label %32, label %75
32: ; preds = %30
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i64 1
store i8* %36, i8** %16
%37 = load i32, i32* %4
%38 = add nsw i32 %37, -1
store i32 %38, i32* %4
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i32 1
store i8** %40, i8*** %5
%41 = load i8*, i8** %16
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
switch i32 %44, label %72 [
i32 112, label %45
i32 115, label %59
i32 97, label %60
]
45: ; preds = %32
%46 = load i8*, i8** %16
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = call i32 @atoi(i8* %47)
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = icmp slt i32 %49, 1024
br i1 %50, label %54, label %51
51: ; preds = %45
%52 = load i32, i32* %7
%53 = icmp sgt i32 %52, 65535
br i1 %53, label %54, label %58
54: ; preds = %51, %45
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %51
br label %74
59: ; preds = %32
store i32 1, i32* %6
br label %74
60: ; preds = %32
%61 = load i8*, i8** %16
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%64 = call i32 @inet_aton(i8* %62, %struct.TYPE_3__* %63)
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %60
%67 = call i32 @diep(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %68
68: ; preds = %66, %60
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%70 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %69, i32 0, i32 0
%71 = load i32, i32* %70
store i32 %71, i32* %9
br label %74
72: ; preds = %32
%73 = call i32 @usage(i32 1)
br label %74
74: ; preds = %72, %68, %59, %58
br label %19
75: ; preds = %30
%76 = load i32, i32* %6
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %138
78: ; preds = %75
%79 = load i8*, i8** @AF_INET
%80 = load i32, i32* @SOCK_DGRAM
%81 = load i32, i32* @IPPROTO_UDP
%82 = call i32 @socket(i8* %79, i32 %80, i32 %81)
store i32 %82, i32* %12
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %78
%85 = call i32 @diep(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %86
86: ; preds = %84, %78
%87 = bitcast %struct.sockaddr_in* %10 to i8*
%88 = call i32 @memset(i8* %87, i32 0, i32 24)
%89 = load i8*, i8** @AF_INET
%90 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i8* %89, i8** %90
%91 = load i32, i32* %7
%92 = call i8* @htons(i32 %91)
%93 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i8* %92, i8** %93
%94 = load i32, i32* %9
%95 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%96 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %95, i32 0, i32 0
store i32 %94, i32* %96
%97 = load i32, i32* %12
%98 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%99 = call i32 @bind(i32 %97, %struct.sockaddr* %98, i32 24)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %103
101: ; preds = %86
%102 = call i32 @diep(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %103
103: ; preds = %101, %86
%104 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%105 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %104, i32 0, i32 0
%106 = load i32, i32* %105
%107 = call i8* @inet_ntoa(i32 %106)
%108 = load i32, i32* %7
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %107, i32 %108)
store i32 0, i32* %13
br label %110
110: ; preds = %131, %103
%111 = load i32, i32* %13
%112 = icmp slt i32 %111, 10
br i1 %112, label %113, label %134
113: ; preds = %110
%114 = load i32, i32* %12
%115 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%116 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%117 = call i32 @recvfrom(i32 %114, i8* %115, i32 512, i32 0, %struct.sockaddr* %116, i32* %14)
%118 = icmp eq i32 %117, -1
br i1 %118, label %119, label %121
119: ; preds = %113
%120 = call i32 @diep(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %121
121: ; preds = %119, %113
%122 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%123 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %122, i32 0, i32 0
%124 = load i32, i32* %123
%125 = call i8* @inet_ntoa(i32 %124)
%126 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%127 = load i8*, i8** %126
%128 = call i32 @ntohs(i8* %127)
%129 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i8* %125, i32 %128, i8* %129)
br label %131
131: ; preds = %121
%132 = load i32, i32* %13
%133 = add nsw i32 %132, 1
store i32 %133, i32* %13
br label %110
134: ; preds = %110
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%136 = load i32, i32* %12
%137 = call i32 @close(i32 %136)
br label %188
138: ; preds = %75
%139 = load i8*, i8** @AF_INET
%140 = load i32, i32* @SOCK_DGRAM
%141 = load i32, i32* @IPPROTO_UDP
%142 = call i32 @socket(i8* %139, i32 %140, i32 %141)
store i32 %142, i32* %12
%143 = icmp eq i32 %142, -1
br i1 %143, label %144, label %146
144: ; preds = %138
%145 = call i32 @diep(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %146
146: ; preds = %144, %138
%147 = bitcast %struct.sockaddr_in* %11 to i8*
%148 = call i32 @memset(i8* %147, i32 0, i32 24)
%149 = load i8*, i8** @AF_INET
%150 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i8* %149, i8** %150
%151 = load i32, i32* %7
%152 = call i8* @htons(i32 %151)
%153 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i8* %152, i8** %153
%154 = load i32, i32* %9
%155 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%156 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %155, i32 0, i32 0
store i32 %154, i32* %156
%157 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%158 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %157, i32 0, i32 0
%159 = load i32, i32* %158
%160 = call i8* @inet_ntoa(i32 %159)
%161 = load i32, i32* %7
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i8* %160, i32 %161)
store i32 0, i32* %13
br label %163
163: ; preds = %181, %146
%164 = load i32, i32* %13
%165 = icmp slt i32 %164, 10
br i1 %165, label %166, label %184
166: ; preds = %163
%167 = load i32, i32* %13
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %167)
%169 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%170 = load i32, i32* %13
%171 = call i32 @sprintf(i8* %169, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i32 %170)
%172 = load i32, i32* %12
%173 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%174 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%175 = load i32, i32* %14
%176 = call i32 @sendto(i32 %172, i8* %173, i32 512, i32 0, %struct.sockaddr* %174, i32 %175)
%177 = icmp eq i32 %176, -1
br i1 %177, label %178, label %180
178: ; preds = %166
%179 = call i32 @diep(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
br label %180
180: ; preds = %178, %166
br label %181
181: ; preds = %180
%182 = load i32, i32* %13
%183 = add nsw i32 %182, 1
store i32 %183, i32* %13
br label %163
184: ; preds = %163
%185 = load i32, i32* %12
%186 = call i32 @close(i32 %185)
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0))
br label %188
188: ; preds = %184, %134
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_3__, i8*, i8* }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@INADDR_ANY = global i32 0
@stderr = global i32 0
@.str = [41 x i8] c"UDP port must be between 1024 and 65535\0A\00"
@.str.1 = [10 x i8] c"inet_aton\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [31 x i8] c"UDP server listening on %s:%d\0A\00"
@.str.5 = [11 x i8] c"recvfrom()\00"
@.str.6 = [38 x i8] c"Received packet from %s:%d\0AData: %s\0A\0A\00"
@.str.8 = [37 x i8] c"UDP client sending packets to %s:%d\0A\00"
@.str.9 = [19 x i8] c"Sending packet %d\0A\00"
@.str.10 = [19 x i8] c"This is packet %d\0A\00"
@.str.11 = [9 x i8] c"sendto()\00"
@str = [19 x i8] c"UDP client closing\00"
@str.13 = [19 x i8] c"UDP server closing\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = load i32, i32* @INADDR_ANY
%8 = tail call i32 @htonl(i32 %7)
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = bitcast %struct.sockaddr_in* %4 to i8*
%11 = bitcast i32* %5 to i8*
store i32 24, i32* %5
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %105
14: ; preds = %2
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
br label %17
17: ; preds = %14, %51
%18 = phi i32 [ %0, %14 ], [ %29, %51 ]
%19 = phi i32 [ %8, %14 ], [ %54, %51 ]
%20 = phi i8** [ %1, %14 ], [ %23, %51 ]
%21 = phi i32 [ 7000, %14 ], [ %53, %51 ]
%22 = phi i32 [ 0, %14 ], [ %52, %51 ]
%23 = getelementptr inbounds i8*, i8** %20, i64 1
%24 = load i8*, i8** %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 45
br i1 %26, label %27, label %56
27: ; preds = %17
%28 = getelementptr inbounds i8, i8* %24, i64 1
%29 = add nsw i32 %18, -1
%30 = load i8, i8* %28
%31 = sext i8 %30 to i32
switch i32 %31, label %49 [
i32 112, label %32
i32 115, label %51
i32 97, label %41
]
32: ; preds = %27
%33 = getelementptr inbounds i8, i8* %24, i64 2
%34 = call i32 @atoi(i8* %33)
%35 = add i32 %34, -65536
%36 = icmp ult i32 %35, -64512
br i1 %36, label %37, label %51
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %27
%42 = getelementptr inbounds i8, i8* %24, i64 2
%43 = call i32 @inet_aton(i8* %42, %struct.TYPE_3__* %15)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @diep(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45, %41
%48 = load i32, i32* %16
br label %51
49: ; preds = %27
%50 = call i32 @usage(i32 1)
br label %51
51: ; preds = %27, %32, %49, %47
%52 = phi i32 [ %22, %49 ], [ %22, %47 ], [ %22, %32 ], [ 1, %27 ]
%53 = phi i32 [ %21, %49 ], [ %21, %47 ], [ %34, %32 ], [ %21, %27 ]
%54 = phi i32 [ %19, %49 ], [ %48, %47 ], [ %19, %32 ], [ %19, %27 ]
%55 = icmp ugt i32 %18, 2
br i1 %55, label %17, label %56
56: ; preds = %17, %51
%57 = phi i32 [ %22, %17 ], [ %52, %51 ]
%58 = phi i32 [ %21, %17 ], [ %53, %51 ]
%59 = phi i32 [ %19, %17 ], [ %54, %51 ]
%60 = icmp eq i32 %57, 0
br i1 %60, label %105, label %61
61: ; preds = %56
%62 = load i8*, i8** @AF_INET
%63 = load i32, i32* @SOCK_DGRAM
%64 = load i32, i32* @IPPROTO_UDP
%65 = call i32 @socket(i8* %62, i32 %63, i32 %64)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %61
%68 = call i32 @diep(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %69
69: ; preds = %67, %61
%70 = call i32 @memset(i8* %9, i32 0, i32 24)
%71 = load i8*, i8** @AF_INET
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %71, i8** %72
%73 = call i8* @htons(i32 %58)
%74 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i8* %73, i8** %74
%75 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %59, i32* %75
%76 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%77 = call i32 @bind(i32 %65, %struct.sockaddr* %76, i32 24)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %81
79: ; preds = %69
%80 = call i32 @diep(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %81
81: ; preds = %79, %69
%82 = load i32, i32* %75
%83 = call i8* @inet_ntoa(i32 %82)
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %83, i32 %58)
%85 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
%87 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
br label %88
88: ; preds = %81, %94
%89 = phi i32 [ 0, %81 ], [ %100, %94 ]
%90 = call i32 @recvfrom(i32 %65, i8* %12, i32 512, i32 0, %struct.sockaddr* %85, i32* %5)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %94
92: ; preds = %88
%93 = call i32 @diep(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %94
94: ; preds = %92, %88
%95 = load i32, i32* %86
%96 = call i8* @inet_ntoa(i32 %95)
%97 = load i8*, i8** %87
%98 = call i32 @ntohs(i8* %97)
%99 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i8* %96, i32 %98, i8* %12)
%100 = add nuw nsw i32 %89, 1
%101 = icmp eq i32 %100, 10
br i1 %101, label %102, label %88
102: ; preds = %94
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.13, i64 0, i64 0))
%104 = call i32 @close(i32 %65)
br label %139
105: ; preds = %2, %56
%106 = phi i32 [ %59, %56 ], [ %8, %2 ]
%107 = phi i32 [ %58, %56 ], [ 7000, %2 ]
%108 = load i8*, i8** @AF_INET
%109 = load i32, i32* @SOCK_DGRAM
%110 = load i32, i32* @IPPROTO_UDP
%111 = call i32 @socket(i8* %108, i32 %109, i32 %110)
%112 = icmp eq i32 %111, -1
br i1 %112, label %113, label %115
113: ; preds = %105
%114 = call i32 @diep(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %115
115: ; preds = %113, %105
%116 = call i32 @memset(i8* %10, i32 0, i32 24)
%117 = load i8*, i8** @AF_INET
%118 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %117, i8** %118
%119 = call i8* @htons(i32 %107)
%120 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i8* %119, i8** %120
%121 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %106, i32* %121
%122 = call i8* @inet_ntoa(i32 %106)
%123 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i8* %122, i32 %107)
%124 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %125
125: ; preds = %115, %133
%126 = phi i32 [ 0, %115 ], [ %134, %133 ]
%127 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %126)
%128 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0), i32 %126)
%129 = call i32 @sendto(i32 %111, i8* %12, i32 512, i32 0, %struct.sockaddr* %124, i32 24)
%130 = icmp eq i32 %129, -1
br i1 %130, label %131, label %133
131: ; preds = %125
%132 = call i32 @diep(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
br label %133
133: ; preds = %125, %131
%134 = add nuw nsw i32 %126, 1
%135 = icmp eq i32 %134, 10
br i1 %135, label %136, label %125
136: ; preds = %133
%137 = call i32 @close(i32 %111)
%138 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %139
139: ; preds = %136, %102
ret i32 0
}