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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int close(int);
int /*<<< orphan*/ exit(int);
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ print_menu();
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int scanf(char *, ...);
int send(int, char *, int, int /*<<< orphan*/);
int server_connect(int, int const);
int /*<<< orphan*/ sockerror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sockfdes, newsockfdes, portnum, select = 0;
  int r, s, c, pid, i = 0;
  const int port_1 = 2323;
  char buf[256], file[2048], confirm[1];
  char initial_message[2048] = "READY FOR INSTANT MESSAGING";
  FILE *fd;
  if (argc > 2) {
    fprintf(stderr, "usage: %s OR %s Port #: 2323 or 3232 for testing\n",
            argv[0], argv[0]);
    exit(1);
  }
  sockfdes = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfdes < 0)
    sockerror("ERROR, while opening socket!!!");
  if (argc == 1) {
    newsockfdes = server_connect(sockfdes, port_1);
  } else {
    portnum = atoi(argv[1]);
    newsockfdes = server_connect(sockfdes, portnum);
  }
  print_menu();
  int u = 1, established = 0;
  while (u) {
    c = scanf("%d", &select);
    if (select == 1) {
      pid = fork();
      if (pid < 0)
        sockerror("ERROR, during fork!!!");
      if (pid == 0) {
        close(sockfdes);
        while (1) {
          if (established == 0) {
            s = send(newsockfdes, initial_message, sizeof initial_message, 0);
            if (s < 0)
              sockerror("ERROR, write failed!!!");
            ++established;
          } else {
            memset(buf, 0, 255);
            r = recv(newsockfdes, buf, 255, 0);
            if (r < 0) {
              print_menu();
              sockerror("ERROR, read failed!!!");
            }
            printf("\nINCOMING MESSAGE:\n %s", buf);
          }
        }
      } else {
        c = close(newsockfdes);
        if (c < 0)
          sockerror("ERROR, unable to close socket!!!");
      }
    } else if (select == 2) {
      printf("File Transfer Imminent, continue? [y/n]\n");
      c = scanf("%s", confirm);
      pid = fork();
      if (pid < 0)
        sockerror("ERROR, during fork!!!");
      if (pid == 0) {
        close(sockfdes);
        if (strcmp(confirm, "y") == 0) {
          s = send(newsockfdes, "READY FOR FILE TRANSFER\n", 23, 0);
          if (s < 0)
            sockerror("ERROR, send failed!!!");
          memset(file, 0, 2047);
          r = recv(newsockfdes, file, 255, 0);
          if (r < 0)
            sockerror("ERROR, read failed!!!");
          memset(buf, 0, 255);
          fd = fopen(file, "at");
          if (!fd)
            fd = fopen(file, "wt");
          if (!fd) {
            printf("can not open %s for writing.\n", file);
          } else
            printf("file %s created\n", file);
          while (u) {
            memset(file, 0, sizeof file - 1);
            r = recv(newsockfdes, file, 80, 0);
            if (r < 0)
              sockerror("ERROR, read failed!!!");
            fwrite(file, sizeof(char), strlen(file), fd);
            ++i;
            u = r;
          }
          print_menu();
          c = fclose(fd);
          if (c < 0)
            printf("ERROR, unable to close file\n");
          c = close(newsockfdes);
          if (c < 0)
            sockerror("ERROR, unable to close socket\n");
          exit(0);
        } else {
          s = send(newsockfdes, "\0", 2, 0);
          if (s < 0)
            sockerror("ERROR, send failed!!!");
        }
      } else {
        c = close(newsockfdes);
        if (c < 0)
          printf("ERROR, unable to cloose file\n");
        select = 0;
      }
    } else if (select == 3) {
      print_menu();
    } else
      select = 0;
  }
  c = close(sockfdes);
  if (c < 0)
    sockerror("ERROR, unable to close socket!!!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1170,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x913,-0x38(%rbp)
lea    -0x1150(%rbp),%rdi
lea    0xd84(%rip),%rsi
mov    $0x800,%edx
call   10c0 <memcpy@plt>
cmpl   $0x2,-0x8(%rbp)
jle    12bd <main+0x7d>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0x1554(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
mov    0x2d03(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12ef <main+0xaf>
lea    0x154a(%rip),%rdi
call   1150 <sockerror@plt>
cmpl   $0x1,-0x8(%rbp)
jne    130e <main+0xce>
mov    -0x14(%rbp),%edi
mov    $0x913,%esi
call   10f0 <server_connect@plt>
mov    %eax,-0x18(%rbp)
jmp    132c <main+0xec>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10f0 <server_connect@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   10d0 <print_menu@plt>
movl   $0x1,-0x115c(%rbp)
movl   $0x0,-0x1160(%rbp)
cmpl   $0x0,-0x115c(%rbp)
je     178e <main+0x54e>
lea    0x14f8(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   10e0 <scanf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    1483 <main+0x243>
mov    $0x0,%al
call   1140 <fork@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1393 <main+0x153>
lea    0x14c8(%rip),%rdi
call   1150 <sockerror@plt>
cmpl   $0x0,-0x30(%rbp)
jne    1458 <main+0x218>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
cmpl   $0x0,-0x1160(%rbp)
jne    13f5 <main+0x1b5>
mov    -0x18(%rbp),%edi
lea    -0x1150(%rbp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    13e1 <main+0x1a1>
lea    0x1490(%rip),%rdi
call   1150 <sockerror@plt>
mov    -0x1160(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1160(%rbp)
jmp    1453 <main+0x213>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1080 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    143e <main+0x1fe>
mov    $0x0,%al
call   10d0 <print_menu@plt>
lea    0x144a(%rip),%rdi
call   1150 <sockerror@plt>
lea    -0x140(%rbp),%rsi
lea    0x144d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13a5 <main+0x165>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1479 <main+0x239>
lea    0x143c(%rip),%rdi
call   1150 <sockerror@plt>
jmp    147e <main+0x23e>
jmp    1789 <main+0x549>
cmpl   $0x2,-0x20(%rbp)
jne    1762 <main+0x522>
lea    0x143d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x941(%rbp),%rsi
lea    0x1404(%rip),%rdi
mov    $0x0,%al
call   10e0 <scanf@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1140 <fork@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    14d3 <main+0x293>
lea    0x1388(%rip),%rdi
call   1150 <sockerror@plt>
cmpl   $0x0,-0x30(%rbp)
jne    1733 <main+0x4f3>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
lea    -0x941(%rbp),%rdi
lea    0x1407(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    16fa <main+0x4ba>
mov    -0x18(%rbp),%edi
lea    0x13f0(%rip),%rsi
mov    $0x17,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1531 <main+0x2f1>
lea    0x13e9(%rip),%rdi
call   1150 <sockerror@plt>
lea    -0x940(%rbp),%rdi
xor    %esi,%esi
mov    $0x7ff,%edx
call   1080 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x940(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1573 <main+0x333>
lea    0x1315(%rip),%rdi
call   1150 <sockerror@plt>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1080 <memset@plt>
lea    -0x940(%rbp),%rdi
lea    0x1397(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x1158(%rbp)
cmpq   $0x0,-0x1158(%rbp)
jne    15c8 <main+0x388>
lea    -0x940(%rbp),%rdi
lea    0x1372(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x1158(%rbp)
cmpq   $0x0,-0x1158(%rbp)
jne    15f0 <main+0x3b0>
lea    -0x940(%rbp),%rsi
lea    0x134d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1605 <main+0x3c5>
lea    -0x940(%rbp),%rsi
lea    0x1351(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    160a <main+0x3ca>
cmpl   $0x0,-0x115c(%rbp)
je     16a4 <main+0x464>
lea    -0x940(%rbp),%rdi
xor    %esi,%esi
mov    $0x7ff,%edx
call   1080 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x940(%rbp),%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1659 <main+0x419>
lea    0x122f(%rip),%rdi
call   1150 <sockerror@plt>
lea    -0x940(%rbp),%rax
mov    %rax,-0x1168(%rbp)
lea    -0x940(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1168(%rbp),%rdi
mov    %eax,%edx
mov    -0x1158(%rbp),%rcx
mov    $0x1,%esi
call   1130 <fwrite@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x115c(%rbp)
jmp    160a <main+0x3ca>
mov    $0x0,%al
call   10d0 <print_menu@plt>
mov    -0x1158(%rbp),%rdi
call   1040 <fclose@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    16d2 <main+0x492>
lea    0x1295(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    16f3 <main+0x4b3>
lea    0x128f(%rip),%rdi
call   1150 <sockerror@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x18(%rbp),%edi
lea    0x10fc(%rip),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1729 <main+0x4e9>
lea    0x11f1(%rip),%rdi
call   1150 <sockerror@plt>
jmp    172e <main+0x4ee>
jmp    175d <main+0x51d>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1756 <main+0x516>
lea    0x124d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x20(%rbp)
jmp    1784 <main+0x544>
cmpl   $0x3,-0x20(%rbp)
jne    1778 <main+0x538>
mov    $0x0,%al
call   10d0 <print_menu@plt>
jmp    177f <main+0x53f>
movl   $0x0,-0x20(%rbp)
jmp    1784 <main+0x544>
jmp    1789 <main+0x549>
jmp    1347 <main+0x107>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    17af <main+0x56f>
lea    0x1106(%rip),%rdi
call   1150 <sockerror@plt>
xor    %eax,%eax
add    $0x1170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1118,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x0,0x4(%rsp)
lea    0xd8b(%rip),%rsi
lea    0x910(%rsp),%rdi
mov    $0x800,%edx
call   10d0 <memcpy@plt>
cmp    $0x3,%ebp
jge    163b <main+0x3eb>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,0x8(%rsp)
test   %eax,%eax
jns    12bd <main+0x6d>
lea    0x157c(%rip),%rdi
call   1160 <sockerror@plt>
mov    $0x913,%esi
cmp    $0x1,%ebp
je     12d2 <main+0x82>
mov    0x8(%rbx),%rdi
call   1120 <atoi@plt>
mov    %eax,%esi
mov    0x8(%rsp),%edi
call   1100 <server_connect@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10e0 <print_menu@plt>
lea    0x1568(%rip),%r15
lea    0x4(%rsp),%rbp
lea    0x165f(%rip),%r12
lea    0x15af(%rip),%r13
lea    0xf(%rsp),%r14
jmp    1317 <main+0xc7>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   10e0 <print_menu@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   10f0 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x3,%eax
je     1310 <main+0xc0>
cmp    $0x2,%eax
je     1360 <main+0x110>
cmp    $0x1,%eax
jne    13e0 <main+0x190>
xor    %eax,%eax
call   1150 <fork@plt>
test   %eax,%eax
js     13ed <main+0x19d>
jne    13f9 <main+0x1a9>
jmp    1449 <main+0x1f9>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10f0 <scanf@plt>
xor    %eax,%eax
call   1150 <fork@plt>
test   %eax,%eax
js     1419 <main+0x1c9>
jne    1425 <main+0x1d5>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
mov    %r14,%rdi
lea    0x1534(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     14d1 <main+0x281>
mov    %ebx,%edi
lea    0x144c(%rip),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %eax,%eax
jns    1317 <main+0xc7>
lea    0x151d(%rip),%rdi
call   1160 <sockerror@plt>
jmp    1317 <main+0xc7>
nopl   0x0(%rax)
movl   $0x0,0x4(%rsp)
jmp    1317 <main+0xc7>
lea    0x1462(%rip),%rdi
call   1160 <sockerror@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
test   %eax,%eax
jns    1317 <main+0xc7>
lea    0x14a1(%rip),%rdi
call   1160 <sockerror@plt>
jmp    1317 <main+0xc7>
lea    0x1436(%rip),%rdi
call   1160 <sockerror@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
test   %eax,%eax
jns    143c <main+0x1ec>
lea    0x1547(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,0x4(%rsp)
jmp    1317 <main+0xc7>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
lea    0x910(%rsp),%rsi
mov    %ebx,%edi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %eax,%eax
jns    1493 <main+0x243>
lea    0x13f9(%rip),%rdi
call   1160 <sockerror@plt>
jmp    1493 <main+0x243>
nopw   0x0(%rax,%rax,1)
lea    0x1412(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1090 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jns    1480 <main+0x230>
xor    %eax,%eax
call   10e0 <print_menu@plt>
lea    0x13b9(%rip),%rdi
call   1160 <sockerror@plt>
jmp    1480 <main+0x230>
lea    0x13fb(%rip),%rsi
mov    %ebx,%edi
mov    $0x17,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %eax,%eax
jns    14f6 <main+0x2a6>
lea    0x13fb(%rip),%rdi
call   1160 <sockerror@plt>
lea    0x110(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x7ff,%edx
call   1090 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jns    152e <main+0x2de>
lea    0x135a(%rip),%rdi
call   1160 <sockerror@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1090 <memset@plt>
lea    0x13bc(%rip),%rsi
lea    0x110(%rsp),%rdi
call   1110 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1583 <main+0x333>
lea    0x13a3(%rip),%rsi
lea    0x110(%rsp),%rdi
call   1110 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1583 <main+0x333>
lea    0x138a(%rip),%rdi
xor    %r14d,%r14d
jmp    158a <main+0x33a>
lea    0x139c(%rip),%rdi
lea    0x110(%rsp),%r12
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x12e0(%rip),%r15
jmp    15ce <main+0x37e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   1140 <fwrite@plt>
test   %ebp,%ebp
je     15fe <main+0x3ae>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x7ff,%edx
call   1090 <memset@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    15b0 <main+0x360>
mov    %r15,%rdi
call   1160 <sockerror@plt>
jmp    15b0 <main+0x360>
xor    %eax,%eax
call   10e0 <print_menu@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
test   %eax,%eax
jns    161d <main+0x3cd>
lea    0x1383(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
test   %eax,%eax
jns    1634 <main+0x3e4>
lea    0x1308(%rip),%rdi
call   1160 <sockerror@plt>
xor    %edi,%edi
call   1130 <exit@plt>
mov    0x2996(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rcx
lea    0x11b4(%rip),%rsi
mov    %rcx,%rdx
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
@__const.main.initial_message = [2048 x i8] c"READY FOR INSTANT MESSAGING\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str = [50 x i8] c"usage: %s OR %s Port #: 2323 or 3232 for testing\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [31 x i8] c"ERROR, while opening socket!!!\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"ERROR, during fork!!!\00"
@.str.4 = [23 x i8] c"ERROR, write failed!!!\00"
@.str.5 = [22 x i8] c"ERROR, read failed!!!\00"
@.str.6 = [23 x i8] c"\0AINCOMING MESSAGE:\0A %s\00"
@.str.7 = [33 x i8] c"ERROR, unable to close socket!!!\00"
@.str.8 = [41 x i8] c"File Transfer Imminent, continue? [y/n]\0A\00"
@.str.9 = [3 x i8] c"%s\00"
@.str.10 = [2 x i8] c"y\00"
@.str.11 = [25 x i8] c"READY FOR FILE TRANSFER\0A\00"
@.str.12 = [22 x i8] c"ERROR, send failed!!!\00"
@.str.13 = [3 x i8] c"at\00"
@.str.14 = [3 x i8] c"wt\00"
@.str.15 = [30 x i8] c"can not open %s for writing.\0A\00"
@.str.16 = [17 x i8] c"file %s created\0A\00"
@.str.17 = [29 x i8] c"ERROR, unable to close file\0A\00"
@.str.18 = [31 x i8] c"ERROR, unable to close socket\0A\00"
@.str.19 = [2 x i8] zeroinitializer
@.str.20 = [30 x i8] c"ERROR, unable to cloose file\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 i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [256 x i8]
%17 = alloca [2048 x i8]
%18 = alloca [1 x i8]
%19 = alloca [2048 x i8]
%20 = alloca i32*
%21 = alloca i32
%22 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 0, i32* %14
store i32 2323, i32* %15
%23 = bitcast [2048 x i8]* %19 to i8*
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 2
br i1 %25, label %26, label %36
26: ; preds = %2
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %30, i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %2
%37 = load i32, i32* @AF_INET
%38 = load i32, i32* @SOCK_STREAM
%39 = call i32 @socket(i32 %37, i32 %38, i32 0)
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @sockerror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %42, %36
%45 = load i32, i32* %4
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* %6
%49 = call i32 @server_connect(i32 %48, i32 2323)
store i32 %49, i32* %7
br label %58
50: ; preds = %44
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 @atoi(i8* %53)
store i32 %54, i32* %8
%55 = load i32, i32* %6
%56 = load i32, i32* %8
%57 = call i32 @server_connect(i32 %55, i32 %56)
store i32 %57, i32* %7
br label %58
58: ; preds = %50, %47
%59 = call i32 (...) @print_menu()
store i32 1, i32* %21
store i32 0, i32* %22
br label %60
60: ; preds = %240, %58
%61 = load i32, i32* %21
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %241
63: ; preds = %60
%64 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
store i32 %64, i32* %12
%65 = load i32, i32* %9
%66 = icmp eq i32 %65, 1
br i1 %66, label %67, label %117
67: ; preds = %63
%68 = call i32 (...) @fork()
store i32 %68, i32* %13
%69 = load i32, i32* %13
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %73
73: ; preds = %71, %67
%74 = load i32, i32* %13
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %108
76: ; preds = %73
%77 = load i32, i32* %6
%78 = call i32 @close(i32 %77)
br label %79
79: ; preds = %76, %107
%80 = load i32, i32* %22
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %93
82: ; preds = %79
%83 = load i32, i32* %7
%84 = getelementptr inbounds [2048 x i8], [2048 x i8]* %19, i64 0, i64 0
%85 = call i32 @send(i32 %83, i8* %84, i32 2048, i32 0)
store i32 %85, i32* %11
%86 = load i32, i32* %11
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %82
%89 = call i32 @sockerror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %90
90: ; preds = %88, %82
%91 = load i32, i32* %22
%92 = add nsw i32 %91, 1
store i32 %92, i32* %22
br label %107
93: ; preds = %79
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%95 = call i32 @memset(i8* %94, i32 0, i32 255)
%96 = load i32, i32* %7
%97 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%98 = call i32 @recv(i32 %96, i8* %97, i32 255, i32 0)
store i32 %98, i32* %10
%99 = load i32, i32* %10
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %104
101: ; preds = %93
%102 = call i32 (...) @print_menu()
%103 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %104
104: ; preds = %101, %93
%105 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %105)
br label %107
107: ; preds = %104, %90
br label %79
108: ; preds = %73
%109 = load i32, i32* %7
%110 = call i32 @close(i32 %109)
store i32 %110, i32* %12
%111 = load i32, i32* %12
%112 = icmp slt i32 %111, 0
br i1 %112, label %113, label %115
113: ; preds = %108
%114 = call i32 @sockerror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %115
115: ; preds = %113, %108
br label %116
116: ; preds = %115
br label %240
117: ; preds = %63
%118 = load i32, i32* %9
%119 = icmp eq i32 %118, 2
br i1 %119, label %120, label %232
120: ; preds = %117
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0))
%122 = getelementptr inbounds [1 x i8], [1 x i8]* %18, i64 0, i64 0
%123 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %122)
store i32 %123, i32* %12
%124 = call i32 (...) @fork()
store i32 %124, i32* %13
%125 = load i32, i32* %13
%126 = icmp slt i32 %125, 0
br i1 %126, label %127, label %129
127: ; preds = %120
%128 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %129
129: ; preds = %127, %120
%130 = load i32, i32* %13
%131 = icmp eq i32 %130, 0
br i1 %131, label %132, label %223
132: ; preds = %129
%133 = load i32, i32* %6
%134 = call i32 @close(i32 %133)
%135 = getelementptr inbounds [1 x i8], [1 x i8]* %18, i64 0, i64 0
%136 = call i64 @strcmp(i8* %135, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%137 = icmp eq i64 %136, 0
br i1 %137, label %138, label %214
138: ; preds = %132
%139 = load i32, i32* %7
%140 = call i32 @send(i32 %139, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 23, i32 0)
store i32 %140, i32* %11
%141 = load i32, i32* %11
%142 = icmp slt i32 %141, 0
br i1 %142, label %143, label %145
143: ; preds = %138
%144 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
br label %145
145: ; preds = %143, %138
%146 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%147 = call i32 @memset(i8* %146, i32 0, i32 2047)
%148 = load i32, i32* %7
%149 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%150 = call i32 @recv(i32 %148, i8* %149, i32 255, i32 0)
store i32 %150, i32* %10
%151 = load i32, i32* %10
%152 = icmp slt i32 %151, 0
br i1 %152, label %153, label %155
153: ; preds = %145
%154 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %155
155: ; preds = %153, %145
%156 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%157 = call i32 @memset(i8* %156, i32 0, i32 255)
%158 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%159 = call i32* @fopen(i8* %158, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
store i32* %159, i32** %20
%160 = load i32*, i32** %20
%161 = icmp ne i32* %160, null
br i1 %161, label %165, label %162
162: ; preds = %155
%163 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%164 = call i32* @fopen(i8* %163, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
store i32* %164, i32** %20
br label %165
165: ; preds = %162, %155
%166 = load i32*, i32** %20
%167 = icmp ne i32* %166, null
br i1 %167, label %171, label %168
168: ; preds = %165
%169 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.15, i64 0, i64 0), i8* %169)
br label %174
171: ; preds = %165
%172 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%173 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.16, i64 0, i64 0), i8* %172)
br label %174
174: ; preds = %171, %168
br label %175
175: ; preds = %188, %174
%176 = load i32, i32* %21
%177 = icmp ne i32 %176, 0
br i1 %177, label %178, label %197
178: ; preds = %175
%179 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%180 = call i32 @memset(i8* %179, i32 0, i32 2047)
%181 = load i32, i32* %7
%182 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%183 = call i32 @recv(i32 %181, i8* %182, i32 80, i32 0)
store i32 %183, i32* %10
%184 = load i32, i32* %10
%185 = icmp slt i32 %184, 0
br i1 %185, label %186, label %188
186: ; preds = %178
%187 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %188
188: ; preds = %186, %178
%189 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%190 = getelementptr inbounds [2048 x i8], [2048 x i8]* %17, i64 0, i64 0
%191 = call i32 @strlen(i8* %190)
%192 = load i32*, i32** %20
%193 = call i32 @fwrite(i8* %189, i32 1, i32 %191, i32* %192)
%194 = load i32, i32* %14
%195 = add nsw i32 %194, 1
store i32 %195, i32* %14
%196 = load i32, i32* %10
store i32 %196, i32* %21
br label %175
197: ; preds = %175
%198 = call i32 (...) @print_menu()
%199 = load i32*, i32** %20
%200 = call i32 @fclose(i32* %199)
store i32 %200, i32* %12
%201 = load i32, i32* %12
%202 = icmp slt i32 %201, 0
br i1 %202, label %203, label %205
203: ; preds = %197
%204 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.17, i64 0, i64 0))
br label %205
205: ; preds = %203, %197
%206 = load i32, i32* %7
%207 = call i32 @close(i32 %206)
store i32 %207, i32* %12
%208 = load i32, i32* %12
%209 = icmp slt i32 %208, 0
br i1 %209, label %210, label %212
210: ; preds = %205
%211 = call i32 @sockerror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.18, i64 0, i64 0))
br label %212
212: ; preds = %210, %205
%213 = call i32 @exit(i32 0)
unreachable
214: ; preds = %132
%215 = load i32, i32* %7
%216 = call i32 @send(i32 %215, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i64 0, i64 0), i32 2, i32 0)
store i32 %216, i32* %11
%217 = load i32, i32* %11
%218 = icmp slt i32 %217, 0
br i1 %218, label %219, label %221
219: ; preds = %214
%220 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
br label %221
221: ; preds = %219, %214
br label %222
222: ; preds = %221
br label %231
223: ; preds = %129
%224 = load i32, i32* %7
%225 = call i32 @close(i32 %224)
store i32 %225, i32* %12
%226 = load i32, i32* %12
%227 = icmp slt i32 %226, 0
br i1 %227, label %228, label %230
228: ; preds = %223
%229 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.20, i64 0, i64 0))
br label %230
230: ; preds = %228, %223
store i32 0, i32* %9
br label %231
231: ; preds = %230, %222
br label %239
232: ; preds = %117
%233 = load i32, i32* %9
%234 = icmp eq i32 %233, 3
br i1 %234, label %235, label %237
235: ; preds = %232
%236 = call i32 (...) @print_menu()
br label %238
237: ; preds = %232
store i32 0, i32* %9
br label %238
238: ; preds = %237, %235
br label %239
239: ; preds = %238, %231
br label %240
240: ; preds = %239, %116
br label %60
241: ; preds = %60
%242 = load i32, i32* %6
%243 = call i32 @close(i32 %242)
store i32 %243, i32* %12
%244 = load i32, i32* %12
%245 = icmp slt i32 %244, 0
br i1 %245, label %246, label %248
246: ; preds = %241
%247 = call i32 @sockerror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %248
248: ; preds = %246, %241
ret i32 0
}

LLVM IR (-O2):
@__const.main.initial_message = [2048 x i8] c"READY FOR INSTANT MESSAGING\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str = [50 x i8] c"usage: %s OR %s Port #: 2323 or 3232 for testing\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [31 x i8] c"ERROR, while opening socket!!!\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"ERROR, during fork!!!\00"
@.str.4 = [23 x i8] c"ERROR, write failed!!!\00"
@.str.5 = [22 x i8] c"ERROR, read failed!!!\00"
@.str.6 = [23 x i8] c"\0AINCOMING MESSAGE:\0A %s\00"
@.str.7 = [33 x i8] c"ERROR, unable to close socket!!!\00"
@.str.9 = [3 x i8] c"%s\00"
@.str.10 = [2 x i8] c"y\00"
@.str.11 = [25 x i8] c"READY FOR FILE TRANSFER\0A\00"
@.str.12 = [22 x i8] c"ERROR, send failed!!!\00"
@.str.13 = [3 x i8] c"at\00"
@.str.14 = [3 x i8] c"wt\00"
@.str.15 = [30 x i8] c"can not open %s for writing.\0A\00"
@.str.16 = [17 x i8] c"file %s created\0A\00"
@.str.18 = [31 x i8] c"ERROR, unable to close socket\0A\00"
@.str.19 = [2 x i8] zeroinitializer
@str = [40 x i8] c"File Transfer Imminent, continue? [y/n]\00"
@str.21 = [29 x i8] c"ERROR, unable to cloose file\00"
@str.22 = [28 x i8] c"ERROR, unable to close file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca [2048 x i8]
%6 = alloca [1 x i8]
%7 = alloca [2048 x i8]
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%13 = icmp sgt i32 %0, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = tail call i32 @socket(i32 %20, i32 %21, i32 0)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 @sockerror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
%27 = icmp eq i32 %0, 1
br i1 %27, label %32, label %28
28: ; preds = %26
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail call i32 @atoi(i8* %30)
br label %32
32: ; preds = %26, %28
%33 = phi i32 [ %31, %28 ], [ 2323, %26 ]
%34 = tail call i32 @server_connect(i32 %22, i32 %33)
%35 = tail call i32 (...) @print_menu()
br label %36
36: ; preds = %132, %32
%37 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%38 = load i32, i32* %3
switch i32 %38, label %141 [
i32 1, label %39
i32 2, label %67
i32 3, label %139
]
39: ; preds = %36
%40 = call i32 (...) @fork()
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %62
44: ; preds = %39
%45 = icmp eq i32 %40, 0
br i1 %45, label %46, label %62
46: ; preds = %44
%47 = call i32 @close(i32 %22)
%48 = call i32 @send(i32 %34, i8* %12, i32 2048, i32 0)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @sockerror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %50, %46
br label %58
53: ; preds = %58
%54 = call i32 (...) @print_menu()
%55 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %53, %58
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %9)
br label %58
58: ; preds = %52, %56
%59 = call i32 @memset(i8* %9, i32 0, i32 255)
%60 = call i32 @recv(i32 %34, i8* %9, i32 255, i32 0)
%61 = icmp slt i32 %60, 0
br i1 %61, label %53, label %56
62: ; preds = %42, %44
%63 = call i32 @close(i32 %34)
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %132
65: ; preds = %62
%66 = call i32 @sockerror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %132
67: ; preds = %36
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%69 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %11)
%70 = call i32 (...) @fork()
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %67
%73 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %133
74: ; preds = %67
%75 = icmp eq i32 %70, 0
br i1 %75, label %76, label %133
76: ; preds = %74
%77 = call i32 @close(i32 %22)
%78 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%79 = icmp eq i64 %78, 0
br i1 %79, label %80, label %127
80: ; preds = %76
%81 = call i32 @send(i32 %34, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i32 23, i32 0)
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %80
%84 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
br label %85
85: ; preds = %83, %80
%86 = call i32 @memset(i8* %10, i32 0, i32 2047)
%87 = call i32 @recv(i32 %34, i8* %10, i32 255, i32 0)
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %85
%90 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %91
91: ; preds = %89, %85
%92 = call i32 @memset(i8* %9, i32 0, i32 255)
%93 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
%94 = icmp eq i32* %93, null
br i1 %94, label %95, label %98
95: ; preds = %91
%96 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
%97 = icmp eq i32* %96, null
br i1 %97, label %100, label %98
98: ; preds = %91, %95
%99 = phi i32* [ %96, %95 ], [ %93, %91 ]
br label %100
100: ; preds = %95, %98
%101 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.16, i64 0, i64 0), %98 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.15, i64 0, i64 0), %95 ]
%102 = phi i32* [ %99, %98 ], [ null, %95 ]
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %101, i8* %10)
br label %104
104: ; preds = %100, %110
%105 = call i32 @memset(i8* %10, i32 0, i32 2047)
%106 = call i32 @recv(i32 %34, i8* %10, i32 80, i32 0)
%107 = icmp slt i32 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %104
%109 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %110
110: ; preds = %108, %104
%111 = call i32 @strlen(i8* %10)
%112 = call i32 @fwrite(i8* %10, i32 1, i32 %111, i32* %102)
%113 = icmp eq i32 %106, 0
br i1 %113, label %114, label %104
114: ; preds = %110
%115 = call i32 (...) @print_menu()
%116 = call i32 @fclose(i32* %102)
%117 = icmp slt i32 %116, 0
br i1 %117, label %118, label %120
118: ; preds = %114
%119 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.22, i64 0, i64 0))
br label %120
120: ; preds = %118, %114
%121 = call i32 @close(i32 %34)
%122 = icmp slt i32 %121, 0
br i1 %122, label %123, label %125
123: ; preds = %120
%124 = call i32 @sockerror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.18, i64 0, i64 0))
br label %125
125: ; preds = %123, %120
%126 = call i32 @exit(i32 0)
unreachable
127: ; preds = %76
%128 = call i32 @send(i32 %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i64 0, i64 0), i32 2, i32 0)
%129 = icmp slt i32 %128, 0
br i1 %129, label %130, label %132
130: ; preds = %127
%131 = call i32 @sockerror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
br label %132
132: ; preds = %130, %127, %138, %141, %139, %65, %62
br label %36
133: ; preds = %72, %74
%134 = call i32 @close(i32 %34)
%135 = icmp slt i32 %134, 0
br i1 %135, label %136, label %138
136: ; preds = %133
%137 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.21, i64 0, i64 0))
br label %138
138: ; preds = %136, %133
store i32 0, i32* %3
br label %132
139: ; preds = %36
%140 = call i32 (...) @print_menu()
br label %132
141: ; preds = %36
store i32 0, i32* %3
br label %132
}