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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ntohs(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int chat_client_connect(char *host, int port) {
  struct sockaddr_in sock;
  struct hostent *server;
  int server_socket_fd, ret;
  if ((server_socket_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    fprintf(stderr, "%s:%d >> Error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/"
            "client.c",
            89, "Can't create socket");
    exit(EXIT_FAILURE);
  };
  memset((char *)&sock, 0, sizeof(sock));
  if ((server = gethostbyname(host)) == NULL) {
    fprintf(stderr, "%s:%d >> Error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/"
            "client.c",
            96, "No such host");
    exit(EXIT_FAILURE);
  };
  sock.sin_family = AF_INET;
  sock.sin_port = ntohs(port);
  bcopy((char *)server->h_addr, (char *)&sock.sin_addr.s_addr,
        server->h_length);
  if ((ret = connect(server_socket_fd, (struct sockaddr *)&sock,
                     sizeof(sock))) < 0) {
    fprintf(stderr, "%s:%d >> Error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/"
            "client.c",
            105, "Error connecting to server");
    exit(EXIT_FAILURE);
  };
  fprintf(stdout, "\033[41m[--]\033[0m "
                  "Connected to server!\n");
  return server_socket_fd;
}


x86 assembly (clang, -O0):
<chat_client_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11ec <chat_client_connect+0x6c>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
lea    0xe49(%rip),%rdx
mov    $0x59,%ecx
lea    0xec7(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    124b <chat_client_connect+0xcb>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
lea    0xdea(%rip),%rdx
mov    $0x60,%ecx
lea    0xe7c(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <ntohs@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1060 <bcopy@plt>
mov    -0x24(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    12ce <chat_client_connect+0x14e>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
lea    0xd67(%rip),%rdx
mov    $0x69,%ecx
lea    0xe06(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chat_client_connect>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
mov    0x2e51(%rip),%r15
mov    (%r15),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1237 <chat_client_connect+0xb7>
mov    %eax,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
mov    %rbp,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     125c <chat_client_connect+0xdc>
mov    %rax,%rbp
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    %r14d,%edi
call   1060 <ntohs@plt>
mov    %eax,0xc(%rsp)
mov    0x8(%rbp),%rsi
mov    0x0(%rbp),%edx
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <memmove@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
test   %eax,%eax
js     1281 <chat_client_connect+0x101>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xeb7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
lea    0xdc6(%rip),%rdx
lea    0xe49(%rip),%r8
mov    $0x59,%ecx
jmp    12a4 <chat_client_connect+0x124>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
lea    0xda1(%rip),%rdx
lea    0xe38(%rip),%r8
mov    $0x60,%ecx
jmp    12a4 <chat_client_connect+0x124>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xd6f(%rip),%rsi
lea    0xd7c(%rip),%rdx
lea    0xe20(%rip),%r8
mov    $0x69,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"%s:%d >> Error: %s\0A\00"
@.str.1 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/client.c\00"
@.str.2 = [20 x i8] c"Can't create socket\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [13 x i8] c"No such host\00"
@.str.4 = [27 x i8] c"Error connecting to server\00"
@stdout = global i32 0
@.str.5 = [36 x i8] c"\1B[41m[--]\1B[0m Connected to server!\0A\00"
define i32 @chat_client_connect(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.hostent*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 89, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = bitcast %struct.sockaddr_in* %5 to i8*
%20 = call i32 @memset(i8* %19, i32 0, i32 12)
%21 = load i8*, i8** %3
%22 = call %struct.hostent* @gethostbyname(i8* %21)
store %struct.hostent* %22, %struct.hostent** %6
%23 = icmp eq %struct.hostent* %22, null
br i1 %23, label %24, label %29
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 96, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %18
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i32, i32* %4
%33 = call i32 @ntohs(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %33, i32* %34
%35 = load %struct.hostent*, %struct.hostent** %6
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %35, i32 0, i32 1
%37 = load i64, i64* %36
%38 = inttoptr i64 %37 to i8*
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
%41 = bitcast i32* %40 to i8*
%42 = load %struct.hostent*, %struct.hostent** %6
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i32 @bcopy(i8* %38, i8* %41, i32 %44)
%46 = load i32, i32* %7
%47 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%48 = call i32 @connect(i32 %46, %struct.sockaddr* %47, i32 12)
store i32 %48, i32* %8
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %29
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 105, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %29
%56 = load i32, i32* @stdout
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%58 = load i32, i32* %7
ret i32 %58
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"%s:%d >> Error: %s\0A\00"
@.str.1 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/client.c\00"
@.str.2 = [20 x i8] c"Can't create socket\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [13 x i8] c"No such host\00"
@.str.4 = [27 x i8] c"Error connecting to server\00"
@stdout = global i32 0
@.str.5 = [36 x i8] c"\1B[41m[--]\1B[0m Connected to server!\0A\00"
define i32 @chat_client_connect(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 89, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = call i32 @memset(i8* %4, i32 0, i32 12)
%16 = call %struct.hostent* @gethostbyname(i8* %0)
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 96, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %14
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @ntohs(i32 %1)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i64 0, i32 1
%29 = load i64, i64* %28
%30 = inttoptr i64 %29 to i8*
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i64 0, i32 0
%32 = load i32, i32* %31
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%34 = call i32 @connect(i32 %7, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %23
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 105, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %23
%42 = load i32, i32* @stdout
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
ret i32 %7
}