#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 sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
struct sockaddr_in *Mem_alloc(int, char *, int);
scalar_t__ Mem_free(struct sockaddr_in *, char *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int net_createSocket();
int net_initSocket(struct sockaddr_in *, char *, int);
int Net_connect(char *host, int port) {
  int fd = -1;
  struct sockaddr_in *srvname = Mem_alloc(
      (sizeof(struct sockaddr_in)),
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/QubeX2/mangolib/refs/heads/master/src/net.c",
      182);
  if (net_initSocket(srvname, host, port) == -1) {
    return -1;
  } else {
    if ((fd = net_createSocket()) != -1) {
      if (connect(fd, (struct sockaddr *)srvname, sizeof(*srvname)) == -1) {
        close(fd);
        return -1;
      }
    }
    if (srvname == NULL) {
      close(fd);
      return -1;
    }
  }
  ((void)(Mem_free((srvname),
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/QubeX2/mangolib/refs/"
                   "heads/master/src/net.c",
                   200),
          (srvname) = 0));
  return fd;
}


x86 assembly (clang, -O0):
<Net_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    $0x4,%edi
lea    0xe7e(%rip),%rsi
mov    $0xb6,%edx
call   1070 <Mem_alloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <net_initSocket@plt>
cmp    $0xffffffff,%eax
jne    11b5 <Net_connect+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    1242 <Net_connect+0xe2>
mov    $0x0,%al
call   1060 <net_createSocket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     11fb <Net_connect+0x9b>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
jne    11f6 <Net_connect+0x96>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1242 <Net_connect+0xe2>
jmp    11fb <Net_connect+0x9b>
cmpq   $0x0,-0x20(%rbp)
jne    121a <Net_connect+0xba>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1242 <Net_connect+0xe2>
jmp    121f <Net_connect+0xbf>
mov    -0x20(%rbp),%rdi
lea    0xdd6(%rip),%rsi
mov    $0xc8,%edx
call   1050 <Mem_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Net_connect>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe8d(%rip),%rsi
mov    $0x4,%edi
mov    $0xb6,%edx
call   1070 <Mem_alloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <net_initSocket@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     11e4 <Net_connect+0x84>
xor    %eax,%eax
call   1060 <net_createSocket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11bf <Net_connect+0x5f>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
je     11dd <Net_connect+0x7d>
test   %r15,%r15
je     11dd <Net_connect+0x7d>
lea    0xe35(%rip),%rsi
mov    %r15,%rdi
mov    $0xc8,%edx
call   1050 <Mem_free@plt>
mov    %ebp,%r14d
jmp    11e4 <Net_connect+0x84>
mov    %ebp,%edi
call   1030 <close@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/QubeX2/mangolib/refs/heads/master/src/net.c\00"
define i32 @Net_connect(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 -1, i32* %6
%8 = call %struct.sockaddr_in* @Mem_alloc(i32 4, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 182)
store %struct.sockaddr_in* %8, %struct.sockaddr_in** %7
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%10 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = call i32 @net_initSocket(%struct.sockaddr_in* %9, i8* %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %39
15: ; preds = %2
%16 = call i32 (...) @net_createSocket()
store i32 %16, i32* %6
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i32, i32* %6
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%21 = bitcast %struct.sockaddr_in* %20 to %struct.sockaddr*
%22 = call i32 @connect(i32 %19, %struct.sockaddr* %21, i32 4)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
store i32 -1, i32* %3
br label %39
27: ; preds = %18
br label %28
28: ; preds = %27, %15
%29 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%30 = icmp eq %struct.sockaddr_in* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
store i32 -1, i32* %3
br label %39
34: ; preds = %28
br label %35
35: ; preds = %34
%36 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%37 = call i64 @Mem_free(%struct.sockaddr_in* %36, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 200)
store %struct.sockaddr_in* null, %struct.sockaddr_in** %7
%38 = load i32, i32* %6
store i32 %38, i32* %3
br label %39
39: ; preds = %35, %31, %24, %14
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/QubeX2/mangolib/refs/heads/master/src/net.c\00"
define i32 @Net_connect(i8* %0, i32 %1) {
%3 = tail call %struct.sockaddr_in* @Mem_alloc(i32 4, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 182)
%4 = tail call i32 @net_initSocket(%struct.sockaddr_in* %3, i8* %0, i32 %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = tail call i32 (...) @net_createSocket()
%8 = icmp eq i32 %7, -1
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%11 = tail call i32 @connect(i32 %7, %struct.sockaddr* %10, i32 4)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @close(i32 %7)
br label %21
15: ; preds = %9, %6
%16 = icmp eq %struct.sockaddr_in* %3, null
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 @close(i32 %7)
br label %21
19: ; preds = %15
%20 = tail call i64 @Mem_free(%struct.sockaddr_in* %3, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 200)
br label %21
21: ; preds = %2, %19, %17, %13
%22 = phi i32 [ -1, %13 ], [ -1, %17 ], [ %7, %19 ], [ -1, %2 ]
ret i32 %22
}