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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char *, char);
size_t strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
void gethost(char *src, char *addr, int *port, char *file) {
  char *p1 = NULL;
  char *p2 = NULL;
  memset(addr, 0, sizeof(addr));
  memset(file, 0, sizeof(file));
  *port = 0;
  if (!(*src))
    return;
  p1 = src;
  if (!strncmp(p1, "http://", sizeof("http://") - 1))
    p1 = src + sizeof("http://") - 1;
  else if (!strncmp(p1, "https://", sizeof("https://") - 1))
    p1 = src + sizeof("https://") - 1;
  p2 = strchr(p1, '/');
  if (!p2) {
    memcpy(addr, p1, strlen(p1));
  } else {
    memcpy(addr, p1, strlen(p1) - strlen(p2));
    if (p2 + 1) {
      memcpy(file, p2 + 1, strlen(p2) - 1);
      file[strlen(p2) - 1] = 0;
    }
  }
  if (p2)
    addr[strlen(p1) - strlen(p2)] = 0;
  else
    addr[strlen(p1)] = 0;
  p2 = strchr(addr, ':');
  if (!p2) {
    *port = 80;
  } else {
    *port = atoi(p2 + 1);
    addr[strlen(p1) - strlen(p2)] = '\0';
  }
}


x86 assembly (clang, -O0):
<gethost>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11c7 <gethost+0x67>
jmp    1404 <gethost+0x2a4>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe26(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1202 <gethost+0xa2>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    1235 <gethost+0xd5>
mov    -0x28(%rbp),%rdi
lea    0xdfb(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1230 <gethost+0xd0>
mov    -0x8(%rbp),%rax
add    $0x9,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    1235 <gethost+0xd5>
mov    -0x28(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    127f <gethost+0x11f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
jmp    1325 <gethost+0x1c5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
sub    %rcx,%rax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
cmp    $0x0,%rax
je     1320 <gethost+0x1c0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
sub    $0x1,%rax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1325 <gethost+0x1c5>
cmpq   $0x0,-0x30(%rbp)
je     1365 <gethost+0x205>
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x80(%rbp),%rcx
mov    %rax,%rdx
mov    -0x78(%rbp),%rax
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1387 <gethost+0x227>
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    13b3 <gethost+0x253>
mov    -0x18(%rbp),%rax
movl   $0x50,(%rax)
jmp    1404 <gethost+0x2a4>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x98(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x98(%rbp),%rcx
mov    %rax,%rdx
mov    -0x90(%rbp),%rax
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethost>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
movl   $0x0,(%r14)
cmpb   $0x0,0x0(%r13)
je     12c7 <gethost+0x167>
lea    0xe52(%rip),%rsi
mov    %r13,%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11e0 <gethost+0x80>
lea    0xe42(%rip),%rsi
mov    %r13,%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
shl    $0x3,%rcx
jmp    11e5 <gethost+0x85>
mov    $0x7,%ecx
add    %rcx,%r13
mov    %r13,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
test   %rbx,%rbx
je     1262 <gethost+0x102>
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
mov    %rbx,%rbp
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    -0x1(%rax),%edx
mov    %r12,%rdi
mov    %rbp,%rsi
call   1070 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movb   $0x0,-0x1(%rax,%r12,1)
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %rax,%rbp
jmp    127a <gethost+0x11a>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
movb   $0x0,(%r15,%rbp,1)
mov    %r15,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     12c0 <gethost+0x160>
mov    %rax,%rbx
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <atoi@plt>
mov    %eax,(%r14)
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %rax,%rbp
movb   $0x0,(%r15,%rbp,1)
jmp    12c7 <gethost+0x167>
movl   $0x50,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
@.str.1 = [9 x i8] c"https://\00"
define void @gethost(i8* %0, i8* %1, i32* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i8* %3, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
%11 = load i8*, i8** %6
%12 = call i32 @memset(i8* %11, i32 0, i32 8)
%13 = load i8*, i8** %8
%14 = call i32 @memset(i8* %13, i32 0, i32 8)
%15 = load i32*, i32** %7
store i32 0, i32* %15
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %4
br label %113
20: ; preds = %4
%21 = load i8*, i8** %5
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = call i32 @strncmp(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%24 = icmp ne i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 8
%28 = getelementptr inbounds i8, i8* %27, i64 -1
store i8* %28, i8** %9
br label %38
29: ; preds = %20
%30 = load i8*, i8** %9
%31 = call i32 @strncmp(i8* %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%32 = icmp ne i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 9
%36 = getelementptr inbounds i8, i8* %35, i64 -1
store i8* %36, i8** %9
br label %37
37: ; preds = %33, %29
br label %38
38: ; preds = %37, %25
%39 = load i8*, i8** %9
%40 = call i8* @strchr(i8* %39, i8 signext 47)
store i8* %40, i8** %10
%41 = load i8*, i8** %10
%42 = icmp ne i8* %41, null
br i1 %42, label %50, label %43
43: ; preds = %38
%44 = load i8*, i8** %6
%45 = load i8*, i8** %9
%46 = load i8*, i8** %9
%47 = call i64 @strlen(i8* %46)
%48 = trunc i64 %47 to i32
%49 = call i32 @memcpy(i8* %44, i8* %45, i32 %48)
br label %78
50: ; preds = %38
%51 = load i8*, i8** %6
%52 = load i8*, i8** %9
%53 = load i8*, i8** %9
%54 = call i64 @strlen(i8* %53)
%55 = load i8*, i8** %10
%56 = call i64 @strlen(i8* %55)
%57 = sub i64 %54, %56
%58 = trunc i64 %57 to i32
%59 = call i32 @memcpy(i8* %51, i8* %52, i32 %58)
%60 = load i8*, i8** %10
%61 = getelementptr inbounds i8, i8* %60, i64 1
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %77
63: ; preds = %50
%64 = load i8*, i8** %8
%65 = load i8*, i8** %10
%66 = getelementptr inbounds i8, i8* %65, i64 1
%67 = load i8*, i8** %10
%68 = call i64 @strlen(i8* %67)
%69 = sub i64 %68, 1
%70 = trunc i64 %69 to i32
%71 = call i32 @memcpy(i8* %64, i8* %66, i32 %70)
%72 = load i8*, i8** %8
%73 = load i8*, i8** %10
%74 = call i64 @strlen(i8* %73)
%75 = sub i64 %74, 1
%76 = getelementptr inbounds i8, i8* %72, i64 %75
store i8 0, i8* %76
br label %77
77: ; preds = %63, %50
br label %78
78: ; preds = %77, %43
%79 = load i8*, i8** %10
%80 = icmp ne i8* %79, null
br i1 %80, label %81, label %89
81: ; preds = %78
%82 = load i8*, i8** %6
%83 = load i8*, i8** %9
%84 = call i64 @strlen(i8* %83)
%85 = load i8*, i8** %10
%86 = call i64 @strlen(i8* %85)
%87 = sub i64 %84, %86
%88 = getelementptr inbounds i8, i8* %82, i64 %87
store i8 0, i8* %88
br label %94
89: ; preds = %78
%90 = load i8*, i8** %6
%91 = load i8*, i8** %9
%92 = call i64 @strlen(i8* %91)
%93 = getelementptr inbounds i8, i8* %90, i64 %92
store i8 0, i8* %93
br label %94
94: ; preds = %89, %81
%95 = load i8*, i8** %6
%96 = call i8* @strchr(i8* %95, i8 signext 58)
store i8* %96, i8** %10
%97 = load i8*, i8** %10
%98 = icmp ne i8* %97, null
br i1 %98, label %101, label %99
99: ; preds = %94
%100 = load i32*, i32** %7
store i32 80, i32* %100
br label %113
101: ; preds = %94
%102 = load i8*, i8** %10
%103 = getelementptr inbounds i8, i8* %102, i64 1
%104 = call i32 @atoi(i8* %103)
%105 = load i32*, i32** %7
store i32 %104, i32* %105
%106 = load i8*, i8** %6
%107 = load i8*, i8** %9
%108 = call i64 @strlen(i8* %107)
%109 = load i8*, i8** %10
%110 = call i64 @strlen(i8* %109)
%111 = sub i64 %108, %110
%112 = getelementptr inbounds i8, i8* %106, i64 %111
store i8 0, i8* %112
br label %113
113: ; preds = %19, %101, %99
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@.str.1 = [9 x i8] c"https://\00"
define void @gethost(i8* %0, i8* %1, i32* nocapture writeonly %2, i8* %3) {
%5 = tail call i32 @memset(i8* %1, i32 0, i32 8)
%6 = tail call i32 @memset(i8* %3, i32 0, i32 8)
store i32 0, i32* %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %55, label %9
9: ; preds = %4
%10 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i64 8, i64 0
br label %16
16: ; preds = %9, %12
%17 = phi i64 [ %15, %12 ], [ 7, %9 ]
%18 = getelementptr i8, i8* %0, i64 %17
%19 = tail call i8* @strchr(i8* %18, i8 signext 47)
%20 = icmp eq i8* %19, null
%21 = tail call i64 @strlen(i8* %18)
br i1 %20, label %38, label %22
22: ; preds = %16
%23 = tail call i64 @strlen(i8* %19)
%24 = sub i64 %21, %23
%25 = trunc i64 %24 to i32
%26 = tail call i32 @memcpy(i8* %1, i8* %18, i32 %25)
%27 = getelementptr inbounds i8, i8* %19, i64 1
%28 = tail call i64 @strlen(i8* %19)
%29 = trunc i64 %28 to i32
%30 = add i32 %29, -1
%31 = tail call i32 @memcpy(i8* %3, i8* %27, i32 %30)
%32 = tail call i64 @strlen(i8* %19)
%33 = add i64 %32, -1
%34 = getelementptr inbounds i8, i8* %3, i64 %33
store i8 0, i8* %34
%35 = tail call i64 @strlen(i8* %18)
%36 = tail call i64 @strlen(i8* %19)
%37 = sub i64 %35, %36
br label %42
38: ; preds = %16
%39 = trunc i64 %21 to i32
%40 = tail call i32 @memcpy(i8* %1, i8* %18, i32 %39)
%41 = tail call i64 @strlen(i8* %18)
br label %42
42: ; preds = %38, %22
%43 = phi i64 [ %41, %38 ], [ %37, %22 ]
%44 = getelementptr inbounds i8, i8* %1, i64 %43
store i8 0, i8* %44
%45 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 58)
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %48
47: ; preds = %42
store i32 80, i32* %2
br label %55
48: ; preds = %42
%49 = getelementptr inbounds i8, i8* %45, i64 1
%50 = tail call i32 @atoi(i8* %49)
store i32 %50, i32* %2
%51 = tail call i64 @strlen(i8* %18)
%52 = tail call i64 @strlen(i8* %45)
%53 = sub i64 %51, %52
%54 = getelementptr inbounds i8, i8* %1, i64 %53
store i8 0, i8* %54
br label %55
55: ; preds = %47, %48, %4
ret void
}