#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *strchr(char *, char);
char *strdup(char const *);
scalar_t__ strncmp(char const *, char *, int);
int /*<<< orphan*/ warn(char *);
int /*<<< orphan*/ warnx(char *, char const *);
char *url2host(const char *host, short *port, char **path) {
  char *url, *ep;
  if (strncmp(host, "https://", 8) == 0) {
    *port = 443;
    if ((url = strdup(host + 8)) == NULL) {
      warn("strdup");
      return (NULL);
    }
  } else if (strncmp(host, "http://", 7) == 0) {
    *port = 80;
    if ((url = strdup(host + 7)) == NULL) {
      warn("strdup");
      return (NULL);
    }
  } else {
    warnx("%s: unknown schema", host);
    return (NULL);
  }
  if ((ep = strchr(url, '/')) != NULL) {
    *path = strdup(ep);
    *ep = '\0';
  } else
    *path = strdup("");
  if (*path == NULL) {
    warn("strdup");
    free(url);
    return (NULL);
  }
  return (url);
}


x86 assembly (clang, -O0):
<url2host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    11d5 <url2host+0x75>
mov    -0x18(%rbp),%rax
movw   $0x1bb,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11d0 <url2host+0x70>
lea    0xe4b(%rip),%rdi
call   1050 <warn@plt>
movq   $0x0,-0x8(%rbp)
jmp    12e1 <url2host+0x181>
jmp    1258 <url2host+0xf8>
mov    -0x10(%rbp),%rdi
lea    0xe30(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1236 <url2host+0xd6>
mov    -0x18(%rbp),%rax
movw   $0x50,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x7,%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1231 <url2host+0xd1>
lea    0xdea(%rip),%rdi
call   1050 <warn@plt>
movq   $0x0,-0x8(%rbp)
jmp    12e1 <url2host+0x181>
jmp    1253 <url2host+0xf3>
mov    -0x10(%rbp),%rsi
lea    0xdd7(%rip),%rdi
call   1070 <warnx@plt>
movq   $0x0,-0x8(%rbp)
jmp    12e1 <url2host+0x181>
jmp    1258 <url2host+0xf8>
mov    -0x28(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1293 <url2host+0x133>
mov    -0x30(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
jmp    12a9 <url2host+0x149>
lea    0xd7d(%rip),%rdi
call   1080 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12d9 <url2host+0x179>
lea    0xd4b(%rip),%rdi
call   1050 <warn@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12e1 <url2host+0x181>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url2host>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe8b(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11b1 <url2host+0x51>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11bd <url2host+0x5d>
lea    0xe74(%rip),%rdi
mov    %rbx,%rsi
call   1070 <warnx@plt>
jmp    123b <url2host+0xdb>
movw   $0x1bb,(%r15)
add    $0x8,%rbx
jmp    11c7 <url2host+0x67>
movw   $0x50,(%r15)
add    $0x7,%rbx
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1205 <url2host+0xa5>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1213 <url2host+0xb3>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <strdup@plt>
mov    %rax,(%r14)
movb   $0x0,(%r15)
mov    (%r14),%rax
test   %rax,%rax
jne    123d <url2host+0xdd>
jmp    1227 <url2host+0xc7>
lea    0xdfd(%rip),%rdi
call   1050 <warn@plt>
jmp    123b <url2host+0xdb>
lea    0xdfd(%rip),%rdi
call   1080 <strdup@plt>
mov    %rax,(%r14)
test   %rax,%rax
jne    123d <url2host+0xdd>
lea    0xddb(%rip),%rdi
call   1050 <warn@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"https://\00"
@.str.1 = [7 x i8] c"strdup\00"
@.str.2 = [8 x i8] c"http://\00"
@.str.3 = [19 x i8] c"%s: unknown schema\00"
@.str.4 = [1 x i8] zeroinitializer
define i8* @url2host(i8* %0, i16* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i16*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i16* %1, i16** %6
store i8** %2, i8*** %7
%10 = load i8*, i8** %5
%11 = call i64 @strncmp(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %3
%14 = load i16*, i16** %6
store i16 443, i16* %14
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 8
%17 = call i8* @strdup(i8* %16)
store i8* %17, i8** %8
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %4
br label %61
21: ; preds = %13
br label %39
22: ; preds = %3
%23 = load i8*, i8** %5
%24 = call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = load i16*, i16** %6
store i16 80, i16* %27
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 7
%30 = call i8* @strdup(i8* %29)
store i8* %30, i8** %8
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %4
br label %61
34: ; preds = %26
br label %38
35: ; preds = %22
%36 = load i8*, i8** %5
%37 = call i32 @warnx(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %36)
store i8* null, i8** %4
br label %61
38: ; preds = %34
br label %39
39: ; preds = %38, %21
%40 = load i8*, i8** %8
%41 = call i8* @strchr(i8* %40, i8 signext 47)
store i8* %41, i8** %9
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i8*, i8** %9
%45 = call i8* @strdup(i8* %44)
%46 = load i8**, i8*** %7
store i8* %45, i8** %46
%47 = load i8*, i8** %9
store i8 0, i8* %47
br label %51
48: ; preds = %39
%49 = call i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%50 = load i8**, i8*** %7
store i8* %49, i8** %50
br label %51
51: ; preds = %48, %43
%52 = load i8**, i8*** %7
%53 = load i8*, i8** %52
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%57 = load i8*, i8** %8
%58 = call i32 @free(i8* %57)
store i8* null, i8** %4
br label %61
59: ; preds = %51
%60 = load i8*, i8** %8
store i8* %60, i8** %4
br label %61
61: ; preds = %59, %55, %35, %32, %19
%62 = load i8*, i8** %4
ret i8* %62
}

LLVM IR (-O2):
@.str = [9 x i8] c"https://\00"
@.str.1 = [7 x i8] c"strdup\00"
@.str.2 = [8 x i8] c"http://\00"
@.str.3 = [19 x i8] c"%s: unknown schema\00"
@.str.4 = [1 x i8] zeroinitializer
define i8* @url2host(i8* %0, i16* nocapture writeonly %1, i8** nocapture %2) {
%4 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %3
store i16 443, i16* %1
%7 = getelementptr inbounds i8, i8* %0, i64 8
%8 = tail call i8* @strdup(i8* %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %23
10: ; preds = %6
%11 = tail call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %38
12: ; preds = %3
%13 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %12
store i16 80, i16* %1
%16 = getelementptr inbounds i8, i8* %0, i64 7
%17 = tail call i8* @strdup(i8* %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = tail call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %38
21: ; preds = %12
%22 = tail call i32 @warnx(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %38
23: ; preds = %15, %6
%24 = phi i8* [ %8, %6 ], [ %17, %15 ]
%25 = tail call i8* @strchr(i8* dereferenceable(1) %24, i8 signext 47)
%26 = icmp eq i8* %25, null
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = tail call i8* @strdup(i8* %25)
store i8* %28, i8** %2
store i8 0, i8* %25
%29 = load i8*, i8** %2
br label %32
30: ; preds = %23
%31 = tail call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
store i8* %31, i8** %2
br label %32
32: ; preds = %30, %27
%33 = phi i8* [ %31, %30 ], [ %29, %27 ]
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = tail call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%37 = tail call i32 @free(i8* %24)
br label %38
38: ; preds = %32, %35, %21, %19, %10
%39 = phi i8* [ null, %10 ], [ null, %35 ], [ null, %19 ], [ null, %21 ], [ %24, %32 ]
ret i8* %39
}