#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 {
  void *sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ serverAddr;
typedef int /*<<< orphan*/ clientAddr;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "Usage: udpclient [IP_server] [server_port]\n");
    return -1;
  }
  int serverPort = atoi(argv[2]);
  if (serverPort <= 0 || serverPort > 65535) {
    fprintf(stderr, "The server port number given is wrong.\n");
    return -2;
  }
  int sockfd, bytesReceived;
  struct sockaddr_in serverAddr, clientAddr;
  struct hostent *hp;
  socklen_t len;
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    perror("Cannot open socket ");
    return -3;
  }
  hp = gethostbyname(argv[1]);
  if (hp == 0) {
    perror("Unknown Host ");
    close(sockfd);
    return -13;
  }
  bzero((char *)&clientAddr, sizeof(clientAddr));
  clientAddr.sin_family = AF_INET;
  clientAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  clientAddr.sin_port = htons(0);
  if (bind(sockfd, (struct sockaddr *)&clientAddr, sizeof(clientAddr)) < 0) {
    perror("Cannot bind ");
    close(sockfd);
    return -4;
  }
  bzero((char *)&serverAddr, sizeof(serverAddr));
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_addr.s_addr = inet_addr(argv[1]);
  serverAddr.sin_port = htons(serverPort);
  bool correctCredentials = false;
  char username[16], password[16], buffer[512];
  for (int i = 0; i < 3; i++) {
    printf("Please enter username:");
    gets(username);
    printf("Please enter password:");
    gets(password);
    strcpy(buffer, username);
    strcat(buffer, ":");
    strcat(buffer, password);
    sendto(sockfd, buffer, 512, 0, (struct sockaddr *)&serverAddr,
           sizeof(serverAddr));
    bytesReceived =
        recvfrom(sockfd, buffer, 512, 0, (struct sockaddr *)&clientAddr, &len);
    if (buffer[0] == '^' && buffer[1] == 'F') {
      correctCredentials = true;
      printf("You have connected successfully to the server.\n\n\n");
      char callFileServer[20] = "./tcpclient ";
      strcat(callFileServer, argv[1]);
      strcat(callFileServer, " 2424");
      system(callFileServer);
      close(sockfd);
      return 0;
    } else
      printf("The credentials you have provided are not valid.\n\n");
  }
  printf("You have provided three times wrong credentials.\n");
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1264 <main+0x44>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1570 <main+0x350>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    128b <main+0x6b>
cmpl   $0xffff,-0x14(%rbp)
jle    12ac <main+0x8c>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1570 <main+0x350>
mov    0x2d35(%rip),%rax
mov    (%rax),%rdi
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12eb <main+0xcb>
lea    0xd7a(%rip),%rdi
call   1100 <perror@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1570 <main+0x350>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1327 <main+0x107>
lea    0xd5a(%rip),%rdi
call   1100 <perror@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
movl   $0xfffffff3,-0x4(%rbp)
jmp    1570 <main+0x350>
lea    -0x50(%rbp),%rdi
mov    $0x18,%esi
call   1110 <bzero@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x48(%rbp)
xor    %edi,%edi
call   1050 <htons@plt>
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x18,%edx
call   10f0 <bind@plt>
cmp    $0x0,%rax
jge    139a <main+0x17a>
lea    0xcf5(%rip),%rdi
call   1100 <perror@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1570 <main+0x350>
lea    -0x38(%rbp),%rdi
mov    $0x18,%esi
call   1110 <bzero@plt>
mov    0x2c39(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <htons@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x284(%rbp)
cmpl   $0x3,-0x284(%rbp)
jge    1555 <main+0x335>
lea    0xc8c(%rip),%rdi
call   1060 <printf@plt>
lea    -0x70(%rbp),%rdi
call   10d0 <gets@plt>
lea    0xc8e(%rip),%rdi
call   1060 <printf@plt>
lea    -0x80(%rbp),%rdi
call   10d0 <gets@plt>
lea    -0x280(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x280(%rbp),%rdi
lea    0xc77(%rip),%rsi
call   1130 <strcat@plt>
lea    -0x280(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1130 <strcat@plt>
mov    -0x18(%rbp),%edi
lea    -0x280(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1080 <sendto@plt>
mov    -0x18(%rbp),%edi
lea    -0x280(%rbp),%rsi
lea    -0x50(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x5c(%rbp),%r9
call   10e0 <recvfrom@plt>
mov    %eax,-0x1c(%rbp)
movsbl -0x280(%rbp),%eax
cmp    $0x5e,%eax
jne    1530 <main+0x310>
movsbl -0x27f(%rbp),%eax
cmp    $0x46,%eax
jne    1530 <main+0x310>
movl   $0x1,-0x60(%rbp)
lea    0xbf5(%rip),%rdi
call   1060 <printf@plt>
mov    0xc88(%rip),%rax
mov    %rax,-0x2a0(%rbp)
mov    0xc82(%rip),%rax
mov    %rax,-0x298(%rbp)
mov    0xc7d(%rip),%eax
mov    %eax,-0x290(%rbp)
lea    -0x2a0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1130 <strcat@plt>
lea    -0x2a0(%rbp),%rdi
lea    0xbd8(%rip),%rsi
call   1130 <strcat@plt>
lea    -0x2a0(%rbp),%rdi
call   1040 <system@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1570 <main+0x350>
lea    0xbb2(%rip),%rdi
call   1060 <printf@plt>
jmp    1541 <main+0x321>
mov    -0x284(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x284(%rbp)
jmp    13e3 <main+0x1c3>
lea    0xbc0(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x288,%rsp
cmp    $0x3,%edi
jne    1280 <main+0x50>
mov    %rsi,%r12
mov    0x10(%rsi),%rdi
call   1130 <atoi@plt>
mov    %eax,%ebp
lea    -0x10000(%rbp),%eax
cmp    $0xffff0000,%eax
ja     129f <main+0x6f>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0xfffffffe,%eax
jmp    15d4 <main+0x3a4>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xd70(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    15d4 <main+0x3a4>
mov    0x2d42(%rip),%r13
mov    0x0(%r13),%rdi
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
test   %eax,%eax
js     1600 <main+0x3d0>
mov    %eax,%r14d
mov    0x8(%r12),%rdi
call   10c0 <gethostbyname@plt>
test   %rax,%rax
je     1613 <main+0x3e3>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x18,%esi
call   1120 <bzero@plt>
mov    0x0(%r13),%rax
mov    %rax,0x20(%rsp)
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x18(%rsp)
xor    %edi,%edi
call   1060 <htons@plt>
mov    %rax,0x10(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   1100 <bind@plt>
test   %rax,%rax
js     162e <main+0x3fe>
lea    0x28(%rsp),%r15
mov    %r15,%rdi
mov    $0x18,%esi
call   1120 <bzero@plt>
mov    0x0(%r13),%rax
mov    %rax,0x38(%rsp)
mov    0x8(%r12),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x30(%rsp)
mov    %ebp,%edi
call   1060 <htons@plt>
mov    %rax,0x28(%rsp)
lea    0xd1d(%rip),%rdi
call   1070 <printf@plt>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
call   10e0 <gets@plt>
lea    0xd1b(%rip),%rdi
call   1070 <printf@plt>
lea    0x40(%rsp),%r13
mov    %r13,%rdi
call   10e0 <gets@plt>
lea    0x80(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xd04(%rip),%rsi
mov    %rbp,%rdi
call   1140 <strcat@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1140 <strcat@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x18,%r9d
call   1090 <sendto@plt>
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   10f0 <recvfrom@plt>
cmpb   $0x5e,0x80(%rsp)
5e
jne    140d <main+0x1dd>
cmpb   $0x46,0x81(%rsp)
46
je     1581 <main+0x351>
lea    0xcd4(%rip),%rdi
call   1040 <puts@plt>
lea    0xc63(%rip),%rdi
call   1070 <printf@plt>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
call   10e0 <gets@plt>
lea    0xc61(%rip),%rdi
call   1070 <printf@plt>
lea    0x40(%rsp),%r15
mov    %r15,%rdi
call   10e0 <gets@plt>
lea    0x80(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xc4a(%rip),%rsi
mov    %rbp,%rdi
call   1140 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1140 <strcat@plt>
lea    0x28(%rsp),%r8
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1090 <sendto@plt>
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   10f0 <recvfrom@plt>
cmpb   $0x5e,0x80(%rsp)
5e
jne    14c9 <main+0x299>
cmpb   $0x46,0x81(%rsp)
46
je     1581 <main+0x351>
lea    0xc18(%rip),%rdi
call   1040 <puts@plt>
lea    0xba7(%rip),%rdi
call   1070 <printf@plt>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
call   10e0 <gets@plt>
lea    0xba5(%rip),%rdi
call   1070 <printf@plt>
lea    0x40(%rsp),%r15
mov    %r15,%rdi
call   10e0 <gets@plt>
lea    0x80(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xb8e(%rip),%rsi
mov    %rbp,%rdi
call   1140 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1140 <strcat@plt>
lea    0x28(%rsp),%r8
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1090 <sendto@plt>
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   10f0 <recvfrom@plt>
cmpb   $0x5e,0x80(%rsp)
5e
jne    15e6 <main+0x3b6>
cmpb   $0x46,0x81(%rsp)
46
jne    15e6 <main+0x3b6>
lea    0xb92(%rip),%rdi
call   1040 <puts@plt>
movaps 0xbbc(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movl   $0x0,0x70(%rsp)
mov    0x8(%r12),%rsi
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
call   1140 <strcat@plt>
lea    0xaf7(%rip),%rsi
mov    %rbx,%rdi
call   1140 <strcat@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x288,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xafb(%rip),%rdi
call   1040 <puts@plt>
lea    0xabe(%rip),%rdi
call   1040 <puts@plt>
jmp    15ca <main+0x39a>
lea    0xa4d(%rip),%rdi
call   1110 <perror@plt>
mov    $0xfffffffd,%eax
jmp    15d4 <main+0x3a4>
lea    0xa4e(%rip),%rdi
call   1110 <perror@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    $0xfffffff3,%eax
jmp    15d4 <main+0x3a4>
lea    0xa41(%rip),%rdi
call   1110 <perror@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    $0xfffffffc,%eax
jmp    15d4 <main+0x3a4>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [44 x i8] c"Usage: udpclient [IP_server] [server_port]\0A\00"
@.str.1 = [40 x i8] c"The server port number given is wrong.\0A\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.2 = [20 x i8] c"Cannot open socket \00"
@.str.3 = [14 x i8] c"Unknown Host \00"
@INADDR_ANY = global i32 0
@.str.4 = [13 x i8] c"Cannot bind \00"
@.str.5 = [23 x i8] c"Please enter username:\00"
@.str.6 = [23 x i8] c"Please enter password:\00"
@.str.7 = [2 x i8] c":\00"
@.str.8 = [50 x i8] c"You have connected successfully to the server.\0A\0A\0A\00"
@__const.main.callFileServer = [20 x i8] c"./tcpclient \00\00\00\00\00\00\00\00"
@.str.9 = [6 x i8] c" 2424\00"
@.str.10 = [51 x i8] c"The credentials you have provided are not valid.\0A\0A\00"
@.str.11 = [50 x i8] c"You have provided three times wrong credentials.\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 %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.hostent*
%12 = alloca i32
%13 = alloca i32
%14 = alloca [16 x i8]
%15 = alloca [16 x i8]
%16 = alloca [512 x i8]
%17 = alloca i32
%18 = alloca [20 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 3
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %148
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp sle i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %24
%32 = load i32, i32* %6
%33 = icmp sgt i32 %32, 65535
br i1 %33, label %34, label %37
34: ; preds = %31, %24
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %3
br label %148
37: ; preds = %31
%38 = load i8*, i8** @AF_INET
%39 = load i32, i32* @SOCK_DGRAM
%40 = call i32 @socket(i8* %38, i32 %39, i32 0)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 -3, i32* %3
br label %148
45: ; preds = %37
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call %struct.hostent* @gethostbyname(i8* %48)
store %struct.hostent* %49, %struct.hostent** %11
%50 = load %struct.hostent*, %struct.hostent** %11
%51 = icmp eq %struct.hostent* %50, null
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%54 = load i32, i32* %7
%55 = call i32 @close(i32 %54)
store i32 -13, i32* %3
br label %148
56: ; preds = %45
%57 = bitcast %struct.sockaddr_in* %10 to i8*
%58 = call i32 @bzero(i8* %57, i32 24)
%59 = load i8*, i8** @AF_INET
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i8* %59, i8** %60
%61 = load i32, i32* @INADDR_ANY
%62 = call i32 @htonl(i32 %61)
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%64 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %63, i32 0, i32 0
store i32 %62, i32* %64
%65 = call i8* @htons(i32 0)
%66 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i8* %65, i8** %66
%67 = load i32, i32* %7
%68 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%69 = call i64 @bind(i32 %67, %struct.sockaddr* %68, i32 24)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %56
%72 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%73 = load i32, i32* %7
%74 = call i32 @close(i32 %73)
store i32 -4, i32* %3
br label %148
75: ; preds = %56
%76 = bitcast %struct.sockaddr_in* %9 to i8*
%77 = call i32 @bzero(i8* %76, i32 24)
%78 = load i8*, i8** @AF_INET
%79 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i8* %78, i8** %79
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 1
%82 = load i8*, i8** %81
%83 = call i32 @inet_addr(i8* %82)
%84 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%85 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %84, i32 0, i32 0
store i32 %83, i32* %85
%86 = load i32, i32* %6
%87 = call i8* @htons(i32 %86)
%88 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i8* %87, i8** %88
store i32 0, i32* %13
store i32 0, i32* %17
br label %89
89: ; preds = %141, %75
%90 = load i32, i32* %17
%91 = icmp slt i32 %90, 3
br i1 %91, label %92, label %144
92: ; preds = %89
%93 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%94 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%95 = call i32 @gets(i8* %94)
%96 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%97 = getelementptr inbounds [16 x i8], [16 x i8]* %15, i64 0, i64 0
%98 = call i32 @gets(i8* %97)
%99 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%100 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%101 = call i32 @strcpy(i8* %99, i8* %100)
%102 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%103 = call i32 @strcat(i8* %102, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%104 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%105 = getelementptr inbounds [16 x i8], [16 x i8]* %15, i64 0, i64 0
%106 = call i32 @strcat(i8* %104, i8* %105)
%107 = load i32, i32* %7
%108 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%109 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%110 = call i32 @sendto(i32 %107, i8* %108, i32 512, i32 0, %struct.sockaddr* %109, i32 24)
%111 = load i32, i32* %7
%112 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%113 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%114 = call i32 @recvfrom(i32 %111, i8* %112, i32 512, i32 0, %struct.sockaddr* %113, i32* %12)
store i32 %114, i32* %8
%115 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%116 = load i8, i8* %115
%117 = sext i8 %116 to i32
%118 = icmp eq i32 %117, 94
br i1 %118, label %119, label %138
119: ; preds = %92
%120 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 1
%121 = load i8, i8* %120
%122 = sext i8 %121 to i32
%123 = icmp eq i32 %122, 70
br i1 %123, label %124, label %138
124: ; preds = %119
store i32 1, i32* %13
%125 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.8, i64 0, i64 0))
%126 = bitcast [20 x i8]* %18 to i8*
%127 = getelementptr inbounds [20 x i8], [20 x i8]* %18, i64 0, i64 0
%128 = load i8**, i8*** %5
%129 = getelementptr inbounds i8*, i8** %128, i64 1
%130 = load i8*, i8** %129
%131 = call i32 @strcat(i8* %127, i8* %130)
%132 = getelementptr inbounds [20 x i8], [20 x i8]* %18, i64 0, i64 0
%133 = call i32 @strcat(i8* %132, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%134 = getelementptr inbounds [20 x i8], [20 x i8]* %18, i64 0, i64 0
%135 = call i32 @system(i8* %134)
%136 = load i32, i32* %7
%137 = call i32 @close(i32 %136)
store i32 0, i32* %3
br label %148
138: ; preds = %119, %92
%139 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.10, i64 0, i64 0))
br label %140
140: ; preds = %138
br label %141
141: ; preds = %140
%142 = load i32, i32* %17
%143 = add nsw i32 %142, 1
store i32 %143, i32* %17
br label %89
144: ; preds = %89
%145 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.11, i64 0, i64 0))
%146 = load i32, i32* %7
%147 = call i32 @close(i32 %146)
store i32 0, i32* %3
br label %148
148: ; preds = %144, %124, %71, %52, %43, %34, %21
%149 = load i32, i32* %3
ret i32 %149
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [44 x i8] c"Usage: udpclient [IP_server] [server_port]\0A\00"
@.str.1 = [40 x i8] c"The server port number given is wrong.\0A\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.2 = [20 x i8] c"Cannot open socket \00"
@.str.3 = [14 x i8] c"Unknown Host \00"
@INADDR_ANY = global i32 0
@.str.4 = [13 x i8] c"Cannot bind \00"
@.str.5 = [23 x i8] c"Please enter username:\00"
@.str.6 = [23 x i8] c"Please enter password:\00"
@.str.7 = [2 x i8] c":\00"
@__const.main.callFileServer = [20 x i8] c"./tcpclient \00\00\00\00\00\00\00\00"
@.str.9 = [6 x i8] c" 2424\00"
@str = [49 x i8] c"You have provided three times wrong credentials.\00"
@str.12 = [50 x i8] c"The credentials you have provided are not valid.\0A\00"
@str.13 = [49 x i8] c"You have connected successfully to the server.\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = alloca [512 x i8]
%9 = alloca [20 x i8]
%10 = icmp eq i32 %0, 3
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %131
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = add i32 %17, -65536
%19 = icmp ult i32 %18, -65535
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %131
23: ; preds = %14
%24 = bitcast %struct.sockaddr_in* %3 to i8*
%25 = bitcast %struct.sockaddr_in* %4 to i8*
%26 = bitcast i32* %5 to i8*
%27 = load i8*, i8** @AF_INET
%28 = load i32, i32* @SOCK_DGRAM
%29 = tail call i32 @socket(i8* %27, i32 %28, i32 0)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %129
33: ; preds = %23
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = tail call %struct.hostent* @gethostbyname(i8* %35)
%37 = icmp eq %struct.hostent* %36, null
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%40 = tail call i32 @close(i32 %29)
br label %129
41: ; preds = %33
%42 = call i32 @bzero(i8* %25, i32 24)
%43 = load i8*, i8** @AF_INET
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %43, i8** %44
%45 = load i32, i32* @INADDR_ANY
%46 = tail call i32 @htonl(i32 %45)
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %46, i32* %47
%48 = tail call i8* @htons(i32 0)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i8* %48, i8** %49
%50 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%51 = call i64 @bind(i32 %29, %struct.sockaddr* %50, i32 24)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %41
%54 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%55 = call i32 @close(i32 %29)
br label %129
56: ; preds = %41
%57 = call i32 @bzero(i8* %24, i32 24)
%58 = load i8*, i8** @AF_INET
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %58, i8** %59
%60 = load i8*, i8** %34
%61 = call i32 @inet_addr(i8* %60)
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %61, i32* %62
%63 = call i8* @htons(i32 %17)
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i8* %63, i8** %64
%65 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%66 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%67 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%68 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%69 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 1
%70 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%71 = call i32 @gets(i8* %65)
%72 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%73 = call i32 @gets(i8* %66)
%74 = call i32 @strcpy(i8* %67, i8* %65)
%75 = call i32 @strcat(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%76 = call i32 @strcat(i8* %67, i8* %66)
%77 = call i32 @sendto(i32 %29, i8* %67, i32 512, i32 0, %struct.sockaddr* %68, i32 24)
%78 = call i32 @recvfrom(i32 %29, i8* %67, i32 512, i32 0, %struct.sockaddr* %50, i32* %5)
%79 = load i8, i8* %67
%80 = icmp eq i8 %79, 94
%81 = load i8, i8* %69
%82 = icmp eq i8 %81, 70
%83 = select i1 %80, i1 %82, i1 false
br i1 %83, label %84, label %92
84: ; preds = %108, %92, %56
%85 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.13, i64 0, i64 0))
%86 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%87 = load i8*, i8** %34
%88 = call i32 @strcat(i8* %86, i8* %87)
%89 = call i32 @strcat(i8* %86, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%90 = call i32 @system(i8* %86)
%91 = call i32 @close(i32 %29)
br label %128
92: ; preds = %56
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.12, i64 0, i64 0))
%94 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%95 = call i32 @gets(i8* %65)
%96 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%97 = call i32 @gets(i8* %66)
%98 = call i32 @strcpy(i8* %67, i8* %65)
%99 = call i32 @strcat(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%100 = call i32 @strcat(i8* %67, i8* %66)
%101 = call i32 @sendto(i32 %29, i8* %67, i32 512, i32 0, %struct.sockaddr* %68, i32 24)
%102 = call i32 @recvfrom(i32 %29, i8* %67, i32 512, i32 0, %struct.sockaddr* %50, i32* %5)
%103 = load i8, i8* %67
%104 = icmp eq i8 %103, 94
%105 = load i8, i8* %69
%106 = icmp eq i8 %105, 70
%107 = select i1 %104, i1 %106, i1 false
br i1 %107, label %84, label %108
108: ; preds = %92
%109 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.12, i64 0, i64 0))
%110 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%111 = call i32 @gets(i8* %65)
%112 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%113 = call i32 @gets(i8* %66)
%114 = call i32 @strcpy(i8* %67, i8* %65)
%115 = call i32 @strcat(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%116 = call i32 @strcat(i8* %67, i8* %66)
%117 = call i32 @sendto(i32 %29, i8* %67, i32 512, i32 0, %struct.sockaddr* %68, i32 24)
%118 = call i32 @recvfrom(i32 %29, i8* %67, i32 512, i32 0, %struct.sockaddr* %50, i32* %5)
%119 = load i8, i8* %67
%120 = icmp eq i8 %119, 94
%121 = load i8, i8* %69
%122 = icmp eq i8 %121, 70
%123 = select i1 %120, i1 %122, i1 false
br i1 %123, label %84, label %124
124: ; preds = %108
%125 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.12, i64 0, i64 0))
%126 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%127 = call i32 @close(i32 %29)
br label %128
128: ; preds = %84, %124
br label %129
129: ; preds = %128, %53, %38, %31
%130 = phi i32 [ -3, %31 ], [ -13, %38 ], [ -4, %53 ], [ 0, %128 ]
br label %131
131: ; preds = %20, %129, %11
%132 = phi i32 [ -1, %11 ], [ -2, %20 ], [ %130, %129 ]
ret i32 %132
}