#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 uint16_t;
typedef int /*<<< orphan*/ transmit_data;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ primary;
typedef int int64_t;
typedef int /*<<< orphan*/ int32_t;
typedef int /*<<< orphan*/ data;
typedef int /*<<< orphan*/ code;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int connect(int /*<<< orphan*/, struct sockaddr *, int);
void *htons(int);
int /*<<< orphan*/ inet_aton(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohs(int);
int /*<<< orphan*/ printf(char *, ...);
size_t recv(int /*<<< orphan*/, int *, int, int /*<<< orphan*/);
size_t send(int /*<<< orphan*/, int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int strtol(char const *, char **, int /*<<< orphan*/);
int main(int argc, const char *argv[]) {
  if (argc == 3) {
    char *end;
    uint16_t port = strtol(argv[2], &end, 0);
    printf("Attempting to connect to %s over port %i\n", argv[1], port);
    struct sockaddr_in primary, data;
    int32_t connection = socket(AF_INET, SOCK_STREAM, 0);
    memset(&primary, 0, sizeof(primary));
    primary.sin_family = AF_INET;
    primary.sin_port = htons(port);
    inet_aton(argv[1], &primary.sin_addr);
    uint16_t new_port, code;
    size_t received_bytes, sent_bytes;
    bool connection_status =
        (connect(connection, (struct sockaddr *)&primary, sizeof(primary)) != -1
             ? true
             : false);
    if (connection_status) {
      printf("Connection Acquired\n");
      received_bytes = recv(connection, &new_port, sizeof(uint16_t), 0);
      new_port = ntohs(new_port);
      if (received_bytes > 0) {
        code = ((new_port < 49152) ? htons(500) : htons(1000));
        sent_bytes = send(connection, &code, sizeof(code), 0);
        received_bytes = recv(connection, &code, sizeof(uint16_t), 0);
        code = ntohs(code);
      }
    }
    printf("Response Code: %i -- %s\n", code,
           ((code == 1000) ? "Success"
                           : ((code == 500) ? "Failure" : "Unknown Response")));
    close(connection);
    if (code == 1000) {
      int32_t data_connection = socket(AF_INET, SOCK_STREAM, 0);
      memset(&data, 0, sizeof(data));
      data.sin_family = AF_INET;
      data.sin_port = htons(new_port);
      inet_aton(argv[1], &data.sin_addr);
      bool data_connection_status =
          (connect(data_connection, (struct sockaddr *)&data, sizeof(data)) !=
                   -1
               ? true
               : false);
      int64_t transmit_data;
      while (data_connection_status) {
        received_bytes =
            recv(data_connection, &transmit_data, sizeof(int64_t), 0);
        sent_bytes =
            send(data_connection, &transmit_data, sizeof(transmit_data), 0);
        data_connection_status =
            ((received_bytes > 0 && sent_bytes > 0) ? true : false);
      }
      close(data_connection);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    14b5 <main+0x305>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1090 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x54(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x38(%rbp),%rsi
call   10a0 <inet_aton@plt>
mov    -0x54(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <connect@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0xffffffff,%edx
cmovne %ecx,%eax
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
je     133e <main+0x18e>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x54(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%edi
call   10b0 <ntohs@plt>
mov    %eax,-0x58(%rbp)
cmpq   $0x0,-0x68(%rbp)
jbe    1339 <main+0x189>
cmpl   $0xc000,-0x58(%rbp)
jge    12e5 <main+0x135>
mov    $0x1f4,%edi
call   1040 <htons@plt>
mov    %rax,-0x88(%rbp)
jmp    12f6 <main+0x146>
mov    $0x3e8,%edi
call   1040 <htons@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
mov    %eax,-0x5c(%rbp)
mov    -0x54(%rbp),%edi
lea    -0x5c(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rax,-0x70(%rbp)
mov    -0x54(%rbp),%edi
lea    -0x5c(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x68(%rbp)
mov    -0x5c(%rbp),%edi
call   10b0 <ntohs@plt>
mov    %eax,-0x5c(%rbp)
jmp    133e <main+0x18e>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
cmpl   $0x3e8,-0x5c(%rbp)
jne    1367 <main+0x1b7>
lea    0xcfd(%rip),%rax
mov    %rax,-0x98(%rbp)
jmp    1389 <main+0x1d9>
mov    -0x5c(%rbp),%edx
lea    0xcf7(%rip),%rax
lea    0xce8(%rip),%rcx
cmp    $0x1f4,%edx
cmove  %rcx,%rax
mov    %rax,-0x98(%rbp)
mov    -0x8c(%rbp),%esi
mov    -0x98(%rbp),%rdx
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
cmpl   $0x3e8,-0x5c(%rbp)
jne    14b0 <main+0x300>
mov    0x2c28(%rip),%rax
mov    (%rax),%rdi
mov    0x2c0e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x78(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2bfb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x58(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x50(%rbp),%rsi
call   10a0 <inet_aton@plt>
mov    -0x78(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <connect@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0xffffffff,%edx
cmovne %ecx,%eax
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
je     14a8 <main+0x2f8>
mov    -0x78(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x68(%rbp)
mov    -0x78(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rax,-0x70(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x68(%rbp)
mov    %al,-0x99(%rbp)
jbe    148d <main+0x2dd>
cmpq   $0x0,-0x70(%rbp)
seta   %al
mov    %al,-0x99(%rbp)
mov    -0x99(%rbp),%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x7c(%rbp)
jmp    1434 <main+0x284>
mov    -0x78(%rbp),%edi
call   1080 <close@plt>
jmp    14b5 <main+0x305>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
cmp    $0x3,%edi
jne    13d4 <main+0x214>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    0x10(%rsi),%rdi
lea    0x40(%rsp),%rsi
xor    %edx,%edx
call   10a0 <strtol@plt>
mov    %eax,%ebx
mov    0x8(%r14),%rsi
lea    0xe09(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2de1(%rip),%r12
mov    (%r12),%rdi
mov    0x2dc6(%rip),%r13
mov    0x0(%r13),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
lea    0x28(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x38(%rsp)
mov    %ebx,%edi
call   1050 <htons@plt>
mov    %rax,0x30(%rsp)
mov    0x8(%r14),%rdi
mov    %r15,%rsi
call   10b0 <inet_aton@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x18,%edx
call   10d0 <connect@plt>
lea    0xdfa(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0x8(%rsp),%edi
call   10c0 <ntohs@plt>
mov    %eax,0x8(%rsp)
cmp    $0xc000,%eax
mov    $0x1f4,%eax
mov    $0x3e8,%edi
cmovl  %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0x4(%rsp),%edi
call   10c0 <ntohs@plt>
mov    %eax,0x4(%rsp)
cmp    $0x1f4,%eax
lea    0xd61(%rip),%rcx
lea    0xd62(%rip),%rsi
cmove  %rcx,%rsi
cmp    $0x3e8,%eax
lea    0xd42(%rip),%rdx
cmovne %rsi,%rdx
lea    0xd1e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
call   1090 <close@plt>
cmpl   $0x3e8,0x4(%rsp)
jne    13c6 <main+0x206>
mov    (%r12),%rdi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x20(%rsp)
mov    0x8(%rsp),%edi
call   1050 <htons@plt>
mov    %rax,0x18(%rsp)
mov    0x8(%r14),%rdi
mov    %rbx,%rsi
call   10b0 <inet_aton@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
je     13bf <main+0x1ff>
lea    0xc(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %rbx,%rbx
je     13bf <main+0x1ff>
test   %rax,%rax
jne    1390 <main+0x1d0>
mov    %ebp,%edi
call   1090 <close@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i8*, i8* }
%struct.sockaddr = type { i32 }
@.str = [42 x i8] c"Attempting to connect to %s over port %i\0A\00"
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"Connection Acquired\0A\00"
@.str.2 = [25 x i8] c"Response Code: %i -- %s\0A\00"
@.str.3 = [8 x i8] c"Success\00"
@.str.4 = [8 x i8] c"Failure\00"
@.str.5 = [17 x i8] c"Unknown Response\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 3
br i1 %20, label %21, label %137
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @strtol(i8* %24, i8** %6, i32 0)
store i32 %25, i32* %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i32, i32* %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %28, i32 %29)
%31 = load i8*, i8** @AF_INET
%32 = load i32, i32* @SOCK_STREAM
%33 = call i32 @socket(i8* %31, i32 %32, i32 0)
store i32 %33, i32* %10
%34 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 24)
%35 = load i8*, i8** @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i8* %35, i8** %36
%37 = load i32, i32* %7
%38 = call i8* @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i8* %38, i8** %39
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%44 = call i32 @inet_aton(i8* %42, i32* %43)
%45 = load i32, i32* %10
%46 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%47 = call i32 @connect(i32 %45, %struct.sockaddr* %46, i32 24)
%48 = icmp ne i32 %47, -1
%49 = zext i1 %48 to i64
%50 = select i1 %48, i32 1, i32 0
store i32 %50, i32* %15
%51 = load i32, i32* %15
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %78
53: ; preds = %21
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%55 = load i32, i32* %10
%56 = call i64 @recv(i32 %55, i32* %11, i32 4, i32 0)
store i64 %56, i64* %13
%57 = load i32, i32* %11
%58 = call i32 @ntohs(i32 %57)
store i32 %58, i32* %11
%59 = load i64, i64* %13
%60 = icmp ugt i64 %59, 0
br i1 %60, label %61, label %77
61: ; preds = %53
%62 = load i32, i32* %11
%63 = icmp slt i32 %62, 49152
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = call i8* @htons(i32 500)
br label %68
66: ; preds = %61
%67 = call i8* @htons(i32 1000)
br label %68
68: ; preds = %66, %64
%69 = phi i8* [ %65, %64 ], [ %67, %66 ]
%70 = ptrtoint i8* %69 to i32
store i32 %70, i32* %12
%71 = load i32, i32* %10
%72 = call i64 @send(i32 %71, i32* %12, i32 4, i32 0)
store i64 %72, i64* %14
%73 = load i32, i32* %10
%74 = call i64 @recv(i32 %73, i32* %12, i32 4, i32 0)
store i64 %74, i64* %13
%75 = load i32, i32* %12
%76 = call i32 @ntohs(i32 %75)
store i32 %76, i32* %12
br label %77
77: ; preds = %68, %53
br label %78
78: ; preds = %77, %21
%79 = load i32, i32* %12
%80 = load i32, i32* %12
%81 = icmp eq i32 %80, 1000
br i1 %81, label %82, label %83
82: ; preds = %78
br label %88
83: ; preds = %78
%84 = load i32, i32* %12
%85 = icmp eq i32 %84, 500
%86 = zext i1 %85 to i64
%87 = select i1 %85, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0)
br label %88
88: ; preds = %83, %82
%89 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %82 ], [ %87, %83 ]
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %79, i8* %89)
%91 = load i32, i32* %10
%92 = call i32 @close(i32 %91)
%93 = load i32, i32* %12
%94 = icmp eq i32 %93, 1000
br i1 %94, label %95, label %136
95: ; preds = %88
%96 = load i8*, i8** @AF_INET
%97 = load i32, i32* @SOCK_STREAM
%98 = call i32 @socket(i8* %96, i32 %97, i32 0)
store i32 %98, i32* %16
%99 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 24)
%100 = load i8*, i8** @AF_INET
%101 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i8* %100, i8** %101
%102 = load i32, i32* %11
%103 = call i8* @htons(i32 %102)
%104 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i8* %103, i8** %104
%105 = load i8**, i8*** %5
%106 = getelementptr inbounds i8*, i8** %105, i64 1
%107 = load i8*, i8** %106
%108 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%109 = call i32 @inet_aton(i8* %107, i32* %108)
%110 = load i32, i32* %16
%111 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%112 = call i32 @connect(i32 %110, %struct.sockaddr* %111, i32 24)
%113 = icmp ne i32 %112, -1
%114 = zext i1 %113 to i64
%115 = select i1 %113, i32 1, i32 0
store i32 %115, i32* %17
br label %116
116: ; preds = %129, %95
%117 = load i32, i32* %17
%118 = icmp ne i32 %117, 0
br i1 %118, label %119, label %133
119: ; preds = %116
%120 = load i32, i32* %16
%121 = call i64 @recv(i32 %120, i32* %18, i32 4, i32 0)
store i64 %121, i64* %13
%122 = load i32, i32* %16
%123 = call i64 @send(i32 %122, i32* %18, i32 4, i32 0)
store i64 %123, i64* %14
%124 = load i64, i64* %13
%125 = icmp ugt i64 %124, 0
br i1 %125, label %126, label %129
126: ; preds = %119
%127 = load i64, i64* %14
%128 = icmp ugt i64 %127, 0
br label %129
129: ; preds = %126, %119
%130 = phi i1 [ false, %119 ], [ %128, %126 ]
%131 = zext i1 %130 to i64
%132 = select i1 %130, i32 1, i32 0
store i32 %132, i32* %17
br label %116
133: ; preds = %116
%134 = load i32, i32* %16
%135 = call i32 @close(i32 %134)
br label %136
136: ; preds = %133, %88
br label %137
137: ; preds = %136, %2
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i8*, i8* }
%struct.sockaddr = type { i32 }
@.str = [42 x i8] c"Attempting to connect to %s over port %i\0A\00"
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@.str.2 = [25 x i8] c"Response Code: %i -- %s\0A\00"
@.str.3 = [8 x i8] c"Success\00"
@.str.4 = [8 x i8] c"Failure\00"
@.str.5 = [17 x i8] c"Unknown Response\00"
@str = [20 x i8] c"Connection Acquired\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = icmp eq i32 %0, 3
br i1 %9, label %10, label %84
10: ; preds = %2
%11 = bitcast i8** %3 to i8*
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = call i32 @strtol(i8* %13, i8** %3, i32 0)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %14)
%18 = bitcast %struct.sockaddr_in* %4 to i8*
%19 = bitcast %struct.sockaddr_in* %5 to i8*
%20 = load i8*, i8** @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = tail call i32 @socket(i8* %20, i32 %21, i32 0)
%23 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 24)
%24 = load i8*, i8** @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %24, i8** %25
%26 = call i8* @htons(i32 %14)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i8* %26, i8** %27
%28 = load i8*, i8** %15
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%30 = call i32 @inet_aton(i8* %28, i32* %29)
%31 = bitcast i32* %6 to i8*
%32 = bitcast i32* %7 to i8*
%33 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%34 = call i32 @connect(i32 %22, %struct.sockaddr* %33, i32 24)
%35 = icmp ne i32 %34, -1
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%37 = call i64 @recv(i32 %22, i32* %6, i32 4, i32 0)
%38 = load i32, i32* %6
%39 = call i32 @ntohs(i32 %38)
store i32 %39, i32* %6
%40 = icmp ne i64 %37, 0
%41 = icmp slt i32 %39, 49152
%42 = select i1 %41, i32 500, i32 1000
%43 = call i8* @htons(i32 %42)
%44 = ptrtoint i8* %43 to i64
%45 = trunc i64 %44 to i32
store i32 %45, i32* %7
%46 = call i64 @send(i32 %22, i32* %7, i32 4, i32 0)
%47 = call i64 @recv(i32 %22, i32* %7, i32 4, i32 0)
%48 = load i32, i32* %7
%49 = call i32 @ntohs(i32 %48)
store i32 %49, i32* %7
%50 = icmp eq i32 %49, 1000
%51 = icmp eq i32 %49, 500
%52 = select i1 %51, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0)
%53 = select i1 %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %52
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %49, i8* %53)
%55 = call i32 @close(i32 %22)
%56 = load i32, i32* %7
%57 = icmp eq i32 %56, 1000
br i1 %57, label %58, label %83
58: ; preds = %10
%59 = load i8*, i8** @AF_INET
%60 = load i32, i32* @SOCK_STREAM
%61 = call i32 @socket(i8* %59, i32 %60, i32 0)
%62 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 24)
%63 = load i8*, i8** @AF_INET
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i8* %63, i8** %64
%65 = load i32, i32* %6
%66 = call i8* @htons(i32 %65)
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i8* %66, i8** %67
%68 = load i8*, i8** %15
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%70 = call i32 @inet_aton(i8* %68, i32* %69)
%71 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%72 = call i32 @connect(i32 %61, %struct.sockaddr* %71, i32 24)
%73 = icmp eq i32 %72, -1
%74 = bitcast i32* %8 to i8*
br i1 %73, label %81, label %75
75: ; preds = %58, %75
%76 = call i64 @recv(i32 %61, i32* %8, i32 4, i32 0)
%77 = call i64 @send(i32 %61, i32* %8, i32 4, i32 0)
%78 = icmp ne i64 %76, 0
%79 = icmp ne i64 %77, 0
%80 = select i1 %78, i1 %79, i1 false
br i1 %80, label %75, label %81
81: ; preds = %75, %58
%82 = call i32 @close(i32 %61)
br label %83
83: ; preds = %81, %10
br label %84
84: ; preds = %83, %2
ret i32 0
}