#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 timeval {
  int tv_sec;
};
struct TYPE_2__ {
  unsigned long s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serverINETAddress;
typedef int /*<<< orphan*/ command;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
unsigned long INADDR_NONE;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int atoi(char *);
int /*<<< orphan*/ authenticate(int, char *, char *);
int /*<<< orphan*/ bad_input(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
unsigned long inet_addr(char *);
int /*<<< orphan*/ instruction();
int /*<<< orphan*/ printf(char *, char *);
int receive_msg(int, char *);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              struct timeval *, int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  int sockfd, serverLen;
  struct sockaddr_in serverINETAddress;
  struct sockaddr *serverSockAddrPtr;
  struct hostent *server;
  char command[256], host[100], buf[32768];
  char user[100], psw[100];
  int port = 5000, result;
  unsigned long inetAddress;
  signal(SIGINT, SIG_IGN);
  signal(SIGQUIT, SIG_IGN);
  if ((argc % 2) == 0 || argc > 9)
    bad_input(argv[0]);
  int i;
  for (i = 1; i < argc; i += 2) {
    char *param = argv[i];
    if (strcmp(param, "-h") == 0)
      strcpy(host, argv[i + 1]);
    else if (strcmp(param, "-p") == 0)
      port = atoi(argv[i + 1]);
    else if (strcmp(param, "-usr") == 0)
      strcpy(user, argv[i + 1]);
    else if (strcmp(param, "-psw") == 0)
      strcpy(psw, argv[i + 1]);
    else
      bad_input(argv[0]);
  }
  serverSockAddrPtr = (struct sockaddr *)&serverINETAddress;
  serverLen = sizeof(serverINETAddress);
  bzero((char *)&serverINETAddress, serverLen);
  serverINETAddress.sin_family = AF_INET;
  serverINETAddress.sin_port = htons(port);
  inetAddress = inet_addr(host);
  if (inetAddress != INADDR_NONE) {
    serverINETAddress.sin_addr.s_addr = inetAddress;
  } else {
    server = gethostbyname(host);
    if (server == NULL) {
      fprintf(stderr, "ERROR, no such host\n");
      exit(0);
    }
    bcopy((char *)server->h_addr, (char *)&serverINETAddress.sin_addr.s_addr,
          server->h_length);
  }
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  int nsec = 1;
  do {
    result = connect(sockfd, serverSockAddrPtr, serverLen);
    if (result == -1) {
      sleep(1);
      nsec++;
    }
  } while (result == -1 && nsec <= 60);
  if (nsec > 60)
    error("Connection timeout");
  struct timeval tv;
  tv.tv_sec = 5;
  setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (struct timeval *)&tv,
             sizeof(struct timeval));
  instruction();
  authenticate(sockfd, user, psw);
  while (1) {
    printf("%s ", "$");
    bzero(command, sizeof(command));
    fgets(command, 256, stdin);
    bzero(buf, sizeof(buf));
    if (send(sockfd, command, sizeof(command), 0) < 0)
      error("ERROR sending message");
    if (strcmp(command, "exit\n") == 0)
      break;
    int total = receive_msg(sockfd, buf);
    if (total > 0) {
      buf[total] = '\0';
      printf("%s\n", buf);
    }
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x82c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1388,-0x8294(%rbp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
call   10e0 <signal@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
mov    0x2cee(%rip),%rax
mov    (%rax),%esi
call   10e0 <signal@plt>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12ef <main+0x6f>
cmpl   $0x9,-0x8(%rbp)
jle    12fb <main+0x7b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1140 <bad_input@plt>
movl   $0x1,-0x82a4(%rbp)
mov    -0x82a4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1465 <main+0x1e5>
mov    -0x10(%rbp),%rax
movslq -0x82a4(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x82b0(%rbp)
mov    -0x82b0(%rbp),%rdi
lea    0xcc8(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    136c <main+0xec>
lea    -0x1b0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x82a4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
jmp    144c <main+0x1cc>
mov    -0x82b0(%rbp),%rdi
lea    0xc89(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    13ad <main+0x12d>
mov    -0x10(%rbp),%rax
mov    -0x82a4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1160 <atoi@plt>
mov    %eax,-0x8294(%rbp)
jmp    1447 <main+0x1c7>
mov    -0x82b0(%rbp),%rdi
lea    0xc4b(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    13ef <main+0x16f>
lea    -0x8220(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x82a4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
jmp    1442 <main+0x1c2>
mov    -0x82b0(%rbp),%rdi
lea    0xc0e(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    1431 <main+0x1b1>
lea    -0x8290(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x82a4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
jmp    143d <main+0x1bd>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1140 <bad_input@plt>
jmp    1442 <main+0x1c2>
jmp    1447 <main+0x1c7>
jmp    144c <main+0x1cc>
jmp    1451 <main+0x1d1>
mov    -0x82a4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x82a4(%rbp)
jmp    1305 <main+0x85>
lea    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x10,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1150 <bzero@plt>
mov    0x2b59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8294(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x20(%rbp)
lea    -0x1b0(%rbp),%rdi
call   10c0 <inet_addr@plt>
mov    %rax,-0x82a0(%rbp)
mov    -0x82a0(%rbp),%rax
mov    0x2b15(%rip),%rcx
cmp    (%rcx),%rax
je     14d4 <main+0x254>
mov    -0x82a0(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1522 <main+0x2a2>
lea    -0x1b0(%rbp),%rdi
call   1100 <gethostbyname@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    150b <main+0x28b>
mov    0x2aaa(%rip),%rax
mov    (%rax),%edi
lea    0xb11(%rip),%rsi
call   1110 <fprintf@plt>
xor    %edi,%edi
call   1170 <exit@plt>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   1120 <bcopy@plt>
mov    0x2ab7(%rip),%rax
mov    (%rax),%edi
mov    0x2a66(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   11a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1554 <main+0x2d4>
lea    0xad6(%rip),%rdi
call   1130 <error@plt>
movl   $0x1,-0x82b4(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1180 <connect@plt>
mov    %eax,-0x8298(%rbp)
cmpl   $0xffffffff,-0x8298(%rbp)
jne    1599 <main+0x319>
mov    $0x1,%edi
call   1190 <sleep@plt>
mov    -0x82b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x82b4(%rbp)
jmp    159e <main+0x31e>
xor    %eax,%eax
cmpl   $0xffffffff,-0x8298(%rbp)
mov    %al,-0x82bd(%rbp)
jne    15c3 <main+0x343>
cmpl   $0x3c,-0x82b4(%rbp)
setle  %al
mov    %al,-0x82bd(%rbp)
mov    -0x82bd(%rbp),%al
test   $0x1,%al
jne    155e <main+0x2de>
cmpl   $0x3c,-0x82b4(%rbp)
jle    15ea <main+0x36a>
lea    0xa55(%rip),%rdi
call   1130 <error@plt>
movl   $0x5,-0x82b8(%rbp)
mov    -0x14(%rbp),%edi
mov    0x29ea(%rip),%rax
mov    (%rax),%esi
mov    0x29a1(%rip),%rax
mov    (%rax),%edx
lea    -0x82b8(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
mov    $0x0,%al
call   10f0 <instruction@plt>
mov    -0x14(%rbp),%edi
lea    -0x8220(%rbp),%rsi
lea    -0x8290(%rbp),%rdx
call   1030 <authenticate@plt>
lea    0xa0e(%rip),%rdi
lea    0xa0b(%rip),%rsi
call   1080 <printf@plt>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   1150 <bzero@plt>
lea    -0x140(%rbp),%rdi
mov    0x295e(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   10b0 <fgets@plt>
lea    -0x81b0(%rbp),%rdi
mov    $0x8000,%esi
call   1150 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0x0,%rax
jge    16b3 <main+0x433>
lea    0x9a5(%rip),%rdi
call   1130 <error@plt>
lea    -0x140(%rbp),%rdi
lea    0x9a8(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    16d5 <main+0x455>
jmp    171e <main+0x49e>
mov    -0x14(%rbp),%edi
lea    -0x81b0(%rbp),%rsi
call   1090 <receive_msg@plt>
mov    %eax,-0x82bc(%rbp)
cmpl   $0x0,-0x82bc(%rbp)
jle    1719 <main+0x499>
movslq -0x82bc(%rbp),%rax
movb   $0x0,-0x81b0(%rbp,%rax,1)
lea    -0x81b0(%rbp),%rsi
lea    0x95b(%rip),%rdi
call   1080 <printf@plt>
jmp    1638 <main+0x3b8>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x82c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8278,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    0x2d12(%rip),%r14
mov    (%r14),%esi
call   10e0 <signal@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%esi
call   10e0 <signal@plt>
cmp    $0x9,%ebp
jg     12cb <main+0x4b>
mov    %ebp,%eax
and    $0x1,%eax
jne    12d3 <main+0x53>
mov    (%rbx),%rdi
call   1140 <bad_input@plt>
mov    $0x1388,%r14d
cmp    $0x2,%ebp
jl     13b3 <main+0x133>
mov    $0x1388,%r14d
mov    $0x1,%r13d
lea    0xd0b(%rip),%r15
jmp    131c <main+0x9c>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rbx,%r13,8),%rsi
lea    0x20(%rsp),%rdi
call   1040 <strcpy@plt>
add    $0x2,%r13
cmp    %ebp,%r13d
jge    13b3 <main+0x133>
mov    (%rbx,%r13,8),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     1300 <main+0x80>
mov    %r12,%rdi
lea    0xcc9(%rip),%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     1380 <main+0x100>
mov    %r12,%rdi
lea    0xcb8(%rip),%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     138f <main+0x10f>
mov    %r12,%rdi
lea    0xca9(%rip),%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     13a1 <main+0x121>
mov    (%rbx),%rdi
call   1140 <bad_input@plt>
jmp    130f <main+0x8f>
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rbx,%r13,8),%rdi
call   1160 <atoi@plt>
mov    %eax,%r14d
jmp    130f <main+0x8f>
mov    0x8(%rbx,%r13,8),%rsi
lea    0x100(%rsp),%rdi
jmp    130a <main+0x8a>
mov    0x8(%rbx,%r13,8),%rsi
lea    0x90(%rsp),%rdi
jmp    130a <main+0x8a>
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   1150 <bzero@plt>
mov    0x2c17(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x1c(%rsp)
mov    %r14d,%edi
call   1060 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0x20(%rsp),%rdi
call   10c0 <inet_addr@plt>
mov    0x2be4(%rip),%rcx
cmp    (%rcx),%rax
jne    1416 <main+0x196>
lea    0x20(%rsp),%rdi
call   1100 <gethostbyname@plt>
test   %rax,%rax
je     15a2 <main+0x322>
mov    0x8(%rax),%rsi
mov    (%rax),%edx
lea    0x10(%rsp),%rdi
call   1120 <memmove@plt>
jmp    141b <main+0x19b>
mov    %rax,0x10(%rsp)
mov    (%rbx),%edi
mov    0x2b74(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   11a0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    143f <main+0x1bf>
lea    0xbeb(%rip),%rdi
call   1130 <error@plt>
mov    $0x3c,%ebp
lea    0x10(%rsp),%r14
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1180 <connect@plt>
cmp    $0xffffffff,%eax
jne    147f <main+0x1ff>
mov    $0x1,%edi
call   1190 <sleep@plt>
add    $0xffffffff,%ebp
jne    1450 <main+0x1d0>
lea    0xbc0(%rip),%rdi
call   1130 <error@plt>
movl   $0x5,0x8(%rsp)
mov    0x2b5a(%rip),%rax
mov    (%rax),%esi
mov    0x2b11(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
xor    %eax,%eax
call   10f0 <instruction@plt>
lea    0x100(%rsp),%rsi
lea    0x90(%rsp),%rdx
mov    %ebx,%edi
call   1030 <authenticate@plt>
lea    0xb81(%rip),%r15
lea    0x170(%rsp),%rbp
mov    0x2ae9(%rip),%r14
lea    0x270(%rsp),%r12
lea    0xb7b(%rip),%r13
xchg   %ax,%ax
lea    0xb56(%rip),%rdi
mov    %r15,%rsi
call   1080 <printf@plt>
mov    %rbp,%rdi
mov    $0x100,%esi
call   1150 <bzero@plt>
mov    (%r14),%edx
mov    %rbp,%rdi
mov    $0x100,%esi
call   10b0 <fgets@plt>
mov    %r12,%rdi
mov    $0x8000,%esi
call   1150 <bzero@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
jns    154b <main+0x2cb>
lea    0xb0d(%rip),%rdi
call   1130 <error@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     1587 <main+0x307>
mov    %ebx,%edi
mov    %r12,%rsi
call   1090 <receive_msg@plt>
test   %eax,%eax
jle    14f0 <main+0x270>
mov    %eax,%eax
movb   $0x0,0x270(%rsp,%rax,1)
lea    0xaf5(%rip),%rdi
mov    %r12,%rsi
call   1080 <printf@plt>
jmp    14f0 <main+0x270>
mov    %ebx,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x8278,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x29f7(%rip),%rax
mov    (%rax),%edi
lea    0xa5e(%rip),%rsi
call   1110 <fprintf@plt>
xor    %edi,%edi
call   1170 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.timeval = type { i32 }
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@SIGQUIT = global i32 0
@.str = [3 x i8] c"-h\00"
@.str.1 = [3 x i8] c"-p\00"
@.str.2 = [5 x i8] c"-usr\00"
@.str.3 = [5 x i8] c"-psw\00"
@AF_INET = global i32 0
@INADDR_NONE = global i64 0
@stderr = global i32 0
@.str.4 = [21 x i8] c"ERROR, no such host\0A\00"
@SOCK_STREAM = global i32 0
@.str.5 = [21 x i8] c"ERROR opening socket\00"
@.str.6 = [19 x i8] c"Connection timeout\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.7 = [4 x i8] c"%s \00"
@.str.8 = [2 x i8] c"$\00"
@stdin = global i32 0
@.str.9 = [22 x i8] c"ERROR sending message\00"
@.str.10 = [6 x i8] c"exit\0A\00"
@.str.11 = [4 x i8] c"%s\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 %struct.sockaddr_in
%9 = alloca %struct.sockaddr*
%10 = alloca %struct.hostent*
%11 = alloca [256 x i8]
%12 = alloca [100 x i8]
%13 = alloca [32768 x i8]
%14 = alloca [100 x i8]
%15 = alloca [100 x i8]
%16 = alloca i32
%17 = alloca i32
%18 = alloca i64
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i32
%22 = alloca %struct.timeval
%23 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 5000, i32* %16
%24 = load i32, i32* @SIGINT
%25 = load i32, i32* @SIG_IGN
%26 = call i32 @signal(i32 %24, i32 %25)
%27 = load i32, i32* @SIGQUIT
%28 = load i32, i32* @SIG_IGN
%29 = call i32 @signal(i32 %27, i32 %28)
%30 = load i32, i32* %4
%31 = srem i32 %30, 2
%32 = icmp eq i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %2
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 9
br i1 %35, label %36, label %41
36: ; preds = %33, %2
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = call i32 @bad_input(i8* %39)
br label %41
41: ; preds = %36, %33
store i32 1, i32* %19
br label %42
42: ; preds = %111, %41
%43 = load i32, i32* %19
%44 = load i32, i32* %4
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %114
46: ; preds = %42
%47 = load i8**, i8*** %5
%48 = load i32, i32* %19
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
store i8* %51, i8** %20
%52 = load i8*, i8** %20
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %64
55: ; preds = %46
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%57 = load i8**, i8*** %5
%58 = load i32, i32* %19
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %57, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 @strcpy(i8* %56, i8* %62)
br label %110
64: ; preds = %46
%65 = load i8*, i8** %20
%66 = call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %76
68: ; preds = %64
%69 = load i8**, i8*** %5
%70 = load i32, i32* %19
%71 = add nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8*, i8** %69, i64 %72
%74 = load i8*, i8** %73
%75 = call i32 @atoi(i8* %74)
store i32 %75, i32* %16
br label %109
76: ; preds = %64
%77 = load i8*, i8** %20
%78 = call i64 @strcmp(i8* %77, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%79 = icmp eq i64 %78, 0
br i1 %79, label %80, label %89
80: ; preds = %76
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%82 = load i8**, i8*** %5
%83 = load i32, i32* %19
%84 = add nsw i32 %83, 1
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8*, i8** %82, i64 %85
%87 = load i8*, i8** %86
%88 = call i32 @strcpy(i8* %81, i8* %87)
br label %108
89: ; preds = %76
%90 = load i8*, i8** %20
%91 = call i64 @strcmp(i8* %90, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %102
93: ; preds = %89
%94 = getelementptr inbounds [100 x i8], [100 x i8]* %15, i64 0, i64 0
%95 = load i8**, i8*** %5
%96 = load i32, i32* %19
%97 = add nsw i32 %96, 1
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8*, i8** %95, i64 %98
%100 = load i8*, i8** %99
%101 = call i32 @strcpy(i8* %94, i8* %100)
br label %107
102: ; preds = %89
%103 = load i8**, i8*** %5
%104 = getelementptr inbounds i8*, i8** %103, i64 0
%105 = load i8*, i8** %104
%106 = call i32 @bad_input(i8* %105)
br label %107
107: ; preds = %102, %93
br label %108
108: ; preds = %107, %80
br label %109
109: ; preds = %108, %68
br label %110
110: ; preds = %109, %55
br label %111
111: ; preds = %110
%112 = load i32, i32* %19
%113 = add nsw i32 %112, 2
store i32 %113, i32* %19
br label %42
114: ; preds = %42
%115 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
store %struct.sockaddr* %115, %struct.sockaddr** %9
store i32 16, i32* %7
%116 = bitcast %struct.sockaddr_in* %8 to i8*
%117 = load i32, i32* %7
%118 = call i32 @bzero(i8* %116, i32 %117)
%119 = load i32, i32* @AF_INET
%120 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %119, i32* %120
%121 = load i32, i32* %16
%122 = call i32 @htons(i32 %121)
%123 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %122, i32* %123
%124 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%125 = call i64 @inet_addr(i8* %124)
store i64 %125, i64* %18
%126 = load i64, i64* %18
%127 = load i64, i64* @INADDR_NONE
%128 = icmp ne i64 %126, %127
br i1 %128, label %129, label %133
129: ; preds = %114
%130 = load i64, i64* %18
%131 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%132 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %131, i32 0, i32 0
store i64 %130, i64* %132
br label %154
133: ; preds = %114
%134 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%135 = call %struct.hostent* @gethostbyname(i8* %134)
store %struct.hostent* %135, %struct.hostent** %10
%136 = load %struct.hostent*, %struct.hostent** %10
%137 = icmp eq %struct.hostent* %136, null
br i1 %137, label %138, label %142
138: ; preds = %133
%139 = load i32, i32* @stderr
%140 = call i32 @fprintf(i32 %139, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%141 = call i32 @exit(i32 0)
unreachable
142: ; preds = %133
%143 = load %struct.hostent*, %struct.hostent** %10
%144 = getelementptr inbounds %struct.hostent, %struct.hostent* %143, i32 0, i32 1
%145 = load i64, i64* %144
%146 = inttoptr i64 %145 to i8*
%147 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%148 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %147, i32 0, i32 0
%149 = bitcast i64* %148 to i8*
%150 = load %struct.hostent*, %struct.hostent** %10
%151 = getelementptr inbounds %struct.hostent, %struct.hostent* %150, i32 0, i32 0
%152 = load i32, i32* %151
%153 = call i32 @bcopy(i8* %146, i8* %149, i32 %152)
br label %154
154: ; preds = %142, %129
%155 = load i32, i32* @AF_INET
%156 = load i32, i32* @SOCK_STREAM
%157 = call i32 @socket(i32 %155, i32 %156, i32 0)
store i32 %157, i32* %6
%158 = load i32, i32* %6
%159 = icmp slt i32 %158, 0
br i1 %159, label %160, label %162
160: ; preds = %154
%161 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %162
162: ; preds = %160, %154
store i32 1, i32* %21
br label %163
163: ; preds = %181, %162
%164 = load i32, i32* %6
%165 = load %struct.sockaddr*, %struct.sockaddr** %9
%166 = load i32, i32* %7
%167 = call i32 @connect(i32 %164, %struct.sockaddr* %165, i32 %166)
store i32 %167, i32* %17
%168 = load i32, i32* %17
%169 = icmp eq i32 %168, -1
br i1 %169, label %170, label %174
170: ; preds = %163
%171 = call i32 @sleep(i32 1)
%172 = load i32, i32* %21
%173 = add nsw i32 %172, 1
store i32 %173, i32* %21
br label %174
174: ; preds = %170, %163
br label %175
175: ; preds = %174
%176 = load i32, i32* %17
%177 = icmp eq i32 %176, -1
br i1 %177, label %178, label %181
178: ; preds = %175
%179 = load i32, i32* %21
%180 = icmp sle i32 %179, 60
br label %181
181: ; preds = %178, %175
%182 = phi i1 [ false, %175 ], [ %180, %178 ]
br i1 %182, label %163, label %183
183: ; preds = %181
%184 = load i32, i32* %21
%185 = icmp sgt i32 %184, 60
br i1 %185, label %186, label %188
186: ; preds = %183
%187 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %188
188: ; preds = %186, %183
%189 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
store i32 5, i32* %189
%190 = load i32, i32* %6
%191 = load i32, i32* @SOL_SOCKET
%192 = load i32, i32* @SO_RCVTIMEO
%193 = call i32 @setsockopt(i32 %190, i32 %191, i32 %192, %struct.timeval* %22, i32 4)
%194 = call i32 (...) @instruction()
%195 = load i32, i32* %6
%196 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%197 = getelementptr inbounds [100 x i8], [100 x i8]* %15, i64 0, i64 0
%198 = call i32 @authenticate(i32 %195, i8* %196, i8* %197)
br label %199
199: ; preds = %188, %231
%200 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%201 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%202 = call i32 @bzero(i8* %201, i32 256)
%203 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%204 = load i32, i32* @stdin
%205 = call i32 @fgets(i8* %203, i32 256, i32 %204)
%206 = getelementptr inbounds [32768 x i8], [32768 x i8]* %13, i64 0, i64 0
%207 = call i32 @bzero(i8* %206, i32 32768)
%208 = load i32, i32* %6
%209 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%210 = call i64 @send(i32 %208, i8* %209, i32 256, i32 0)
%211 = icmp slt i64 %210, 0
br i1 %211, label %212, label %214
212: ; preds = %199
%213 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %214
214: ; preds = %212, %199
%215 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%216 = call i64 @strcmp(i8* %215, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%217 = icmp eq i64 %216, 0
br i1 %217, label %218, label %219
218: ; preds = %214
br label %232
219: ; preds = %214
%220 = load i32, i32* %6
%221 = getelementptr inbounds [32768 x i8], [32768 x i8]* %13, i64 0, i64 0
%222 = call i32 @receive_msg(i32 %220, i8* %221)
store i32 %222, i32* %23
%223 = load i32, i32* %23
%224 = icmp sgt i32 %223, 0
br i1 %224, label %225, label %231
225: ; preds = %219
%226 = load i32, i32* %23
%227 = sext i32 %226 to i64
%228 = getelementptr inbounds [32768 x i8], [32768 x i8]* %13, i64 0, i64 %227
store i8 0, i8* %228
%229 = getelementptr inbounds [32768 x i8], [32768 x i8]* %13, i64 0, i64 0
%230 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %229)
br label %231
231: ; preds = %225, %219
br label %199
232: ; preds = %218
%233 = load i32, i32* %6
%234 = call i32 @close(i32 %233)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.timeval = type { i32 }
%struct.sockaddr = type { i32 }
%struct.hostent = type { i32, i64 }
@SIGINT = global i32 0
@SIG_IGN = global i32 0
@SIGQUIT = global i32 0
@.str = [3 x i8] c"-h\00"
@.str.1 = [3 x i8] c"-p\00"
@.str.2 = [5 x i8] c"-usr\00"
@.str.3 = [5 x i8] c"-psw\00"
@AF_INET = global i32 0
@INADDR_NONE = global i64 0
@stderr = global i32 0
@.str.4 = [21 x i8] c"ERROR, no such host\0A\00"
@SOCK_STREAM = global i32 0
@.str.5 = [21 x i8] c"ERROR opening socket\00"
@.str.6 = [19 x i8] c"Connection timeout\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.7 = [4 x i8] c"%s \00"
@.str.8 = [2 x i8] c"$\00"
@stdin = global i32 0
@.str.9 = [22 x i8] c"ERROR sending message\00"
@.str.10 = [6 x i8] c"exit\0A\00"
@.str.11 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca [100 x i8]
%6 = alloca [32768 x i8]
%7 = alloca [100 x i8]
%8 = alloca [100 x i8]
%9 = alloca %struct.timeval
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [32768 x i8], [32768 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%16 = load i32, i32* @SIGINT
%17 = load i32, i32* @SIG_IGN
%18 = tail call i32 @signal(i32 %16, i32 %17)
%19 = load i32, i32* @SIGQUIT
%20 = load i32, i32* @SIG_IGN
%21 = tail call i32 @signal(i32 %19, i32 %20)
%22 = and i32 %0, 1
%23 = icmp eq i32 %22, 0
%24 = icmp sgt i32 %0, 9
%25 = or i1 %24, %23
br i1 %25, label %26, label %29
26: ; preds = %2
%27 = load i8*, i8** %1
%28 = tail call i32 @bad_input(i8* %27)
br label %29
29: ; preds = %2, %26
%30 = icmp sgt i32 %0, 1
br i1 %30, label %31, label %75
31: ; preds = %29, %70
%32 = phi i64 [ %72, %70 ], [ 1, %29 ]
%33 = phi i32 [ %71, %70 ], [ 5000, %29 ]
%34 = getelementptr inbounds i8*, i8** %1, i64 %32
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = add nuw nsw i64 %32, 1
%40 = getelementptr inbounds i8*, i8** %1, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 @strcpy(i8* %12, i8* %41)
br label %70
43: ; preds = %31
%44 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = add nuw nsw i64 %32, 1
%48 = getelementptr inbounds i8*, i8** %1, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 @atoi(i8* %49)
br label %70
51: ; preds = %43
%52 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %51
%55 = add nuw nsw i64 %32, 1
%56 = getelementptr inbounds i8*, i8** %1, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 @strcpy(i8* %14, i8* %57)
br label %70
59: ; preds = %51
%60 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %59
%63 = add nuw nsw i64 %32, 1
%64 = getelementptr inbounds i8*, i8** %1, i64 %63
%65 = load i8*, i8** %64
%66 = call i32 @strcpy(i8* %15, i8* %65)
br label %70
67: ; preds = %59
%68 = load i8*, i8** %1
%69 = call i32 @bad_input(i8* %68)
br label %70
70: ; preds = %46, %62, %67, %54, %38
%71 = phi i32 [ %33, %38 ], [ %50, %46 ], [ %33, %54 ], [ %33, %62 ], [ %33, %67 ]
%72 = add nuw i64 %32, 2
%73 = trunc i64 %72 to i32
%74 = icmp slt i32 %73, %0
br i1 %74, label %31, label %75
75: ; preds = %70, %29
%76 = phi i32 [ 5000, %29 ], [ %71, %70 ]
%77 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%78 = call i32 @bzero(i8* %10, i32 16)
%79 = load i32, i32* @AF_INET
%80 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %79, i32* %80
%81 = call i32 @htons(i32 %76)
%82 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %81, i32* %82
%83 = call i64 @inet_addr(i8* %12)
%84 = load i64, i64* @INADDR_NONE
%85 = icmp eq i64 %83, %84
br i1 %85, label %88, label %86
86: ; preds = %75
%87 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i64 %83, i64* %87
br label %101
88: ; preds = %75
%89 = call %struct.hostent* @gethostbyname(i8* %12)
%90 = icmp eq %struct.hostent* %89, null
br i1 %90, label %91, label %95
91: ; preds = %88
%92 = load i32, i32* @stderr
%93 = call i32 @fprintf(i32 %92, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%94 = call i32 @exit(i32 0)
unreachable
95: ; preds = %88
%96 = getelementptr inbounds %struct.hostent, %struct.hostent* %89, i64 0, i32 1
%97 = load i64, i64* %96
%98 = inttoptr i64 %97 to i8*
%99 = getelementptr inbounds %struct.hostent, %struct.hostent* %89, i64 0, i32 0
%100 = load i32, i32* %99
br label %101
101: ; preds = %95, %86
%102 = load i32, i32* @AF_INET
%103 = load i32, i32* @SOCK_STREAM
%104 = call i32 @socket(i32 %102, i32 %103, i32 0)
%105 = icmp slt i32 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %101
%107 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %108
108: ; preds = %106, %101
br label %109
109: ; preds = %108, %113
%110 = phi i32 [ %115, %113 ], [ 1, %108 ]
%111 = call i32 @connect(i32 %104, %struct.sockaddr* %77, i32 16)
%112 = icmp eq i32 %111, -1
br i1 %112, label %113, label %119
113: ; preds = %109
%114 = call i32 @sleep(i32 1)
%115 = add nuw nsw i32 %110, 1
%116 = icmp eq i32 %115, 61
br i1 %116, label %117, label %109
117: ; preds = %113
%118 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %119
119: ; preds = %109, %117
%120 = bitcast %struct.timeval* %9 to i8*
%121 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 0
store i32 5, i32* %121
%122 = load i32, i32* @SOL_SOCKET
%123 = load i32, i32* @SO_RCVTIMEO
%124 = call i32 @setsockopt(i32 %104, i32 %122, i32 %123, %struct.timeval* %9, i32 4)
%125 = call i32 (...) @instruction()
%126 = call i32 @authenticate(i32 %104, i8* %14, i8* %15)
br label %127
127: ; preds = %147, %119
%128 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%129 = call i32 @bzero(i8* %11, i32 256)
%130 = load i32, i32* @stdin
%131 = call i32 @fgets(i8* %11, i32 256, i32 %130)
%132 = call i32 @bzero(i8* %13, i32 32768)
%133 = call i64 @send(i32 %104, i8* %11, i32 256, i32 0)
%134 = icmp slt i64 %133, 0
br i1 %134, label %135, label %137
135: ; preds = %127
%136 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %137
137: ; preds = %135, %127
%138 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%139 = icmp eq i64 %138, 0
br i1 %139, label %148, label %140
140: ; preds = %137
%141 = call i32 @receive_msg(i32 %104, i8* %13)
%142 = icmp sgt i32 %141, 0
br i1 %142, label %143, label %147
143: ; preds = %140
%144 = zext i32 %141 to i64
%145 = getelementptr inbounds [32768 x i8], [32768 x i8]* %6, i64 0, i64 %144
store i8 0, i8* %145
%146 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %13)
br label %147
147: ; preds = %143, %140
br label %127
148: ; preds = %137
%149 = call i32 @close(i32 %104)
ret i32 0
}