#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 {
  int /*<<< orphan*/ sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ listen(int, int);
int /*<<< orphan*/ logger(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int do_connect(int port) {
  char up[30];
  sprintf(up, "Subindo o Servidor na porta: %d\n", port);
  logger(up);
  struct sockaddr_in addr_server;
  int descriptor;
  if ((descriptor = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    errx(1, "Erro ao criar o socket");
  }
  addr_server.sin_family = AF_INET;
  addr_server.sin_port = htons(3001);
  addr_server.sin_addr.s_addr = inet_addr("192.168.133.26");
  bzero(&(addr_server.sin_zero), 8);
  if (bind(descriptor, (struct sockaddr *)&addr_server,
           sizeof(struct sockaddr)) == -1) {
    close(descriptor);
    errx(1, "Erro ao executar o bind");
  }
  if (listen(descriptor, 20) < 0) {
    close(descriptor);
    errx(1, "Erro ao executar o linten");
  }
  return descriptor;
}


x86 assembly (clang, -O0):
<do_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe47(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1070 <logger@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
jne    11fd <do_connect+0x5d>
mov    $0x1,%edi
lea    0xe29(%rip),%rsi
call   1030 <errx@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    $0xbb9,%edi
call   1040 <htons@plt>
mov    %eax,-0x38(%rbp)
lea    0xe1b(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x3c(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x8,%esi
call   10a0 <bzero@plt>
mov    -0x44(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x4,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    1266 <do_connect+0xc6>
mov    -0x44(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
lea    0xde6(%rip),%rsi
call   1030 <errx@plt>
mov    -0x44(%rbp),%edi
mov    $0x14,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
jge    1296 <do_connect+0xf6>
mov    -0x44(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
lea    0xdce(%rip),%rsi
call   1030 <errx@plt>
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_connect>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %edi,%edx
lea    0xe50(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <logger@plt>
mov    0x2e1c(%rip),%r14
mov    (%r14),%edi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11f7 <do_connect+0x57>
lea    0xe34(%rip),%rsi
mov    $0x1,%edi
call   1030 <errx@plt>
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    $0xbb9,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0xe25(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x8,%esi
call   10a0 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    1258 <do_connect+0xb8>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xdf9(%rip),%rsi
mov    $0x1,%edi
call   1030 <errx@plt>
mov    %ebx,%edi
mov    $0x14,%esi
call   1080 <listen@plt>
test   %rax,%rax
jns    1281 <do_connect+0xe1>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xde8(%rip),%rsi
mov    $0x1,%edi
call   1030 <errx@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [33 x i8] c"Subindo o Servidor na porta: %d\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [23 x i8] c"Erro ao criar o socket\00"
@.str.2 = [15 x i8] c"192.168.133.26\00"
@.str.3 = [24 x i8] c"Erro ao executar o bind\00"
@.str.4 = [26 x i8] c"Erro ao executar o linten\00"
define i32 @do_connect(i32 %0) {
%2 = alloca i32
%3 = alloca [30 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
store i32 %0, i32* %2
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* %2
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%10 = call i32 @logger(i8* %9)
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %1
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 3
store i32 %18, i32* %19
%20 = call i32 @htons(i32 3001)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%26 = call i32 @bzero(i32* %25, i32 8)
%27 = load i32, i32* %5
%28 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%29 = call i32 @bind(i32 %27, %struct.sockaddr* %28, i32 4)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %17
%32 = load i32, i32* %5
%33 = call i32 @close(i32 %32)
%34 = call i32 @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %31, %17
%36 = load i32, i32* %5
%37 = call i64 @listen(i32 %36, i32 20)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i32, i32* %5
%41 = call i32 @close(i32 %40)
%42 = call i32 @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %39, %35
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [33 x i8] c"Subindo o Servidor na porta: %d\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [23 x i8] c"Erro ao criar o socket\00"
@.str.2 = [15 x i8] c"192.168.133.26\00"
@.str.3 = [24 x i8] c"Erro ao executar o bind\00"
@.str.4 = [26 x i8] c"Erro ao executar o linten\00"
define i32 @do_connect(i32 %0) {
%2 = alloca [30 x i8]
%3 = alloca %struct.sockaddr_in
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = call i32 @logger(i8* %4)
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %15, i32* %16
%17 = call i32 @htons(i32 3001)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%22 = call i32 @bzero(i32* %21, i32 8)
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%24 = call i32 @bind(i32 %10, %struct.sockaddr* %23, i32 4)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %14
%27 = call i32 @close(i32 %10)
%28 = call i32 @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %26, %14
%30 = call i64 @listen(i32 %10, i32 20)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i32 @close(i32 %10)
%34 = call i32 @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %32, %29
ret i32 %10
}