#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 atoi(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *strrchr(char *, char);
void parse_url(char *input, char *host, int *port, char *pathname,
               char *outfile) {
  char *p;
  p = strrchr(input, '/') + 1;
  strcpy(outfile, p);
  *port = 80;
  if (!strncmp(input, "http://", 7))
    input += 7;
  else if (!strncmp(input, "http:", 5))
    input += 5;
  p = strchr(input, '/');
  if (p) {
    strcpy(pathname, p);
    *p = 0;
  } else {
    strcpy(pathname, "/");
  }
  p = strchr(input, ':');
  if (p) {
    *p = 0;
    p++;
    *port = atoi(p);
  }
  strcpy(host, input);
}


x86 assembly (clang, -O0):
<parse_url>:
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
mov    $0x2f,%esi
call   1060 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
movl   $0x50,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11c8 <parse_url+0x78>
mov    -0x8(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x8(%rbp)
jmp    11f7 <parse_url+0xa7>
mov    -0x8(%rbp),%rdi
lea    0xe35(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11f2 <parse_url+0xa2>
mov    -0x8(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x8(%rbp)
jmp    11f7 <parse_url+0xa7>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     122d <parse_url+0xdd>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
jmp    123d <parse_url+0xed>
mov    -0x20(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     127e <parse_url+0x12e>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_url>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%rbx
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r13
mov    $0x2f,%esi
call   1060 <strrchr@plt>
lea    0x1(%rax),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
movl   $0x50,(%r15)
lea    0xe74(%rip),%rsi
mov    %r13,%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11be <parse_url+0x6e>
lea    0xe64(%rip),%rsi
mov    %r13,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,4),%rax
jmp    11c3 <parse_url+0x73>
mov    $0x7,%eax
add    %rax,%r13
mov    %r13,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11eb <parse_url+0x9b>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
movb   $0x0,(%rbx)
jmp    11fa <parse_url+0xaa>
lea    0xe14(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcpy@plt>
mov    %r13,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     121e <parse_url+0xce>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,(%r15)
mov    %r14,%rdi
mov    %r13,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <strcpy@plt>

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

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@.str.1 = [6 x i8] c"http:\00"
@.str.2 = [2 x i8] c"/\00"
define void @parse_url(i8* %0, i8* %1, i32* nocapture writeonly %2, i8* %3, i8* %4) {
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = tail call i32 @strcpy(i8* %4, i8* %7)
store i32 80, i32* %2
%9 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %5
%12 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i64 5, i64 0
br label %15
15: ; preds = %5, %11
%16 = phi i64 [ %14, %11 ], [ 7, %5 ]
%17 = getelementptr i8, i8* %0, i64 %16
%18 = tail call i8* @strchr(i8* dereferenceable(1) %17, i8 signext 47)
%19 = icmp eq i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = tail call i32 @strcpy(i8* %3, i8* %18)
store i8 0, i8* %18
br label %24
22: ; preds = %15
%23 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
%25 = tail call i8* @strchr(i8* dereferenceable(1) %17, i8 signext 58)
%26 = icmp eq i8* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
store i8 0, i8* %25
%28 = getelementptr inbounds i8, i8* %25, i64 1
%29 = tail call i32 @atoi(i8* %28)
store i32 %29, i32* %2
br label %30
30: ; preds = %27, %24
%31 = tail call i32 @strcpy(i8* %1, i8* %17)
ret void
}