#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 */
char *proto_default_port(char *);
char *strchr(char *, char);
char *strrchr(char *, char);
char *strstr(char const *, char *);
char *xstrdup(char const *);
int parseurl(const char *url, char **phost, char **pfile, char **pproto,
             char **pport) {
  if (((*phost) = strstr(url, "://"))) {
    *(*phost) = '\0';
    (*phost) = xstrdup((*phost) + 3);
    (*pproto) = xstrdup(url);
  } else {
    (*phost) = xstrdup(url);
    (*pproto) = xstrdup("http");
  }
  if (*(*phost) == '/') {
    (*pfile) = (*phost);
    (*phost) = NULL;
    (*pport) = NULL;
  } else {
    (*pfile) = strchr((*phost), '/');
    if ((*pfile)) {
      char *slash = (*pfile);
      (*pfile) = xstrdup((*pfile));
      *slash = '\0';
    } else {
      (*pfile) = xstrdup("/");
    }
    if (((*pport) = strrchr((*phost), ':')))
      *(*pport)++ = '\0';
    else
      (*pport) = proto_default_port((*pproto));
    (*pport) = xstrdup((*pport));
  }
  return 0;
}


x86 assembly (clang, -O0):
<parseurl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1070 <strstr@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
je     11c9 <parseurl+0x79>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
add    $0x3,%rdi
call   1060 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
call   1060 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    11f2 <parseurl+0xa2>
mov    -0x8(%rbp),%rdi
call   1060 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    0xe21(%rip),%rdi
call   1060 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    122e <parseurl+0xde>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
jmp    1301 <parseurl+0x1b1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1284 <parseurl+0x134>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1060 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
jmp    129a <parseurl+0x14a>
lea    0xd77(%rip),%rdi
call   1060 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x3a,%esi
call   1050 <strrchr@plt>
mov    -0x28(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
je     12d5 <parseurl+0x185>
mov    -0x28(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
movb   $0x0,(%rax)
jmp    12eb <parseurl+0x19b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <proto_default_port@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1060 <xstrdup@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseurl>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r15
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0xe91(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,0x0(%r13)
test   %rax,%rax
je     118f <parseurl+0x3f>
movb   $0x0,(%rax)
mov    0x0(%r13),%rdi
add    $0x3,%rdi
call   1060 <xstrdup@plt>
jmp    119e <parseurl+0x4e>
mov    %rbx,%rdi
call   1060 <xstrdup@plt>
lea    0xe66(%rip),%rbx
mov    %rax,0x0(%r13)
mov    %rbx,%rdi
call   1060 <xstrdup@plt>
mov    %rax,(%r14)
mov    0x0(%r13),%rdi
cmpb   $0x2f,(%rdi)
jne    11c6 <parseurl+0x76>
mov    %rdi,(%r12)
movq   $0x0,0x0(%r13)
xor    %eax,%eax
jmp    1238 <parseurl+0xe8>
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     11ed <parseurl+0x9d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <xstrdup@plt>
mov    %rax,(%r12)
movb   $0x0,(%rbx)
jmp    11fd <parseurl+0xad>
lea    0xe0e(%rip),%rdi
call   1060 <xstrdup@plt>
mov    %rax,(%r12)
mov    0x0(%r13),%rdi
mov    $0x3a,%esi
call   1050 <strrchr@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1225 <parseurl+0xd5>
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,(%r15)
movb   $0x0,(%rax)
mov    (%r15),%rdi
jmp    1233 <parseurl+0xe3>
mov    (%r14),%rdi
call   1030 <proto_default_port@plt>
mov    %rax,%rdi
mov    %rax,(%r15)
call   1060 <xstrdup@plt>
mov    %rax,(%r15)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"://\00"
@.str.1 = [5 x i8] c"http\00"
@.str.2 = [2 x i8] c"/\00"
define i32 @parseurl(i8* %0, i8** %1, i8** %2, i8** %3, i8** %4) {
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i8**
%11 = alloca i8*
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i8** %2, i8*** %8
store i8** %3, i8*** %9
store i8** %4, i8*** %10
%12 = load i8*, i8** %6
%13 = call i8* @strstr(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%14 = load i8**, i8*** %7
store i8* %13, i8** %14
%15 = icmp ne i8* %13, null
br i1 %15, label %16, label %27
16: ; preds = %5
%17 = load i8**, i8*** %7
%18 = load i8*, i8** %17
store i8 0, i8* %18
%19 = load i8**, i8*** %7
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 3
%22 = call i8* @xstrdup(i8* %21)
%23 = load i8**, i8*** %7
store i8* %22, i8** %23
%24 = load i8*, i8** %6
%25 = call i8* @xstrdup(i8* %24)
%26 = load i8**, i8*** %9
store i8* %25, i8** %26
br label %33
27: ; preds = %5
%28 = load i8*, i8** %6
%29 = call i8* @xstrdup(i8* %28)
%30 = load i8**, i8*** %7
store i8* %29, i8** %30
%31 = call i8* @xstrdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = load i8**, i8*** %9
store i8* %31, i8** %32
br label %33
33: ; preds = %27, %16
%34 = load i8**, i8*** %7
%35 = load i8*, i8** %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 47
br i1 %38, label %39, label %45
39: ; preds = %33
%40 = load i8**, i8*** %7
%41 = load i8*, i8** %40
%42 = load i8**, i8*** %8
store i8* %41, i8** %42
%43 = load i8**, i8*** %7
store i8* null, i8** %43
%44 = load i8**, i8*** %10
store i8* null, i8** %44
br label %84
45: ; preds = %33
%46 = load i8**, i8*** %7
%47 = load i8*, i8** %46
%48 = call i8* @strchr(i8* %47, i8 signext 47)
%49 = load i8**, i8*** %8
store i8* %48, i8** %49
%50 = load i8**, i8*** %8
%51 = load i8*, i8** %50
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %61
53: ; preds = %45
%54 = load i8**, i8*** %8
%55 = load i8*, i8** %54
store i8* %55, i8** %11
%56 = load i8**, i8*** %8
%57 = load i8*, i8** %56
%58 = call i8* @xstrdup(i8* %57)
%59 = load i8**, i8*** %8
store i8* %58, i8** %59
%60 = load i8*, i8** %11
store i8 0, i8* %60
br label %64
61: ; preds = %45
%62 = call i8* @xstrdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%63 = load i8**, i8*** %8
store i8* %62, i8** %63
br label %64
64: ; preds = %61, %53
%65 = load i8**, i8*** %7
%66 = load i8*, i8** %65
%67 = call i8* @strrchr(i8* %66, i8 signext 58)
%68 = load i8**, i8*** %10
store i8* %67, i8** %68
%69 = icmp ne i8* %67, null
br i1 %69, label %70, label %74
70: ; preds = %64
%71 = load i8**, i8*** %10
%72 = load i8*, i8** %71
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %71
store i8 0, i8* %72
br label %79
74: ; preds = %64
%75 = load i8**, i8*** %9
%76 = load i8*, i8** %75
%77 = call i8* @proto_default_port(i8* %76)
%78 = load i8**, i8*** %10
store i8* %77, i8** %78
br label %79
79: ; preds = %74, %70
%80 = load i8**, i8*** %10
%81 = load i8*, i8** %80
%82 = call i8* @xstrdup(i8* %81)
%83 = load i8**, i8*** %10
store i8* %82, i8** %83
br label %84
84: ; preds = %79, %39
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"://\00"
@.str.1 = [5 x i8] c"http\00"
@.str.2 = [2 x i8] c"/\00"
define i32 @parseurl(i8* %0, i8** nocapture %1, i8** nocapture writeonly %2, i8** nocapture %3, i8** nocapture %4) {
%6 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %1
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
store i8 0, i8* %6
%9 = load i8*, i8** %1
%10 = getelementptr inbounds i8, i8* %9, i64 3
%11 = tail call i8* @xstrdup(i8* %10)
br label %14
12: ; preds = %5
%13 = tail call i8* @xstrdup(i8* %0)
br label %14
14: ; preds = %12, %8
%15 = phi i8* [ %13, %12 ], [ %11, %8 ]
%16 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %12 ], [ %0, %8 ]
store i8* %15, i8** %1
%17 = tail call i8* @xstrdup(i8* %16)
store i8* %17, i8** %3
%18 = load i8*, i8** %1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 47
br i1 %20, label %21, label %22
21: ; preds = %14
store i8* %18, i8** %2
store i8* null, i8** %1
br label %42
22: ; preds = %14
%23 = tail call i8* @strchr(i8* %18, i8 signext 47)
store i8* %23, i8** %2
%24 = icmp eq i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i8* @xstrdup(i8* %23)
store i8* %26, i8** %2
store i8 0, i8* %23
br label %29
27: ; preds = %22
%28 = tail call i8* @xstrdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %28, i8** %2
br label %29
29: ; preds = %27, %25
%30 = load i8*, i8** %1
%31 = tail call i8* @strrchr(i8* dereferenceable(1) %30, i8 signext 58)
store i8* %31, i8** %4
%32 = icmp eq i8* %31, null
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %34, i8** %4
store i8 0, i8* %31
%35 = load i8*, i8** %4
br label %39
36: ; preds = %29
%37 = load i8*, i8** %3
%38 = tail call i8* @proto_default_port(i8* %37)
store i8* %38, i8** %4
br label %39
39: ; preds = %36, %33
%40 = phi i8* [ %38, %36 ], [ %35, %33 ]
%41 = tail call i8* @xstrdup(i8* %40)
br label %42
42: ; preds = %39, %21
%43 = phi i8* [ %41, %39 ], [ null, %21 ]
store i8* %43, i8** %4
ret i32 0
}