#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 */
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
char *build_msg(char *, char *, char *);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ gen_err_msg(char *, char *, char *, int);
int /*<<< orphan*/ getaddrinfo(char *, char *, struct addrinfo *,
                               struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ put_err(int /*<<< orphan*/);
int /*<<< orphan*/ put_info(int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int conn_connect_socket(char *host, char *port) {
  int new = 0;
  struct addrinfo hints;
  struct addrinfo *res;
  put_info(gen_err_msg(
      "[1;32mINFO:[0m  ", build_msg("connecting to host: %s:%s", host, port),
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/janLo/htw-computer-networks-mailserver/refs/"
      "heads/master/connection.c",
      749));
  if ((new = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
    if (!0)
      put_err(gen_err_msg(
          "[1;31mERROR:[0m ", "socket creation",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/janLo/htw-computer-networks-mailserver/"
          "refs/heads/master/connection.c",
          752));
    return -1;
  }
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = IPPROTO_TCP;
  getaddrinfo(host, port, &hints, &res);
  if (connect(new, res->ai_addr, res->ai_addrlen) == -1) {
    if (!0)
      put_err(gen_err_msg(
          "[1;31mERROR:[0m ", "socket creation",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/janLo/htw-computer-networks-mailserver/"
          "refs/heads/master/connection.c",
          765));
    return -1;
  }
  freeaddrinfo(res);
  return new;
}


x86 assembly (clang, -O0):
<conn_connect_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe5d(%rip),%rdi
call   1060 <build_msg@plt>
mov    %rax,%rsi
lea    0xe3b(%rip),%rdi
lea    0xe61(%rip),%rdx
mov    $0x2ed,%ecx
call   1040 <gen_err_msg@plt>
mov    %eax,%edi
call   1090 <put_info@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1234 <conn_connect_socket+0xa4>
lea    0xec4(%rip),%rdi
lea    0xed0(%rip),%rsi
lea    0xe16(%rip),%rdx
mov    $0x2f0,%ecx
call   1040 <gen_err_msg@plt>
mov    %eax,%edi
call   1050 <put_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <conn_connect_socket+0x14c>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    -0x1c(%rbp),%edi
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
jne    12cd <conn_connect_socket+0x13d>
lea    0xe2b(%rip),%rdi
lea    0xe37(%rip),%rsi
lea    0xd7d(%rip),%rdx
mov    $0x2fd,%ecx
call   1040 <gen_err_msg@plt>
mov    %eax,%edi
call   1050 <put_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12dc <conn_connect_socket+0x14c>
mov    -0x38(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conn_connect_socket>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe6a(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <build_msg@plt>
lea    0xe45(%rip),%rdi
lea    0xe6b(%rip),%rdx
mov    %rax,%rsi
mov    $0x2ed,%ecx
call   1040 <gen_err_msg@plt>
mov    %eax,%edi
call   1090 <put_info@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    0x2dea(%rip),%r12
mov    (%r12),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     125f <conn_connect_socket+0xcf>
mov    %eax,%ebp
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    (%r12),%eax
mov    %eax,0x14(%rsp)
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <getaddrinfo@plt>
mov    (%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebp,%edi
call   1070 <connect@plt>
cmp    $0xffffffff,%eax
je     127b <conn_connect_socket+0xeb>
mov    (%rsp),%rdi
call   10a0 <freeaddrinfo@plt>
jmp    12a6 <conn_connect_socket+0x116>
lea    0xe67(%rip),%rdi
lea    0xe73(%rip),%rsi
lea    0xdb9(%rip),%rdx
mov    $0x2f0,%ecx
jmp    1295 <conn_connect_socket+0x105>
lea    0xe4b(%rip),%rdi
lea    0xe57(%rip),%rsi
lea    0xd9d(%rip),%rdx
mov    $0x2fd,%ecx
call   1040 <gen_err_msg@plt>
mov    %eax,%edi
call   1050 <put_err@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str = [19 x i8] c"\1B[1;32mINFO:\1B[0m \00"
@.str.1 = [26 x i8] c"connecting to host: %s:%s\00"
@.str.2 = [160 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/janLo/htw-computer-networks-mailserver/refs/heads/master/connection.c\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [19 x i8] c"\1B[1;31mERROR:\1B[0m \00"
@.str.4 = [16 x i8] c"socket creation\00"
@AF_INET = global i32 0
@IPPROTO_TCP = global i32 0
define i32 @conn_connect_socket(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.addrinfo
%8 = alloca %struct.addrinfo*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @build_msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %10)
%12 = call i32 @gen_err_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 749)
%13 = call i32 @put_info(i32 %12)
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 @gen_err_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 752)
%20 = call i32 @put_err(i32 %19)
store i32 -1, i32* %3
br label %48
21: ; preds = %2
%22 = call i32 @memset(%struct.addrinfo* %7, i32 0, i32 20)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 4
store i32 %23, i32* %24
%25 = load i32, i32* @SOCK_STREAM
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 3
store i32 %25, i32* %26
%27 = load i32, i32* @IPPROTO_TCP
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 2
store i32 %27, i32* %28
%29 = load i8*, i8** %4
%30 = load i8*, i8** %5
%31 = call i32 @getaddrinfo(i8* %29, i8* %30, %struct.addrinfo* %7, %struct.addrinfo** %8)
%32 = load i32, i32* %6
%33 = load %struct.addrinfo*, %struct.addrinfo** %8
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = load %struct.addrinfo*, %struct.addrinfo** %8
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @connect(i32 %32, i32 %35, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %21
%42 = call i32 @gen_err_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 765)
%43 = call i32 @put_err(i32 %42)
store i32 -1, i32* %3
br label %48
44: ; preds = %21
%45 = load %struct.addrinfo*, %struct.addrinfo** %8
%46 = call i32 @freeaddrinfo(%struct.addrinfo* %45)
%47 = load i32, i32* %6
store i32 %47, i32* %3
br label %48
48: ; preds = %44, %41, %18
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str = [19 x i8] c"\1B[1;32mINFO:\1B[0m \00"
@.str.1 = [26 x i8] c"connecting to host: %s:%s\00"
@.str.2 = [160 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/janLo/htw-computer-networks-mailserver/refs/heads/master/connection.c\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [19 x i8] c"\1B[1;31mERROR:\1B[0m \00"
@.str.4 = [16 x i8] c"socket creation\00"
@AF_INET = global i32 0
@IPPROTO_TCP = global i32 0
define i32 @conn_connect_socket(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = tail call i8* @build_msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
%8 = tail call i32 @gen_err_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 749)
%9 = tail call i32 @put_info(i32 %8)
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = tail call i32 @gen_err_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 752)
%16 = tail call i32 @put_err(i32 %15)
br label %39
17: ; preds = %2
%18 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 20)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %19, i32* %20
%21 = load i32, i32* @SOCK_STREAM
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %21, i32* %22
%23 = load i32, i32* @IPPROTO_TCP
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %3, %struct.addrinfo** %4)
%26 = load %struct.addrinfo*, %struct.addrinfo** %4
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @connect(i32 %12, i32 %28, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %17
%34 = call i32 @gen_err_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.2, i64 0, i64 0), i32 765)
%35 = call i32 @put_err(i32 %34)
br label %39
36: ; preds = %17
%37 = load %struct.addrinfo*, %struct.addrinfo** %4
%38 = call i32 @freeaddrinfo(%struct.addrinfo* %37)
br label %39
39: ; preds = %36, %33, %14
%40 = phi i32 [ -1, %14 ], [ -1, %33 ], [ %12, %36 ]
ret i32 %40
}