#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 */

/* Type definitions */
typedef int /*<<< orphan*/ their_addr;
struct sockaddr_storage {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ ACK;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ dropper2(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int expected_id = 0;
  int sockfd;
  struct addrinfo hints, *servinfo, *p;
  int rv;
  int numbytes;
  struct sockaddr_storage their_addr;
  char buf[261];
  socklen_t addr_len;
  if (argc != 3) {
    fprintf(stderr, "usage: PORT PROBABILITY\n");
    exit(1);
  }
  int probability = atoi(argv[2]);
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_flags = AI_PASSIVE;
  if ((rv = getaddrinfo(NULL, argv[1], &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
    return 1;
  }
  for (p = servinfo; p != NULL; p = p->ai_next) {
    if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
      perror("Receiver: socket");
      continue;
    }
    if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
      close(sockfd);
      perror("Receiver: bind");
      continue;
    }
    break;
  }
  if (p == NULL) {
    fprintf(stderr, "Receiver: failed to bind socket\n");
    return 2;
  }
  freeaddrinfo(servinfo);
  printf("Receiver: waiting to recvfrom...\n");
  while (1) {
    addr_len = sizeof their_addr;
    if ((numbytes = recvfrom(sockfd, buf, 261 - 1, 0,
                             (struct sockaddr *)&their_addr, &addr_len)) ==
        -1) {
      perror("recvfrom");
      exit(1);
    }
    buf[numbytes] = '\0';
    int seq_id = 0;
    sscanf(buf, "%d", &seq_id);
    if (dropper2(probability)) {
      if (seq_id == expected_id) {
        printf("receiver: good id, message: %s", buf);
        expected_id++;
        char ACK[261];
        snprintf(ACK, 10, "%d", seq_id);
        int numbytes;
        if ((numbytes = sendto(sockfd, ACK, sizeof(ACK), 0,
                               (struct sockaddr *)&their_addr,
                               sizeof(their_addr))) == -1) {
          perror("receiver: sendto");
          exit(1);
        }
      } else if (seq_id > expected_id) {
        printf("receiver: Out-of-order message: %s", buf);
      }
    }
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     125b <main+0x4b>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x178(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   1110 <getaddrinfo@plt>
mov    %eax,-0x54(%rbp)
cmp    $0x0,%eax
je     1301 <main+0xf1>
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x298(%rbp)
mov    -0x54(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x298(%rbp),%edi
mov    %rax,%rdx
lea    0xd2b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1537 <main+0x327>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     1398 <main+0x188>
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x50(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%edx
call   1130 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    134b <main+0x13b>
lea    0xce9(%rip),%rdi
call   10d0 <perror@plt>
jmp    1387 <main+0x177>
mov    -0x18(%rbp),%edi
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1382 <main+0x172>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
lea    0xcc3(%rip),%rdi
call   10d0 <perror@plt>
jmp    1387 <main+0x177>
jmp    1398 <main+0x188>
mov    -0x50(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    1309 <main+0xf9>
cmpq   $0x0,-0x50(%rbp)
jne    13c6 <main+0x1b6>
mov    0x2c1e(%rip),%rax
mov    (%rax),%edi
lea    0xc97(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1537 <main+0x327>
mov    -0x48(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
lea    0xc95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x4,-0x174(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x170(%rbp),%rsi
lea    -0x60(%rbp),%r8
mov    $0x104,%edx
xor    %ecx,%ecx
lea    -0x174(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x58(%rbp)
cmp    $0xffffffff,%eax
jne    142a <main+0x21a>
lea    0xc72(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movslq -0x58(%rbp),%rax
movb   $0x0,-0x170(%rbp,%rax,1)
movl   $0x0,-0x17c(%rbp)
lea    -0x170(%rbp),%rdi
lea    0xc48(%rip),%rsi
lea    -0x17c(%rbp),%rdx
call   10b0 <sscanf@plt>
mov    -0x178(%rbp),%edi
call   1100 <dropper2@plt>
cmp    $0x0,%rax
je     1532 <main+0x322>
mov    -0x17c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1504 <main+0x2f4>
lea    -0x170(%rbp),%rsi
lea    0xc0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    -0x290(%rbp),%rdi
mov    -0x17c(%rbp),%ecx
mov    $0xa,%esi
lea    0xbe1(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x18(%rbp),%edi
lea    -0x290(%rbp),%rsi
lea    -0x60(%rbp),%r8
mov    $0x105,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1070 <sendto@plt>
mov    %eax,-0x294(%rbp)
cmp    $0xffffffff,%eax
jne    14ff <main+0x2ef>
lea    0xbc8(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    152d <main+0x31d>
mov    -0x17c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1528 <main+0x318>
lea    -0x170(%rbp),%rsi
lea    0xba8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    152d <main+0x31d>
jmp    1532 <main+0x322>
jmp    13dd <main+0x1cd>
mov    -0x4(%rbp),%eax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x268,%rsp
cmp    $0x3,%edi
jne    14ac <main+0x28c>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   10f0 <atoi@plt>
mov    %eax,%r14d
lea    0x28(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x48(%rsp)
mov    0x8(%rbx),%rsi
lea    0x20(%rsp),%rcx
xor    %edi,%edi
mov    %rbp,%rdx
call   1120 <getaddrinfo@plt>
test   %eax,%eax
je     12c5 <main+0xa5>
mov    0x2d26(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1060 <gai_strerror@plt>
lea    0xd67(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%eax
jmp    1341 <main+0x121>
mov    %r14d,0x14(%rsp)
mov    0x20(%rsp),%rbx
test   %rbx,%rbx
je     1325 <main+0x105>
lea    0xd4f(%rip),%r14
lea    0xd59(%rip),%r12
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   1140 <socket@plt>
mov    %r14,%rdi
cmp    $0xffffffff,%eax
je     1317 <main+0xf7>
mov    %eax,%r15d
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   10d0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1353 <main+0x133>
mov    %r15d,%edi
call   1090 <close@plt>
mov    %r12,%rdi
call   10e0 <perror@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
jne    12e2 <main+0xc2>
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
lea    0xd15(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x2,%eax
add    $0x268,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x20(%rsp),%rdi
call   1130 <freeaddrinfo@plt>
lea    0xd66(%rip),%rdi
call   1030 <puts@plt>
movl   $0x4,0x10(%rsp)
lea    0x50(%rsp),%rsi
lea    0x18(%rsp),%r8
lea    0x10(%rsp),%r9
mov    %r15d,%edi
mov    $0x104,%edx
xor    %ecx,%ecx
call   10b0 <recvfrom@plt>
cmp    $0xffffffff,%eax
mov    0x14(%rsp),%r14d
jne    13af <main+0x18f>
lea    0xccb(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xcbe(%rip),%rbx
lea    0x50(%rsp),%r13
lea    0x18(%rsp),%rbp
xor    %r12d,%r12d
jmp    13f7 <main+0x1d7>
cs nopw 0x0(%rax,%rax,1)
nop
movl   $0x4,0x10(%rsp)
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x104,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
lea    0x10(%rsp),%r9
call   10b0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     1399 <main+0x179>
cltq
movb   $0x0,0x50(%rsp,%rax,1)
movl   $0x0,0xc(%rsp)
mov    %r13,%rdi
mov    %rbx,%rsi
lea    0xc(%rsp),%rdx
call   10c0 <sscanf@plt>
mov    %r14d,%edi
call   1110 <dropper2@plt>
test   %rax,%rax
je     13d0 <main+0x1b0>
cmp    %r12d,0xc(%rsp)
jne    1490 <main+0x270>
lea    0xc46(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%ecx
mov    %rbx,%rdx
lea    0x160(%rsp),%r14
mov    %r14,%rdi
mov    $0xa,%esi
call   1050 <snprintf@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x105,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
mov    $0x4,%r9d
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
je     14cd <main+0x2ad>
add    $0x1,%r12d
mov    0x14(%rsp),%r14d
jmp    13d0 <main+0x1b0>
cs nopw 0x0(%rax,%rax,1)
nop
jle    13d0 <main+0x1b0>
lea    0xc0a(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    13d0 <main+0x1b0>
mov    0x2b15(%rip),%rax
mov    (%rax),%edi
lea    0xb44(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xbc2(%rip),%rdi
jmp    13a0 <main+0x180>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"usage: PORT PROBABILITY\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [17 x i8] c"Receiver: socket\00"
@.str.3 = [15 x i8] c"Receiver: bind\00"
@.str.4 = [33 x i8] c"Receiver: failed to bind socket\0A\00"
@.str.5 = [34 x i8] c"Receiver: waiting to recvfrom...\0A\00"
@.str.6 = [9 x i8] c"recvfrom\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [31 x i8] c"receiver: good id, message: %s\00"
@.str.9 = [17 x i8] c"receiver: sendto\00"
@.str.10 = [35 x i8] c"receiver: Out-of-order message: %s\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 %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.addrinfo*
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.sockaddr_storage
%14 = alloca [261 x i8]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca [261 x i8]
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 3
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %16
%31 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 40)
%32 = load i32, i32* @AF_UNSPEC
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %32, i32* %33
%34 = load i32, i32* @SOCK_DGRAM
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
store i32 %34, i32* %35
%36 = load i32, i32* @AI_PASSIVE
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 6
store i32 %36, i32* %37
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @getaddrinfo(i32* null, i8* %40, %struct.addrinfo* %8, %struct.addrinfo** %9)
store i32 %41, i32* %11
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %26
%44 = load i32, i32* @stderr
%45 = load i32, i32* %11
%46 = call i8* @gai_strerror(i32 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %46)
store i32 1, i32* %3
br label %145
48: ; preds = %26
%49 = load %struct.addrinfo*, %struct.addrinfo** %9
store %struct.addrinfo* %49, %struct.addrinfo** %10
br label %50
50: ; preds = %82, %48
%51 = load %struct.addrinfo*, %struct.addrinfo** %10
%52 = icmp ne %struct.addrinfo* %51, null
br i1 %52, label %53, label %86
53: ; preds = %50
%54 = load %struct.addrinfo*, %struct.addrinfo** %10
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %54, i32 0, i32 4
%56 = load i32, i32* %55
%57 = load %struct.addrinfo*, %struct.addrinfo** %10
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i32 0, i32 3
%59 = load i32, i32* %58
%60 = load %struct.addrinfo*, %struct.addrinfo** %10
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i32 0, i32 2
%62 = load i32, i32* %61
%63 = call i32 @socket(i32 %56, i32 %59, i32 %62)
store i32 %63, i32* %7
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %67
65: ; preds = %53
%66 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %82
67: ; preds = %53
%68 = load i32, i32* %7
%69 = load %struct.addrinfo*, %struct.addrinfo** %10
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 1
%71 = load i32, i32* %70
%72 = load %struct.addrinfo*, %struct.addrinfo** %10
%73 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = call i32 @bind(i32 %68, i32 %71, i32 %74)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %81
77: ; preds = %67
%78 = load i32, i32* %7
%79 = call i32 @close(i32 %78)
%80 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %82
81: ; preds = %67
br label %86
82: ; preds = %77, %65
%83 = load %struct.addrinfo*, %struct.addrinfo** %10
%84 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %83, i32 0, i32 5
%85 = load %struct.addrinfo*, %struct.addrinfo** %84
store %struct.addrinfo* %85, %struct.addrinfo** %10
br label %50
86: ; preds = %81, %50
%87 = load %struct.addrinfo*, %struct.addrinfo** %10
%88 = icmp eq %struct.addrinfo* %87, null
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load i32, i32* @stderr
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %145
92: ; preds = %86
%93 = load %struct.addrinfo*, %struct.addrinfo** %9
%94 = call i32 @freeaddrinfo(%struct.addrinfo* %93)
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %96
96: ; preds = %92, %144
store i32 4, i32* %15
%97 = load i32, i32* %7
%98 = getelementptr inbounds [261 x i8], [261 x i8]* %14, i64 0, i64 0
%99 = bitcast %struct.sockaddr_storage* %13 to %struct.sockaddr*
%100 = call i32 @recvfrom(i32 %97, i8* %98, i32 260, i32 0, %struct.sockaddr* %99, i32* %15)
store i32 %100, i32* %12
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %105
102: ; preds = %96
%103 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %96
%106 = load i32, i32* %12
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [261 x i8], [261 x i8]* %14, i64 0, i64 %107
store i8 0, i8* %108
store i32 0, i32* %17
%109 = getelementptr inbounds [261 x i8], [261 x i8]* %14, i64 0, i64 0
%110 = call i32 @sscanf(i8* %109, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %17)
%111 = load i32, i32* %16
%112 = call i64 @dropper2(i32 %111)
%113 = icmp ne i64 %112, 0
br i1 %113, label %114, label %144
114: ; preds = %105
%115 = load i32, i32* %17
%116 = load i32, i32* %6
%117 = icmp eq i32 %115, %116
br i1 %117, label %118, label %135
118: ; preds = %114
%119 = getelementptr inbounds [261 x i8], [261 x i8]* %14, i64 0, i64 0
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %119)
%121 = load i32, i32* %6
%122 = add nsw i32 %121, 1
store i32 %122, i32* %6
%123 = getelementptr inbounds [261 x i8], [261 x i8]* %18, i64 0, i64 0
%124 = load i32, i32* %17
%125 = call i32 @snprintf(i8* %123, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %124)
%126 = load i32, i32* %7
%127 = getelementptr inbounds [261 x i8], [261 x i8]* %18, i64 0, i64 0
%128 = bitcast %struct.sockaddr_storage* %13 to %struct.sockaddr*
%129 = call i32 @sendto(i32 %126, i8* %127, i32 261, i32 0, %struct.sockaddr* %128, i32 4)
store i32 %129, i32* %19
%130 = icmp eq i32 %129, -1
br i1 %130, label %131, label %134
131: ; preds = %118
%132 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%133 = call i32 @exit(i32 1)
unreachable
134: ; preds = %118
br label %143
135: ; preds = %114
%136 = load i32, i32* %17
%137 = load i32, i32* %6
%138 = icmp sgt i32 %136, %137
br i1 %138, label %139, label %142
139: ; preds = %135
%140 = getelementptr inbounds [261 x i8], [261 x i8]* %14, i64 0, i64 0
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0), i8* %140)
br label %142
142: ; preds = %139, %135
br label %143
143: ; preds = %142, %134
br label %144
144: ; preds = %143, %105
br label %96
145: ; preds = %89, %43
%146 = load i32, i32* %3
ret i32 %146
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"usage: PORT PROBABILITY\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [17 x i8] c"Receiver: socket\00"
@.str.3 = [15 x i8] c"Receiver: bind\00"
@.str.4 = [33 x i8] c"Receiver: failed to bind socket\0A\00"
@.str.6 = [9 x i8] c"recvfrom\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [31 x i8] c"receiver: good id, message: %s\00"
@.str.9 = [17 x i8] c"receiver: sendto\00"
@.str.10 = [35 x i8] c"receiver: Out-of-order message: %s\00"
@str = [33 x i8] c"Receiver: waiting to recvfrom...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.sockaddr_storage
%6 = alloca [261 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca [261 x i8]
%10 = bitcast %struct.addrinfo* %3 to i8*
%11 = bitcast %struct.addrinfo** %4 to i8*
%12 = bitcast %struct.sockaddr_storage* %5 to i8*
%13 = getelementptr inbounds [261 x i8], [261 x i8]* %6, i64 0, i64 0
%14 = bitcast i32* %7 to i8*
%15 = icmp eq i32 %0, 3
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 40)
%25 = load i32, i32* @AF_UNSPEC
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %25, i32* %26
%27 = load i32, i32* @SOCK_DGRAM
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %27, i32* %28
%29 = load i32, i32* @AI_PASSIVE
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 6
store i32 %29, i32* %30
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @getaddrinfo(i32* null, i8* %32, %struct.addrinfo* %3, %struct.addrinfo** %4)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %20
%36 = load %struct.addrinfo*, %struct.addrinfo** %4
%37 = icmp eq %struct.addrinfo* %36, null
br i1 %37, label %67, label %42
38: ; preds = %20
%39 = load i32, i32* @stderr
%40 = call i8* @gai_strerror(i32 %33)
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %113
42: ; preds = %35, %61
%43 = phi %struct.addrinfo* [ %65, %61 ], [ %36, %35 ]
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 4
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 3
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 2
%49 = load i32, i32* %48
%50 = call i32 @socket(i32 %45, i32 %47, i32 %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %61, label %52
52: ; preds = %42
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 1
%54 = load i32, i32* %53
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @bind(i32 %50, i32 %54, i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %70
59: ; preds = %52
%60 = call i32 @close(i32 %50)
br label %61
61: ; preds = %42, %59
%62 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %59 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %42 ]
%63 = call i32 @perror(i8* %62)
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 5
%65 = load %struct.addrinfo*, %struct.addrinfo** %64
%66 = icmp eq %struct.addrinfo* %65, null
br i1 %66, label %67, label %42
67: ; preds = %61, %35
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %113
70: ; preds = %52
%71 = load %struct.addrinfo*, %struct.addrinfo** %4
%72 = call i32 @freeaddrinfo(%struct.addrinfo* %71)
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%74 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
store i32 4, i32* %7
%75 = call i32 @recvfrom(i32 %50, i8* %13, i32 260, i32 0, %struct.sockaddr* %74, i32* %7)
%76 = icmp eq i32 %75, -1
br i1 %76, label %80, label %77
77: ; preds = %70
%78 = bitcast i32* %8 to i8*
%79 = getelementptr inbounds [261 x i8], [261 x i8]* %9, i64 0, i64 0
br label %83
80: ; preds = %109, %70
%81 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %77, %109
%84 = phi i32 [ %75, %77 ], [ %111, %109 ]
%85 = phi i32 [ 0, %77 ], [ %110, %109 ]
%86 = sext i32 %84 to i64
%87 = getelementptr inbounds [261 x i8], [261 x i8]* %6, i64 0, i64 %86
store i8 0, i8* %87
store i32 0, i32* %8
%88 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %8)
%89 = call i64 @dropper2(i32 %23)
%90 = icmp eq i64 %89, 0
br i1 %90, label %109, label %91
91: ; preds = %83
%92 = load i32, i32* %8
%93 = icmp eq i32 %92, %85
br i1 %93, label %94, label %105
94: ; preds = %91
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %13)
%96 = load i32, i32* %8
%97 = call i32 @snprintf(i8* %79, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %96)
%98 = call i32 @sendto(i32 %50, i8* %79, i32 261, i32 0, %struct.sockaddr* %74, i32 4)
%99 = icmp eq i32 %98, -1
br i1 %99, label %100, label %103
100: ; preds = %94
%101 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%102 = call i32 @exit(i32 1)
unreachable
103: ; preds = %94
%104 = add nsw i32 %85, 1
br label %109
105: ; preds = %91
%106 = icmp sgt i32 %92, %85
br i1 %106, label %107, label %109
107: ; preds = %105
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0), i8* %13)
br label %109
109: ; preds = %103, %107, %105, %83
%110 = phi i32 [ %104, %103 ], [ %85, %107 ], [ %85, %105 ], [ %85, %83 ]
store i32 4, i32* %7
%111 = call i32 @recvfrom(i32 %50, i8* %13, i32 260, i32 0, %struct.sockaddr* %74, i32* %7)
%112 = icmp eq i32 %111, -1
br i1 %112, label %80, label %83
113: ; preds = %67, %38
%114 = phi i32 [ 1, %38 ], [ 2, %67 ]
ret i32 %114
}