#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__ {
  long s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_zero;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ portnum;
typedef int /*<<< orphan*/ hostname;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ abort();
int atoi(char *);
int connect(int, struct sockaddr *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strchr(char *, char);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int create_socket(char url_str[], BIO *out) {
  int sockfd;
  char hostname[256] = "";
  char portnum[6] = "443";
  char proto[6] = "";
  char *tmp_ptr = NULL;
  int port;
  struct hostent *host;
  struct sockaddr_in dest_addr;
  if (url_str[strlen(url_str)] == '/')
    url_str[strlen(url_str)] = '\0';
  strncpy(proto, url_str, (strchr(url_str, ':') - url_str));
  strncpy(hostname, strstr(url_str, "://") + 3, sizeof(hostname));
  if (strchr(hostname, ':')) {
    tmp_ptr = strchr(hostname, ':');
    strncpy(portnum, tmp_ptr + 1, sizeof(portnum));
    *tmp_ptr = '\0';
  }
  port = atoi(portnum);
  if ((host = gethostbyname(hostname)) == NULL) {
    abort();
  }
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  dest_addr.sin_family = AF_INET;
  dest_addr.sin_port = htons(port);
  dest_addr.sin_addr.s_addr = *(long *)(host->h_addr);
  memset(&(dest_addr.sin_zero), '\0', 8);
  tmp_ptr = inet_ntoa(dest_addr.sin_addr);
  if (connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) ==
      -1) {
  }
  return sockfd;
}


x86 assembly (clang, -O0):
<create_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
mov    0xe14(%rip),%eax
mov    %eax,-0x126(%rbp)
mov    0xe0b(%rip),%ax
mov    %ax,-0x122(%rbp)
lea    -0x12c(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1090 <memset@plt>
movq   $0x0,-0x138(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x168(%rbp),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    126b <create_socket+0xab>
mov    -0x8(%rbp),%rax
mov    %rax,-0x170(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x170(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
lea    -0x12c(%rbp),%rax
mov    %rax,-0x188(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x180(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
mov    -0x188(%rbp),%rdi
mov    -0x180(%rbp),%rsi
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
lea    -0x120(%rbp),%rax
mov    %rax,-0x178(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd3f(%rip),%rsi
call   10d0 <strstr@plt>
mov    -0x178(%rbp),%rdi
mov    %rax,%rsi
add    $0x3,%rsi
mov    $0x100,%edx
call   1040 <strncpy@plt>
lea    -0x120(%rbp),%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
cmp    $0x0,%rax
je     133d <create_socket+0x17d>
lea    -0x120(%rbp),%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
mov    %rax,-0x138(%rbp)
lea    -0x126(%rbp),%rdi
mov    -0x138(%rbp),%rsi
add    $0x1,%rsi
mov    $0x6,%edx
call   1040 <strncpy@plt>
mov    -0x138(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x126(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x13c(%rbp)
lea    -0x120(%rbp),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x148(%rbp)
cmp    $0x0,%rax
jne    1373 <create_socket+0x1b3>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
mov    0x2c55(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2c52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
mov    -0x13c(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x154(%rbp)
mov    -0x148(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x160(%rbp)
lea    -0x160(%rbp),%rdi
add    $0x8,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    -0x160(%rbp),%rdi
call   1050 <inet_ntoa@plt>
mov    %rax,-0x138(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x160(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
jne    140f <create_socket+0x24f>
jmp    140f <create_socket+0x24f>
mov    -0x14(%rbp),%eax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x138,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movw   $0x0,0xc(%rsp)
movl   $0x333434,0x8(%rsp)
movw   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
call   1060 <strlen@plt>
cmpb   $0x2f,(%rbx,%rax,1)
jne    1271 <create_socket+0xb1>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
sub    %ebx,%eax
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
lea    0xd70(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <strstr@plt>
lea    0x3(%rax),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%edx
call   1040 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1080 <strchr@plt>
test   %rax,%rax
je     12e2 <create_socket+0x122>
mov    %rax,%rbx
mov    %rax,%rsi
add    $0x1,%rsi
lea    0x8(%rsp),%rdi
mov    $0x6,%edx
call   1040 <strncpy@plt>
movb   $0x0,(%rbx)
lea    0x8(%rsp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r14d
lea    0x30(%rsp),%rdi
call   10a0 <gethostbyname@plt>
test   %rax,%rax
je     1378 <create_socket+0x1b8>
mov    %rax,%rbp
mov    0x2ce0(%rip),%r15
mov    (%r15),%edi
mov    0x2cc6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
mov    (%r15),%eax
mov    %eax,0x28(%rsp)
mov    %r14d,%edi
call   1070 <htons@plt>
mov    %eax,0x24(%rsp)
mov    0x0(%rbp),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    0x18(%rsp),%rdi
call   1050 <inet_ntoa@plt>
lea    0x18(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   10c0 <connect@plt>
mov    %ebx,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@__const.create_socket.portnum = [6 x i8] c"443\00\00\00"
@.str = [4 x i8] c"://\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @create_socket(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca [6 x i8]
%8 = alloca [6 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca %struct.hostent*
%12 = alloca %struct.sockaddr_in
store i8* %0, i8** %3
store i32* %1, i32** %4
%13 = bitcast [256 x i8]* %6 to i8*
%14 = bitcast [6 x i8]* %7 to i8*
%15 = bitcast [6 x i8]* %8 to i8*
store i8* null, i8** %9
%16 = load i8*, i8** %3
%17 = load i8*, i8** %3
%18 = call i64 @strlen(i8* %17)
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %28
23: ; preds = %2
%24 = load i8*, i8** %3
%25 = load i8*, i8** %3
%26 = call i64 @strlen(i8* %25)
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %23, %2
%29 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%30 = load i8*, i8** %3
%31 = load i8*, i8** %3
%32 = call i8* @strchr(i8* %31, i8 signext 58)
%33 = load i8*, i8** %3
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = trunc i64 %36 to i32
%38 = call i32 @strncpy(i8* %29, i8* %30, i32 %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%40 = load i8*, i8** %3
%41 = call i8* @strstr(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%42 = getelementptr inbounds i8, i8* %41, i64 3
%43 = call i32 @strncpy(i8* %39, i8* %42, i32 256)
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%45 = call i8* @strchr(i8* %44, i8 signext 58)
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %55
47: ; preds = %28
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%49 = call i8* @strchr(i8* %48, i8 signext 58)
store i8* %49, i8** %9
%50 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%51 = load i8*, i8** %9
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = call i32 @strncpy(i8* %50, i8* %52, i32 6)
%54 = load i8*, i8** %9
store i8 0, i8* %54
br label %55
55: ; preds = %47, %28
%56 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%57 = call i32 @atoi(i8* %56)
store i32 %57, i32* %10
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%59 = call %struct.hostent* @gethostbyname(i8* %58)
store %struct.hostent* %59, %struct.hostent** %11
%60 = icmp eq %struct.hostent* %59, null
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = call i32 (...) @abort()
unreachable
63: ; preds = %55
%64 = load i32, i32* @AF_INET
%65 = load i32, i32* @SOCK_STREAM
%66 = call i32 @socket(i32 %64, i32 %65, i32 0)
store i32 %66, i32* %5
%67 = load i32, i32* @AF_INET
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 3
store i32 %67, i32* %68
%69 = load i32, i32* %10
%70 = call i32 @htons(i32 %69)
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %70, i32* %71
%72 = load %struct.hostent*, %struct.hostent** %11
%73 = getelementptr inbounds %struct.hostent, %struct.hostent* %72, i32 0, i32 0
%74 = load i64, i64* %73
%75 = inttoptr i64 %74 to i64*
%76 = load i64, i64* %75
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%78 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %77, i32 0, i32 0
store i64 %76, i64* %78
%79 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%80 = call i32 @memset(i32* %79, i8 signext 0, i32 8)
%81 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%82 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %81, i32 0, i32 0
%83 = load i64, i64* %82
%84 = call i8* @inet_ntoa(i64 %83)
store i8* %84, i8** %9
%85 = load i32, i32* %5
%86 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%87 = call i32 @connect(i32 %85, %struct.sockaddr* %86, i32 4)
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %90
89: ; preds = %63
br label %90
90: ; preds = %89, %63
%91 = load i32, i32* %5
ret i32 %91
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@__const.create_socket.portnum = [6 x i8] c"443\00\00\00"
@.str = [4 x i8] c"://\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @create_socket(i8* %0, i32* nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca [6 x i8]
%5 = alloca [6 x i8]
%6 = alloca %struct.sockaddr_in
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
br i1 %14, label %15, label %16
15: ; preds = %2
store i8 0, i8* %12
br label %16
16: ; preds = %15, %2
%17 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%18 = ptrtoint i8* %17 to i64
%19 = ptrtoint i8* %0 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = call i32 @strncpy(i8* %9, i8* %0, i32 %21)
%23 = call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%24 = getelementptr inbounds i8, i8* %23, i64 3
%25 = call i32 @strncpy(i8* %7, i8* %24, i32 256)
%26 = call i8* @strchr(i8* %7, i8 signext 58)
%27 = icmp eq i8* %26, null
br i1 %27, label %31, label %28
28: ; preds = %16
%29 = getelementptr inbounds i8, i8* %26, i64 1
%30 = call i32 @strncpy(i8* %8, i8* %29, i32 6)
store i8 0, i8* %26
br label %31
31: ; preds = %28, %16
%32 = call i32 @atoi(i8* %8)
%33 = call %struct.hostent* @gethostbyname(i8* %7)
%34 = icmp eq %struct.hostent* %33, null
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (...) @abort()
unreachable
37: ; preds = %31
%38 = load i32, i32* @AF_INET
%39 = load i32, i32* @SOCK_STREAM
%40 = call i32 @socket(i32 %38, i32 %39, i32 0)
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 3
store i32 %41, i32* %42
%43 = call i32 @htons(i32 %32)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %43, i32* %44
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %33, i64 0, i32 0
%46 = load i64, i64* %45
%47 = inttoptr i64 %46 to i64*
%48 = load i64, i64* %47
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0, i32 0
store i64 %48, i64* %49
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
%51 = call i32 @memset(i32* %50, i8 signext 0, i32 8)
%52 = load i64, i64* %49
%53 = call i8* @inet_ntoa(i64 %52)
%54 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%55 = call i32 @connect(i32 %40, %struct.sockaddr* %54, i32 4)
ret i32 %40
}