#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 /*<<< orphan*/ bzero(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int do_connect() {
  struct sockaddr_in addr_struct;
  int socket_descriptor;
  socket_descriptor = socket(AF_INET, SOCK_STREAM, 0);
  if (socket_descriptor == -1) {
    errx(-1, "Error creating socket");
  }
  addr_struct.sin_family = AF_INET;
  addr_struct.sin_port = htons(3001);
  addr_struct.sin_addr.s_addr = inet_addr("192.168.133.26");
  bzero(&(addr_struct.sin_zero), 8);
  if (connect(socket_descriptor, (struct sockaddr *)&addr_struct,
              sizeof(struct sockaddr)) == -1) {
    close(socket_descriptor);
    errx(-1, "Error connecting to the server");
  }
  return socket_descriptor;
}


x86 assembly (clang, -O0):
<do_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11af <do_connect+0x3f>
mov    $0xffffffff,%edi
lea    0xe56(%rip),%rsi
call   1030 <errx@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    $0xbb9,%edi
call   1040 <htons@plt>
mov    %eax,-0x8(%rbp)
lea    0xe47(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
jne    1218 <do_connect+0xa8>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    $0xffffffff,%edi
lea    0xe12(%rip),%rsi
call   1030 <errx@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_connect>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e6a(%rip),%r14
mov    (%r14),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11a9 <do_connect+0x39>
lea    0xe61(%rip),%rsi
mov    $0xffffffff,%edi
call   1030 <errx@plt>
mov    (%r14),%eax
mov    %eax,0x14(%rsp)
mov    $0xbb9,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0xe51(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x8,%esi
call   1070 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
jne    120c <do_connect+0x9c>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xe23(%rip),%rsi
mov    $0xffffffff,%edi
call   1030 <errx@plt>
mov    %ebx,%eax
add    $0x18,%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 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"Error creating socket\00"
@.str.1 = [15 x i8] c"192.168.133.26\00"
@.str.2 = [31 x i8] c"Error connecting to the server\00"
define i32 @do_connect() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = call i32 @socket(i32 %3, i32 %4, i32 0)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 3
store i32 %11, i32* %12
%13 = call i32 @htons(i32 3001)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i32 0, i32 0
%19 = call i32 @bzero(i32* %18, i32 8)
%20 = load i32, i32* %2
%21 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%22 = call i32 @connect(i32 %20, %struct.sockaddr* %21, i32 4)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %10
%25 = load i32, i32* %2
%26 = call i32 @close(i32 %25)
%27 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %24, %10
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"Error creating socket\00"
@.str.1 = [15 x i8] c"192.168.133.26\00"
@.str.2 = [31 x i8] c"Error connecting to the server\00"
define i32 @do_connect() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @errx(i32 -1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 3
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 3001)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %12, i32* %13
%14 = tail call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%17 = call i32 @bzero(i32* %16, i32 8)
%18 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%19 = call i32 @connect(i32 %5, %struct.sockaddr* %18, i32 4)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %9
%22 = call i32 @close(i32 %5)
%23 = call i32 @errx(i32 -1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %21, %9
ret i32 %5
}