#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 {
  TYPE_1__ sin_addr;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ *h_addr_list;
};
typedef int /*<<< orphan*/ server_addr;
typedef int /*<<< orphan*/ client_addr;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int bind(int, struct sockaddr *, int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ memcpy(void *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ process_response_code(unsigned char);
int send_token_to_server(int, char const *, int, unsigned char *);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int client_socket, res;
  unsigned char resp_code;
  struct sockaddr_in client_addr;
  struct sockaddr_in server_addr;
  struct hostent *hp;
  char *hostname;
  int port;
  char token[4 + 1];
  if (argc > 4) {
    fprintf(stderr, "Usage: %s [hostname] [port] [token]\n", argv[0]);
    return -1;
  }
  hostname = (argc >= 2) ? argv[1] : "localhost";
  port = (argc >= 3) ? atoi(argv[2]) : 5000;
  if (argc == 4) {
    memcpy(token, argv[3], 4);
    token[4] = '\0';
  }
  client_socket = socket(AF_INET, SOCK_STREAM, 0);
  if (client_socket < 0) {
    fprintf(stderr, "Could not create socket: %d\n", client_socket);
    return 1;
  }
  memset((char *)&client_addr, 0, sizeof(client_addr));
  client_addr.sin_family = AF_INET;
  client_addr.sin_port = htons(0);
  client_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  res =
      bind(client_socket, (struct sockaddr *)&client_addr, sizeof(client_addr));
  if (res < 0) {
    fprintf(stderr, "Could not bind the socket: %d\n", res);
    return 2;
  }
  hp = gethostbyname(hostname);
  if (!hp) {
    fprintf(stderr, "Could not find hostname %s\n", "localhost");
    return 3;
  }
  memset((char *)&server_addr, 0, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(port);
  memcpy((void *)&server_addr.sin_addr, hp->h_addr_list[0], hp->h_length);
  res = connect(client_socket, (struct sockaddr *)&server_addr,
                sizeof(server_addr));
  if (res < 0) {
    fprintf(stderr, "Could not connect to the server: %d\n", res);
    return 4;
  }
  res = send_token_to_server(client_socket, (const char *)token, 4, &resp_code);
  if (res < 0) {
    fprintf(stderr,
            "Error while communicating with the server (%d), shutting down\n",
            res);
    shutdown(client_socket, SHUT_RDWR);
    return 5;
  }
  process_response_code(resp_code);
  shutdown(client_socket, SHUT_RDWR);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jle    121d <main+0x4d>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b5 <main+0x2e5>
cmpl   $0x2,-0x8(%rbp)
jl     1238 <main+0x68>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x78(%rbp)
jmp    1248 <main+0x78>
lea    0xde6(%rip),%rax
mov    %rax,-0x78(%rbp)
jmp    1248 <main+0x78>
mov    -0x78(%rbp),%rax
mov    %rax,-0x60(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     126f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x7c(%rbp)
jmp    127c <main+0xac>
mov    $0x1388,%eax
mov    %eax,-0x7c(%rbp)
jmp    127c <main+0xac>
mov    -0x7c(%rbp),%eax
mov    %eax,-0x64(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    12a6 <main+0xd6>
lea    -0x69(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    $0x4,%edx
call   10a0 <memcpy@plt>
movb   $0x0,-0x65(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%rdi
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12f3 <main+0x123>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xd4f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14b5 <main+0x2e5>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
xor    %edi,%edi
call   1050 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x18,%edx
call   10b0 <bind@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1371 <main+0x1a1>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xcee(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    14b5 <main+0x2e5>
mov    -0x60(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    13b3 <main+0x1e3>
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
lea    0xcd2(%rip),%rsi
lea    0xc85(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    14b5 <main+0x2e5>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2c16(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x64(%rbp),%edi
call   1050 <htons@plt>
mov    %rax,-0x48(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%rax
movslq (%rax),%rsi
mov    -0x58(%rbp),%rax
mov    (%rax),%edx
call   10a0 <memcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x18,%edx
call   10e0 <connect@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    143b <main+0x26b>
mov    0x2bac(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xc5f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x4,-0x4(%rbp)
jmp    14b5 <main+0x2e5>
mov    -0x14(%rbp),%edi
lea    -0x69(%rbp),%rsi
mov    $0x4,%edx
lea    -0x19(%rbp),%rcx
call   1030 <send_token_to_server@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1494 <main+0x2c4>
mov    0x2b64(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xc3c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x14(%rbp),%edi
mov    0x2b6f(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
movl   $0x5,-0x4(%rbp)
jmp    14b5 <main+0x2e5>
movzbl -0x19(%rbp),%edi
call   10d0 <process_response_code@plt>
mov    -0x14(%rbp),%edi
mov    0x2b49(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
cmp    $0x5,%edi
jl     1208 <main+0x38>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe09(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1420 <main+0x250>
mov    %edi,%ebp
mov    $0x1388,%r14d
cmp    $0x2,%edi
jl     1246 <main+0x76>
mov    0x8(%rbx),%r15
je     124d <main+0x7d>
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
cmp    $0x4,%ebp
jne    124d <main+0x7d>
mov    0x18(%rbx),%rsi
lea    0xb(%rsp),%rdi
mov    $0x4,%edx
call   10a0 <memcpy@plt>
movb   $0x0,0xf(%rsp)
jmp    124d <main+0x7d>
lea    0xdd8(%rip),%r15
mov    0x2d8c(%rip),%r12
mov    (%r12),%rdi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     136a <main+0x19a>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x20(%rsp)
xor    %edi,%edi
call   1050 <htons@plt>
mov    %rax,0x18(%rsp)
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   10b0 <bind@plt>
test   %eax,%eax
js     138d <main+0x1bd>
mov    %r15,%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     13ad <main+0x1dd>
mov    %rax,%rbp
lea    0x28(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x38(%rsp)
mov    %r14d,%edi
call   1050 <htons@plt>
mov    %rax,0x30(%rsp)
mov    0x8(%rbp),%rax
movslq (%rax),%rsi
mov    0x0(%rbp),%edx
mov    %r15,%rdi
call   10a0 <memcpy@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x18,%edx
call   10e0 <connect@plt>
test   %eax,%eax
js     13d2 <main+0x202>
lea    0xb(%rsp),%rsi
lea    0xa(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <send_token_to_server@plt>
test   %eax,%eax
js     13f2 <main+0x222>
movzbl 0xa(%rsp),%edi
call   10d0 <process_response_code@plt>
mov    0x2c96(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <shutdown@plt>
xor    %eax,%eax
jmp    1420 <main+0x250>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
lea    0xcb5(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%eax
jmp    1420 <main+0x250>
mov    0x2c34(%rip),%rcx
mov    (%rcx),%edi
lea    0xcaf(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x2,%eax
jmp    1420 <main+0x250>
mov    0x2c14(%rip),%rax
mov    (%rax),%edi
lea    0xcae(%rip),%rsi
lea    0xc61(%rip),%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x3,%eax
jmp    1420 <main+0x250>
mov    0x2bef(%rip),%rcx
mov    (%rcx),%edi
lea    0xca5(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x4,%eax
jmp    1420 <main+0x250>
mov    0x2bcf(%rip),%rcx
mov    (%rcx),%edi
lea    0xcaa(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2bde(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <shutdown@plt>
mov    $0x5,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32* }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s [hostname] [port] [token]\0A\00"
@.str.1 = [10 x i8] c"localhost\00"
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@.str.2 = [29 x i8] c"Could not create socket: %d\0A\00"
@INADDR_ANY = global i32 0
@.str.3 = [31 x i8] c"Could not bind the socket: %d\0A\00"
@.str.4 = [28 x i8] c"Could not find hostname %s\0A\00"
@.str.5 = [37 x i8] c"Could not connect to the server: %d\0A\00"
@.str.6 = [63 x i8] c"Error while communicating with the server (%d), shutting down\0A\00"
@SHUT_RDWR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.hostent*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 4
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 -1, i32* %3
br label %139
23: ; preds = %2
%24 = load i32, i32* %4
%25 = icmp sge i32 %24, 2
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
br label %31
30: ; preds = %23
br label %31
31: ; preds = %30, %26
%32 = phi i8* [ %29, %26 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %30 ]
store i8* %32, i8** %12
%33 = load i32, i32* %4
%34 = icmp sge i32 %33, 3
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
br label %41
40: ; preds = %31
br label %41
41: ; preds = %40, %35
%42 = phi i32 [ %39, %35 ], [ 5000, %40 ]
store i32 %42, i32* %13
%43 = load i32, i32* %4
%44 = icmp eq i32 %43, 4
br i1 %44, label %45, label %52
45: ; preds = %41
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 0
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 @memcpy(i8* %46, i8* %49, i32 4)
%51 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 4
store i8 0, i8* %51
br label %52
52: ; preds = %45, %41
%53 = load i8*, i8** @AF_INET
%54 = load i32, i32* @SOCK_STREAM
%55 = call i32 @socket(i8* %53, i32 %54, i32 0)
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %52
%59 = load i32, i32* @stderr
%60 = load i32, i32* %6
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %60)
store i32 1, i32* %3
br label %139
62: ; preds = %52
%63 = bitcast %struct.sockaddr_in* %9 to i8*
%64 = call i32 @memset(i8* %63, i32 0, i32 24)
%65 = load i8*, i8** @AF_INET
%66 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i8* %65, i8** %66
%67 = call i8* @htons(i32 0)
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i8* %67, i8** %68
%69 = load i32, i32* @INADDR_ANY
%70 = call i32 @htonl(i32 %69)
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%72 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %71, i32 0, i32 0
store i32 %70, i32* %72
%73 = load i32, i32* %6
%74 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%75 = call i32 @bind(i32 %73, %struct.sockaddr* %74, i32 24)
store i32 %75, i32* %7
%76 = load i32, i32* %7
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %62
%79 = load i32, i32* @stderr
%80 = load i32, i32* %7
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %80)
store i32 2, i32* %3
br label %139
82: ; preds = %62
%83 = load i8*, i8** %12
%84 = call %struct.hostent* @gethostbyname(i8* %83)
store %struct.hostent* %84, %struct.hostent** %11
%85 = load %struct.hostent*, %struct.hostent** %11
%86 = icmp ne %struct.hostent* %85, null
br i1 %86, label %90, label %87
87: ; preds = %82
%88 = load i32, i32* @stderr
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 3, i32* %3
br label %139
90: ; preds = %82
%91 = bitcast %struct.sockaddr_in* %10 to i8*
%92 = call i32 @memset(i8* %91, i32 0, i32 24)
%93 = load i8*, i8** @AF_INET
%94 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i8* %93, i8** %94
%95 = load i32, i32* %13
%96 = call i8* @htons(i32 %95)
%97 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i8* %96, i8** %97
%98 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%99 = bitcast %struct.TYPE_2__* %98 to i8*
%100 = load %struct.hostent*, %struct.hostent** %11
%101 = getelementptr inbounds %struct.hostent, %struct.hostent* %100, i32 0, i32 1
%102 = load i32*, i32** %101
%103 = getelementptr inbounds i32, i32* %102, i64 0
%104 = load i32, i32* %103
%105 = sext i32 %104 to i64
%106 = inttoptr i64 %105 to i8*
%107 = load %struct.hostent*, %struct.hostent** %11
%108 = getelementptr inbounds %struct.hostent, %struct.hostent* %107, i32 0, i32 0
%109 = load i32, i32* %108
%110 = call i32 @memcpy(i8* %99, i8* %106, i32 %109)
%111 = load i32, i32* %6
%112 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%113 = call i32 @connect(i32 %111, %struct.sockaddr* %112, i32 24)
store i32 %113, i32* %7
%114 = load i32, i32* %7
%115 = icmp slt i32 %114, 0
br i1 %115, label %116, label %120
116: ; preds = %90
%117 = load i32, i32* @stderr
%118 = load i32, i32* %7
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %118)
store i32 4, i32* %3
br label %139
120: ; preds = %90
%121 = load i32, i32* %6
%122 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 0
%123 = call i32 @send_token_to_server(i32 %121, i8* %122, i32 4, i8* %8)
store i32 %123, i32* %7
%124 = load i32, i32* %7
%125 = icmp slt i32 %124, 0
br i1 %125, label %126, label %133
126: ; preds = %120
%127 = load i32, i32* @stderr
%128 = load i32, i32* %7
%129 = call i32 (i32, i8*, ...) @fprintf(i32 %127, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.6, i64 0, i64 0), i32 %128)
%130 = load i32, i32* %6
%131 = load i32, i32* @SHUT_RDWR
%132 = call i32 @shutdown(i32 %130, i32 %131)
store i32 5, i32* %3
br label %139
133: ; preds = %120
%134 = load i8, i8* %8
%135 = call i32 @process_response_code(i8 zeroext %134)
%136 = load i32, i32* %6
%137 = load i32, i32* @SHUT_RDWR
%138 = call i32 @shutdown(i32 %136, i32 %137)
store i32 0, i32* %3
br label %139
139: ; preds = %133, %126, %116, %87, %78, %58, %17
%140 = load i32, i32* %3
ret i32 %140
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
%struct.hostent = type { i32, i32* }
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s [hostname] [port] [token]\0A\00"
@.str.1 = [10 x i8] c"localhost\00"
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@.str.2 = [29 x i8] c"Could not create socket: %d\0A\00"
@INADDR_ANY = global i32 0
@.str.3 = [31 x i8] c"Could not bind the socket: %d\0A\00"
@.str.4 = [28 x i8] c"Could not find hostname %s\0A\00"
@.str.5 = [37 x i8] c"Could not connect to the server: %d\0A\00"
@.str.6 = [63 x i8] c"Error while communicating with the server (%d), shutting down\0A\00"
@SHUT_RDWR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [5 x i8]
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%10 = icmp sgt i32 %0, 4
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %95
15: ; preds = %2
%16 = icmp sgt i32 %0, 1
br i1 %16, label %17, label %31
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = icmp eq i32 %0, 2
br i1 %20, label %31, label %21
21: ; preds = %17
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
%25 = icmp eq i32 %0, 4
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = getelementptr inbounds i8*, i8** %1, i64 3
%28 = load i8*, i8** %27
%29 = call i32 @memcpy(i8* %9, i8* %28, i32 4)
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 4
store i8 0, i8* %30
br label %31
31: ; preds = %15, %17, %26, %21
%32 = phi i32 [ %24, %26 ], [ %24, %21 ], [ 5000, %17 ], [ 5000, %15 ]
%33 = phi i8* [ %19, %26 ], [ %19, %21 ], [ %19, %17 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %15 ]
%34 = load i8*, i8** @AF_INET
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @socket(i8* %34, i32 %35, i32 0)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %36)
br label %95
41: ; preds = %31
%42 = call i32 @memset(i8* %7, i32 0, 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 = call i8* @htons(i32 0)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i8* %45, i8** %46
%47 = load i32, i32* @INADDR_ANY
%48 = call i32 @htonl(i32 %47)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %48, i32* %49
%50 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%51 = call i32 @bind(i32 %36, %struct.sockaddr* %50, i32 24)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %41
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %51)
br label %95
56: ; preds = %41
%57 = call %struct.hostent* @gethostbyname(i8* %33)
%58 = icmp eq %struct.hostent* %57, null
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %95
62: ; preds = %56
%63 = call i32 @memset(i8* %8, i32 0, i32 24)
%64 = load i8*, i8** @AF_INET
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i8* %64, i8** %65
%66 = call i8* @htons(i32 %32)
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i8* %66, i8** %67
%68 = getelementptr inbounds %struct.hostent, %struct.hostent* %57, i64 0, i32 1
%69 = load i32*, i32** %68
%70 = load i32, i32* %69
%71 = sext i32 %70 to i64
%72 = inttoptr i64 %71 to i8*
%73 = getelementptr inbounds %struct.hostent, %struct.hostent* %57, i64 0, i32 0
%74 = load i32, i32* %73
%75 = call i32 @memcpy(i8* %8, i8* %72, i32 %74)
%76 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%77 = call i32 @connect(i32 %36, %struct.sockaddr* %76, i32 24)
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %62
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %77)
br label %95
82: ; preds = %62
%83 = call i32 @send_token_to_server(i32 %36, i8* %9, i32 4, i8* %3)
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %90
85: ; preds = %82
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.6, i64 0, i64 0), i32 %83)
%88 = load i32, i32* @SHUT_RDWR
%89 = call i32 @shutdown(i32 %36, i32 %88)
br label %95
90: ; preds = %82
%91 = load i8, i8* %3
%92 = call i32 @process_response_code(i8 zeroext %91)
%93 = load i32, i32* @SHUT_RDWR
%94 = call i32 @shutdown(i32 %36, i32 %93)
br label %95
95: ; preds = %90, %85, %79, %59, %53, %38, %11
%96 = phi i32 [ -1, %11 ], [ 1, %38 ], [ 2, %53 ], [ 4, %79 ], [ 5, %85 ], [ 0, %90 ], [ 3, %59 ]
ret i32 %96
}