#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
scalar_t__ malloc(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ resolveipv4(char *);
char *strcasestr(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strtok(char *, char *);
uint32_t resolveIPfromURL(char *url) {
  char *hostptr;
  char *tptr;
  char *prefix = "http://";
  char *prefixs = "https://";
  uint32_t resolved;
  tptr = (char *)malloc(strlen(url));
  if (tptr == NULL) {
    perror("can't allocate memory");
    exit(1);
  }
  memset(tptr, 0x00, strlen(url));
  memcpy(tptr, url, strlen(url));
  hostptr = strcasestr(tptr, prefix);
  if (hostptr != NULL) {
    hostptr += strlen(prefix);
  } else {
    hostptr = (char *)strcasestr(tptr, prefixs);
    if (hostptr != NULL) {
      hostptr += strlen(prefixs);
    }
  }
  strtok(hostptr, " :/");
  resolved = htonl(resolveipv4(hostptr));
  free(tptr);
  return (resolved);
}


x86 assembly (clang, -O0):
<resolveIPfromURL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe3d(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe3a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1207 <resolveIPfromURL+0x57>
lea    0xe19(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <strcasestr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1287 <resolveIPfromURL+0xd7>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    12c1 <resolveIPfromURL+0x111>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10b0 <strcasestr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12bc <resolveIPfromURL+0x10c>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    12c1 <resolveIPfromURL+0x111>
mov    -0x10(%rbp),%rdi
lea    0xd5b(%rip),%rsi
call   10a0 <strtok@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <resolveipv4@plt>
mov    %eax,%edi
call   1050 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolveIPfromURL>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1278 <resolveIPfromURL+0xc8>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
lea    0xdfd(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   10b0 <strcasestr@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1230 <resolveIPfromURL+0x80>
lea    0xdeb(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   10b0 <strcasestr@plt>
mov    %rax,%r12
test   %rax,%rax
je     1274 <resolveIPfromURL+0xc4>
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbx
add    %r12,%rbx
lea    0xde2(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strtok@plt>
mov    %rbx,%rdi
call   10c0 <resolveipv4@plt>
mov    %eax,%edi
call   1050 <htonl@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
jmp    123e <resolveIPfromURL+0x8e>
lea    0xd92(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
@.str.1 = [9 x i8] c"https://\00"
@.str.2 = [22 x i8] c"can't allocate memory\00"
@.str.3 = [4 x i8] c" :/\00"
define i32 @resolveIPfromURL(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %6
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
%18 = load i8*, i8** %4
%19 = load i8*, i8** %2
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @memset(i8* %18, i32 0, i32 %20)
%22 = load i8*, i8** %4
%23 = load i8*, i8** %2
%24 = load i8*, i8** %2
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @memcpy(i8* %22, i8* %23, i32 %25)
%27 = load i8*, i8** %4
%28 = load i8*, i8** %5
%29 = call i8* @strcasestr(i8* %27, i8* %28)
store i8* %29, i8** %3
%30 = load i8*, i8** %3
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %38
32: ; preds = %17
%33 = load i8*, i8** %5
%34 = call i32 @strlen(i8* %33)
%35 = load i8*, i8** %3
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8* %37, i8** %3
br label %51
38: ; preds = %17
%39 = load i8*, i8** %4
%40 = load i8*, i8** %6
%41 = call i8* @strcasestr(i8* %39, i8* %40)
store i8* %41, i8** %3
%42 = load i8*, i8** %3
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %50
44: ; preds = %38
%45 = load i8*, i8** %6
%46 = call i32 @strlen(i8* %45)
%47 = load i8*, i8** %3
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8* %49, i8** %3
br label %50
50: ; preds = %44, %38
br label %51
51: ; preds = %50, %32
%52 = load i8*, i8** %3
%53 = call i32 @strtok(i8* %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%54 = load i8*, i8** %3
%55 = call i32 @resolveipv4(i8* %54)
%56 = call i32 @htonl(i32 %55)
store i32 %56, i32* %7
%57 = load i8*, i8** %4
%58 = call i32 @free(i8* %57)
%59 = load i32, i32* %7
ret i32 %59
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@.str.1 = [9 x i8] c"https://\00"
@.str.2 = [22 x i8] c"can't allocate memory\00"
@.str.3 = [4 x i8] c" :/\00"
define i32 @resolveIPfromURL(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = tail call i32 @strlen(i8* %0)
%11 = tail call i32 @memset(i8* %4, i32 0, i32 %10)
%12 = tail call i32 @strlen(i8* %0)
%13 = tail call i32 @memcpy(i8* %4, i8* %0, i32 %12)
%14 = tail call i8* @strcasestr(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = tail call i8* @strcasestr(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %25, label %19
19: ; preds = %16, %9
%20 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %16 ]
%21 = phi i8* [ %14, %9 ], [ %17, %16 ]
%22 = tail call i32 @strlen(i8* %20)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
br label %25
25: ; preds = %19, %16
%26 = phi i8* [ null, %16 ], [ %24, %19 ]
%27 = tail call i32 @strtok(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%28 = tail call i32 @resolveipv4(i8* %26)
%29 = tail call i32 @htonl(i32 %28)
%30 = tail call i32 @free(i8* %4)
ret i32 %29
}