#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int sock;
  int addr_len;
  int numbytes;
  char buff_in[100];
  struct sockaddr_in my_addr;
  struct sockaddr_in their_addr;
  FILE *directory;
  directory = fopen("directory.txt", "w");
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("Unable to open socket ");
    exit(1);
  }
  my_addr.sin_family = AF_INET;
  my_addr.sin_port = htons(3745);
  my_addr.sin_addr.s_addr = INADDR_ANY;
  memset(&(my_addr.sin_zero), '\0', 8);
  if (bind(sock, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {
    perror("Unable to bind UDP socket to the assigned port");
    exit(1);
  } else
    addr_len = sizeof(struct sockaddr);
  int peer_in = 0;
  for (peer_in = 1; peer_in < 5; peer_in++) {
    if ((numbytes = recvfrom(sock, buff_in, 100 - 1, 0,
                             (struct sockaddr *)&their_addr, &addr_len)) ==
        -1) {
      perror("Error receiving from the peers \n");
      exit(1);
    }
    buff_in[numbytes] = '\0';
    fprintf(directory, "%s\n", buff_in);
    char p = (char)peer_in;
    if (buff_in[0] == 'p' && buff_in[1] == 'e' && buff_in[2] == 'e' &&
        buff_in[3] == 'r')
      printf("Peer%d registration is done successfully!\n", peer_in);
    else
      perror("Unable to register peers");
  }
  printf("Registration of peers completed!\n");
  printf("Run the content_providers!\n");
  fclose(directory);
  int provider_in = 0;
  for (provider_in = 1; provider_in < 3; provider_in++) {
    if ((numbytes = recvfrom(sock, buff_in, 100 - 1, 0,
                             (struct sockaddr *)&their_addr, &addr_len)) ==
        -1) {
      perror("Error receiving from providers \n");
      exit(1);
    }
    buff_in[numbytes] = '\0';
    printf("Incoming message from content_provider%d\n", provider_in);
    if (buff_in[0] == 'p' && buff_in[1] == 'r' && buff_in[2] == 'o' &&
        buff_in[3] == 'v' && buff_in[4] == 'i' && buff_in[5] == 'd' &&
        buff_in[6] == 'e' && buff_in[7] == 'r')
      printf("Provider%d registration is done successfully!\n", provider_in);
    else
      printf("Provider registration unsuccessfully!\n");
  }
  printf("Registration of providers completed!\n");
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe27(%rip),%rdi
lea    0xe2e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0xa8(%rbp)
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1227 <main+0x67>
lea    0xdf8(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    $0xea1,%edi
call   1040 <htons@plt>
mov    %eax,-0x88(%rbp)
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x4,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    129b <main+0xdb>
lea    0xd9b(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0x4,-0xc(%rbp)
movl   $0x0,-0xac(%rbp)
movl   $0x1,-0xac(%rbp)
cmpl   $0x5,-0xac(%rbp)
jge    13a1 <main+0x1e1>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0xa0(%rbp),%r8
mov    $0x63,%edx
xor    %ecx,%ecx
lea    -0xc(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    1303 <main+0x143>
lea    0xd62(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0xa8(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xd59(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0xac(%rbp),%eax
mov    %al,-0xad(%rbp)
movsbl -0x80(%rbp),%eax
cmp    $0x70,%eax
jne    137c <main+0x1bc>
movsbl -0x7f(%rbp),%eax
cmp    $0x65,%eax
jne    137c <main+0x1bc>
movsbl -0x7e(%rbp),%eax
cmp    $0x65,%eax
jne    137c <main+0x1bc>
movsbl -0x7d(%rbp),%eax
cmp    $0x72,%eax
jne    137c <main+0x1bc>
mov    -0xac(%rbp),%esi
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1388 <main+0x1c8>
lea    0xd23(%rip),%rdi
call   10c0 <perror@plt>
jmp    138d <main+0x1cd>
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    12b6 <main+0xf6>
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xa8(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0xb4(%rbp)
movl   $0x1,-0xb4(%rbp)
cmpl   $0x3,-0xb4(%rbp)
jge    14ef <main+0x32f>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0xa0(%rbp),%r8
mov    $0x63,%edx
xor    %ecx,%ecx
lea    -0xc(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    142a <main+0x26a>
lea    0xce2(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0xb4(%rbp),%esi
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0x80(%rbp),%eax
cmp    $0x70,%eax
jne    14c8 <main+0x308>
movsbl -0x7f(%rbp),%eax
cmp    $0x72,%eax
jne    14c8 <main+0x308>
movsbl -0x7e(%rbp),%eax
cmp    $0x6f,%eax
jne    14c8 <main+0x308>
movsbl -0x7d(%rbp),%eax
cmp    $0x76,%eax
jne    14c8 <main+0x308>
movsbl -0x7c(%rbp),%eax
cmp    $0x69,%eax
jne    14c8 <main+0x308>
movsbl -0x7b(%rbp),%eax
cmp    $0x64,%eax
jne    14c8 <main+0x308>
movsbl -0x7a(%rbp),%eax
cmp    $0x65,%eax
jne    14c8 <main+0x308>
movsbl -0x79(%rbp),%eax
cmp    $0x72,%eax
jne    14c8 <main+0x308>
mov    -0xb4(%rbp),%esi
lea    0xc8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14d6 <main+0x316>
lea    0xca8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14db <main+0x31b>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    13dd <main+0x21d>
lea    0xca8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xa0,%rsp
lea    0xe1e(%rip),%rdi
lea    0xe25(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r14
mov    0x2df0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     1591 <main+0x3c1>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x2c(%rsp)
mov    $0xea1,%edi
call   1050 <htons@plt>
mov    %eax,0x28(%rsp)
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     159a <main+0x3ca>
movl   $0x4,0xc(%rsp)
lea    0x30(%rsp),%rsi
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    $0x63,%edx
xor    %ecx,%ecx
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     157f <main+0x3af>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xdd9(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    %r14,%rdi
call   1090 <fprintf@plt>
movdqa 0x30(%rsp),%xmm0
movd   %xmm0,%eax
cmp    $0x72656570,%eax
jne    153b <main+0x36b>
lea    0xdb4(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x30(%rsp),%rsi
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    $0x63,%edx
xor    %ecx,%ecx
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     157f <main+0x3af>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xd70(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    %r14,%rdi
call   1090 <fprintf@plt>
movdqa 0x30(%rsp),%xmm0
movd   %xmm0,%eax
cmp    $0x72656570,%eax
jne    154c <main+0x37c>
lea    0xd4b(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x30(%rsp),%rsi
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    $0x63,%edx
xor    %ecx,%ecx
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     157f <main+0x3af>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xd07(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    %r14,%rdi
call   1090 <fprintf@plt>
movdqa 0x30(%rsp),%xmm0
movd   %xmm0,%eax
cmp    $0x72656570,%eax
jne    155d <main+0x38d>
lea    0xce2(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x30(%rsp),%rsi
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    $0x63,%edx
xor    %ecx,%ecx
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     157f <main+0x3af>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xc9e(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    %r14,%rdi
call   1090 <fprintf@plt>
movdqa 0x30(%rsp),%xmm0
movd   %xmm0,%eax
cmp    $0x72656570,%eax
jne    156e <main+0x39e>
lea    0xc79(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd24(%rip),%rdi
call   1030 <puts@plt>
lea    0xd39(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0x30(%rsp),%rsi
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    $0x63,%edx
xor    %ecx,%ecx
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     1588 <main+0x3b8>
movabs $0x72656469766f7270,%rbx
64 65 72
cltq
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xc74(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movq   0x30(%rsp),%xmm0
movq   %xmm0,%rax
cmp    %rbx,%rax
jne    149d <main+0x2cd>
lea    0xc7b(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    14a9 <main+0x2d9>
lea    0xcf6(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rsi
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    $0x63,%edx
xor    %ecx,%ecx
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     1588 <main+0x3b8>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xc03(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movq   0x30(%rsp),%xmm0
movq   %xmm0,%rax
cmp    %rbx,%rax
jne    150e <main+0x33e>
lea    0xc0a(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    151a <main+0x34a>
lea    0xc85(%rip),%rdi
call   1030 <puts@plt>
lea    0xc54(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xb64(%rip),%rdi
call   10d0 <perror@plt>
jmp    12d3 <main+0x103>
lea    0xb53(%rip),%rdi
call   10d0 <perror@plt>
jmp    133c <main+0x16c>
lea    0xb42(%rip),%rdi
call   10d0 <perror@plt>
jmp    13a5 <main+0x1d5>
lea    0xb31(%rip),%rdi
call   10d0 <perror@plt>
jmp    140e <main+0x23e>
lea    0xad0(%rip),%rdi
jmp    15a1 <main+0x3d1>
lea    0xb30(%rip),%rdi
jmp    15a1 <main+0x3d1>
lea    0xa78(%rip),%rdi
jmp    15a1 <main+0x3d1>
lea    0xa86(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"directory.txt\00"
@.str.1 = [2 x i8] c"w\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [23 x i8] c"Unable to open socket \00"
@INADDR_ANY = global i32 0
@.str.3 = [47 x i8] c"Unable to bind UDP socket to the assigned port\00"
@.str.4 = [33 x i8] c"Error receiving from the peers \0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [43 x i8] c"Peer%d registration is done successfully!\0A\00"
@.str.7 = [25 x i8] c"Unable to register peers\00"
@.str.8 = [34 x i8] c"Registration of peers completed!\0A\00"
@.str.9 = [28 x i8] c"Run the content_providers!\0A\00"
@.str.10 = [33 x i8] c"Error receiving from providers \0A\00"
@.str.11 = [42 x i8] c"Incoming message from content_provider%d\0A\00"
@.str.12 = [47 x i8] c"Provider%d registration is done successfully!\0A\00"
@.str.13 = [39 x i8] c"Provider registration unsuccessfully!\0A\00"
@.str.14 = [38 x i8] c"Registration of providers completed!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32
store i32 0, i32* %1
%12 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %2
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 3
store i32 %21, i32* %22
%23 = call i32 @htons(i32 3745)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%29 = call i32 @memset(i32* %28, i8 signext 0, i32 8)
%30 = load i32, i32* %2
%31 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%32 = call i32 @bind(i32 %30, %struct.sockaddr* %31, i32 4)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %20
%35 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %20
store i32 4, i32* %3
br label %38
38: ; preds = %37
store i32 0, i32* %9
store i32 1, i32* %9
br label %39
39: ; preds = %85, %38
%40 = load i32, i32* %9
%41 = icmp slt i32 %40, 5
br i1 %41, label %42, label %88
42: ; preds = %39
%43 = load i32, i32* %2
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%45 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%46 = call i32 @recvfrom(i32 %43, i8* %44, i32 99, i32 0, %struct.sockaddr* %45, i32* %3)
store i32 %46, i32* %4
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %42
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %53
store i8 0, i8* %54
%55 = load i32*, i32** %8
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%57 = call i32 @fprintf(i32* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %56)
%58 = load i32, i32* %9
%59 = trunc i32 %58 to i8
store i8 %59, i8* %10
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 112
br i1 %63, label %64, label %82
64: ; preds = %51
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 1
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp eq i32 %67, 101
br i1 %68, label %69, label %82
69: ; preds = %64
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 2
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 101
br i1 %73, label %74, label %82
74: ; preds = %69
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 3
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 114
br i1 %78, label %79, label %82
79: ; preds = %74
%80 = load i32, i32* %9
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %80)
br label %84
82: ; preds = %74, %69, %64, %51
%83 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %84
84: ; preds = %82, %79
br label %85
85: ; preds = %84
%86 = load i32, i32* %9
%87 = add nsw i32 %86, 1
store i32 %87, i32* %9
br label %39
88: ; preds = %39
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0))
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%91 = load i32*, i32** %8
%92 = call i32 @fclose(i32* %91)
store i32 0, i32* %11
store i32 1, i32* %11
br label %93
93: ; preds = %156, %88
%94 = load i32, i32* %11
%95 = icmp slt i32 %94, 3
br i1 %95, label %96, label %159
96: ; preds = %93
%97 = load i32, i32* %2
%98 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%99 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%100 = call i32 @recvfrom(i32 %97, i8* %98, i32 99, i32 0, %struct.sockaddr* %99, i32* %3)
store i32 %100, i32* %4
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %105
102: ; preds = %96
%103 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %96
%106 = load i32, i32* %4
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %107
store i8 0, i8* %108
%109 = load i32, i32* %11
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i32 %109)
%111 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%112 = load i8, i8* %111
%113 = sext i8 %112 to i32
%114 = icmp eq i32 %113, 112
br i1 %114, label %115, label %153
115: ; preds = %105
%116 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 1
%117 = load i8, i8* %116
%118 = sext i8 %117 to i32
%119 = icmp eq i32 %118, 114
br i1 %119, label %120, label %153
120: ; preds = %115
%121 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 2
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = icmp eq i32 %123, 111
br i1 %124, label %125, label %153
125: ; preds = %120
%126 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 3
%127 = load i8, i8* %126
%128 = sext i8 %127 to i32
%129 = icmp eq i32 %128, 118
br i1 %129, label %130, label %153
130: ; preds = %125
%131 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 4
%132 = load i8, i8* %131
%133 = sext i8 %132 to i32
%134 = icmp eq i32 %133, 105
br i1 %134, label %135, label %153
135: ; preds = %130
%136 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 5
%137 = load i8, i8* %136
%138 = sext i8 %137 to i32
%139 = icmp eq i32 %138, 100
br i1 %139, label %140, label %153
140: ; preds = %135
%141 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 6
%142 = load i8, i8* %141
%143 = sext i8 %142 to i32
%144 = icmp eq i32 %143, 101
br i1 %144, label %145, label %153
145: ; preds = %140
%146 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 7
%147 = load i8, i8* %146
%148 = sext i8 %147 to i32
%149 = icmp eq i32 %148, 114
br i1 %149, label %150, label %153
150: ; preds = %145
%151 = load i32, i32* %11
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0), i32 %151)
br label %155
153: ; preds = %145, %140, %135, %130, %125, %120, %115, %105
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.13, i64 0, i64 0))
br label %155
155: ; preds = %153, %150
br label %156
156: ; preds = %155
%157 = load i32, i32* %11
%158 = add nsw i32 %157, 1
store i32 %158, i32* %11
br label %93
159: ; preds = %93
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.14, i64 0, i64 0))
%161 = load i32, i32* %2
%162 = call i32 @close(i32 %161)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"directory.txt\00"
@.str.1 = [2 x i8] c"w\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [23 x i8] c"Unable to open socket \00"
@INADDR_ANY = global i32 0
@.str.3 = [47 x i8] c"Unable to bind UDP socket to the assigned port\00"
@.str.4 = [33 x i8] c"Error receiving from the peers \0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [43 x i8] c"Peer%d registration is done successfully!\0A\00"
@.str.7 = [25 x i8] c"Unable to register peers\00"
@.str.10 = [33 x i8] c"Error receiving from providers \0A\00"
@.str.11 = [42 x i8] c"Incoming message from content_provider%d\0A\00"
@.str.12 = [47 x i8] c"Provider%d registration is done successfully!\0A\00"
@str = [33 x i8] c"Registration of peers completed!\00"
@str.15 = [27 x i8] c"Run the content_providers!\00"
@str.16 = [37 x i8] c"Registration of providers completed!\00"
@str.17 = [38 x i8] c"Provider registration unsuccessfully!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %1 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 3745)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%25 = call i32 @memset(i32* %24, i8 signext 0, i32 8)
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%27 = call i32 @bind(i32 %12, %struct.sockaddr* %26, i32 4)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %17
%30 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %17
store i32 4, i32* %1
%33 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%34 = call i32 @recvfrom(i32 %12, i8* %6, i32 99, i32 0, %struct.sockaddr* %33, i32* %1)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %84, %68, %52, %32
%37 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %32
%40 = sext i32 %34 to i64
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%43 = bitcast [100 x i8]* %2 to <4 x i8>*
%44 = load <4 x i8>, <4 x i8>* %43
%45 = freeze <4 x i8> %44
%46 = bitcast <4 x i8> %45 to i32
%47 = icmp eq i32 %46, 1919247728
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 1)
br label %52
50: ; preds = %39
%51 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %52
52: ; preds = %50, %48
%53 = call i32 @recvfrom(i32 %12, i8* %6, i32 99, i32 0, %struct.sockaddr* %33, i32* %1)
%54 = icmp eq i32 %53, -1
br i1 %54, label %36, label %55
55: ; preds = %52
%56 = sext i32 %53 to i64
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %56
store i8 0, i8* %57
%58 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%59 = bitcast [100 x i8]* %2 to <4 x i8>*
%60 = load <4 x i8>, <4 x i8>* %59
%61 = freeze <4 x i8> %60
%62 = bitcast <4 x i8> %61 to i32
%63 = icmp eq i32 %62, 1919247728
br i1 %63, label %66, label %64
64: ; preds = %55
%65 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %68
66: ; preds = %55
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 2)
br label %68
68: ; preds = %66, %64
%69 = call i32 @recvfrom(i32 %12, i8* %6, i32 99, i32 0, %struct.sockaddr* %33, i32* %1)
%70 = icmp eq i32 %69, -1
br i1 %70, label %36, label %71
71: ; preds = %68
%72 = sext i32 %69 to i64
%73 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %72
store i8 0, i8* %73
%74 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%75 = bitcast [100 x i8]* %2 to <4 x i8>*
%76 = load <4 x i8>, <4 x i8>* %75
%77 = freeze <4 x i8> %76
%78 = bitcast <4 x i8> %77 to i32
%79 = icmp eq i32 %78, 1919247728
br i1 %79, label %82, label %80
80: ; preds = %71
%81 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %84
82: ; preds = %71
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 3)
br label %84
84: ; preds = %82, %80
%85 = call i32 @recvfrom(i32 %12, i8* %6, i32 99, i32 0, %struct.sockaddr* %33, i32* %1)
%86 = icmp eq i32 %85, -1
br i1 %86, label %36, label %87
87: ; preds = %84
%88 = sext i32 %85 to i64
%89 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %88
store i8 0, i8* %89
%90 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%91 = bitcast [100 x i8]* %2 to <4 x i8>*
%92 = load <4 x i8>, <4 x i8>* %91
%93 = freeze <4 x i8> %92
%94 = bitcast <4 x i8> %93 to i32
%95 = icmp eq i32 %94, 1919247728
br i1 %95, label %98, label %96
96: ; preds = %87
%97 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %100
98: ; preds = %87
%99 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 4)
br label %100
100: ; preds = %98, %96
%101 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%102 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.15, i64 0, i64 0))
%103 = call i32 @fclose(i32* %9)
%104 = call i32 @recvfrom(i32 %12, i8* %6, i32 99, i32 0, %struct.sockaddr* %33, i32* %1)
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %109
106: ; preds = %122, %100
%107 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %100
%110 = sext i32 %104 to i64
%111 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %110
store i8 0, i8* %111
%112 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i32 1)
%113 = bitcast [100 x i8]* %2 to <8 x i8>*
%114 = load <8 x i8>, <8 x i8>* %113
%115 = freeze <8 x i8> %114
%116 = bitcast <8 x i8> %115 to i64
%117 = icmp eq i64 %116, 8243105097092919920
br i1 %117, label %118, label %120
118: ; preds = %109
%119 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0), i32 1)
br label %122
120: ; preds = %109
%121 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.17, i64 0, i64 0))
br label %122
122: ; preds = %118, %120
%123 = call i32 @recvfrom(i32 %12, i8* %6, i32 99, i32 0, %struct.sockaddr* %33, i32* %1)
%124 = icmp eq i32 %123, -1
br i1 %124, label %106, label %125
125: ; preds = %122
%126 = sext i32 %123 to i64
%127 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %126
store i8 0, i8* %127
%128 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i32 2)
%129 = bitcast [100 x i8]* %2 to <8 x i8>*
%130 = load <8 x i8>, <8 x i8>* %129
%131 = freeze <8 x i8> %130
%132 = bitcast <8 x i8> %131 to i64
%133 = icmp eq i64 %132, 8243105097092919920
br i1 %133, label %136, label %134
134: ; preds = %125
%135 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.17, i64 0, i64 0))
br label %138
136: ; preds = %125
%137 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0), i32 2)
br label %138
138: ; preds = %136, %134
%139 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.16, i64 0, i64 0))
%140 = call i32 @close(i32 %12)
ret i32 0
}