#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 sscanf(char const *, char *, ...);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int Parse_Url(const char *url, char *host, char *resource, short int *port) {
  char *loc_of_semicolon;
  char *loc_of_slash;
  char *end_of_host_loc;
  char *loc_of_resource;
  char *loc_of_port;
  char url_wo_http[512];
  if (sscanf(url, "http://%255s", url_wo_http) != 1) {
    if (sscanf(url, "%255s", url_wo_http) != 1) {
      return -894;
    }
  }
  loc_of_semicolon = strchr(url_wo_http, ':');
  loc_of_slash = strchr(url_wo_http, '/');
  if (NULL == loc_of_slash) {
    return -894;
  } else {
    loc_of_resource = loc_of_slash + 1;
  }
  if (NULL == loc_of_semicolon || loc_of_semicolon > loc_of_slash) {
    loc_of_semicolon = NULL;
    if (NULL != port) {
      *port = 80;
    }
    end_of_host_loc = loc_of_slash;
  } else {
    loc_of_port = loc_of_semicolon + 1;
    if ((loc_of_slash - loc_of_port) > 5) {
      return -894;
    }
    end_of_host_loc = loc_of_semicolon;
  }
  if (NULL != host) {
    strncpy(host, url_wo_http, end_of_host_loc - url_wo_http);
    host[end_of_host_loc - url_wo_http] = '\0';
  }
  if (NULL != loc_of_semicolon) {
    if (sscanf(loc_of_port, "%hd", port) != 1) {
      *port = 80;
    }
    if (*port < 0 || *port > 16383) {
      return -894;
    }
  }
  if (NULL != resource) {
    strcpy(resource, loc_of_resource);
  }
  return 0;
}


x86 assembly (clang, -O0):
<Parse_Url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x250(%rbp),%rdx
lea    0xe93(%rip),%rsi
mov    $0x0,%al
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11b0 <Parse_Url+0x70>
mov    -0x10(%rbp),%rdi
lea    -0x250(%rbp),%rdx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11ab <Parse_Url+0x6b>
movl   $0xfffffc82,-0x4(%rbp)
jmp    1340 <Parse_Url+0x200>
jmp    11b0 <Parse_Url+0x70>
lea    -0x250(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
lea    -0x250(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    11f2 <Parse_Url+0xb2>
movl   $0xfffffc82,-0x4(%rbp)
jmp    1340 <Parse_Url+0x200>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
je     1218 <Parse_Url+0xd8>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jbe    1242 <Parse_Url+0x102>
movq   $0x0,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
je     1235 <Parse_Url+0xf5>
mov    -0x28(%rbp),%rax
movw   $0x50,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1277 <Parse_Url+0x137>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x50(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x5,%rax
jle    126f <Parse_Url+0x12f>
movl   $0xfffffc82,-0x4(%rbp)
jmp    1340 <Parse_Url+0x200>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     12b9 <Parse_Url+0x179>
mov    -0x18(%rbp),%rdi
lea    -0x250(%rbp),%rsi
mov    -0x40(%rbp),%rax
lea    -0x250(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
lea    -0x250(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
je     1320 <Parse_Url+0x1e0>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd39(%rip),%rsi
mov    $0x0,%al
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     12ed <Parse_Url+0x1ad>
mov    -0x28(%rbp),%rax
movw   $0x50,(%rax)
mov    -0x28(%rbp),%rax
movswl (%rax),%eax
cmp    $0x0,%eax
jl     130f <Parse_Url+0x1cf>
mov    -0x28(%rbp),%rax
movswl (%rax),%eax
cmp    $0x3fff,%eax
jle    131b <Parse_Url+0x1db>
movl   $0xfffffc82,-0x4(%rbp)
jmp    1340 <Parse_Url+0x200>
jmp    1320 <Parse_Url+0x1e0>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
je     1339 <Parse_Url+0x1f9>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Parse_Url>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe9c(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     119a <Parse_Url+0x5a>
lea    0xe8b(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    $0xfffffc82,%r13d
cmp    $0x1,%eax
jne    128a <Parse_Url+0x14a>
mov    %r14,(%rsp)
mov    %rbp,0x8(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    $0xfffffc82,%r13d
test   %rax,%rax
je     128a <Parse_Url+0x14a>
mov    %rax,%r12
test   %r14,%r14
je     124c <Parse_Url+0x10c>
cmp    %r12,%r14
ja     124c <Parse_Url+0x10c>
mov    %rbx,%rsi
mov    %r15,%rbp
mov    %r14,%r15
add    $0x1,%r15
mov    %r12,%rax
sub    %r15,%rax
mov    %r14,%rbx
cmp    $0x5,%rax
jg     128a <Parse_Url+0x14a>
test   %rbp,%rbp
je     1218 <Parse_Url+0xd8>
sub    %rsi,%rbx
mov    %rbp,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x0(%rbp,%rbx,1)
test   %r14,%r14
mov    0x8(%rsp),%rbx
mov    (%rsp),%rbp
je     1273 <Parse_Url+0x133>
lea    0xde0(%rip),%rsi
mov    %r15,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    126d <Parse_Url+0x12d>
movzwl 0x0(%rbp),%eax
cmp    $0x3fff,%eax
jbe    1273 <Parse_Url+0x133>
jmp    128a <Parse_Url+0x14a>
mov    %rbx,%rsi
mov    %r15,%rbp
mov    (%rsp),%rax
test   %rax,%rax
je     1260 <Parse_Url+0x120>
movw   $0x50,(%rax)
xor    %r14d,%r14d
mov    %r12,%rbx
test   %rbp,%rbp
jne    1206 <Parse_Url+0xc6>
jmp    1218 <Parse_Url+0xd8>
movw   $0x50,0x0(%rbp)
xor    %r13d,%r13d
test   %rbx,%rbx
je     128a <Parse_Url+0x14a>
add    $0x1,%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r13d,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"http://%255s\00"
@.str.1 = [6 x i8] c"%255s\00"
@.str.2 = [4 x i8] c"%hd\00"
define i32 @Parse_Url(i8* nocapture %0, i8* %1, i8* %2, i16* %3) {
%5 = alloca [512 x i8]
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%7 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = icmp eq i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %55
12: ; preds = %9, %4
%13 = call i8* @strchr(i8* %6, i8 signext 58)
%14 = call i8* @strchr(i8* %6, i8 signext 47)
%15 = icmp eq i8* %14, null
br i1 %15, label %55, label %16
16: ; preds = %12
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = icmp eq i8* %13, null
%19 = icmp ugt i8* %13, %14
%20 = select i1 %18, i1 true, i1 %19
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = icmp eq i16* %3, null
br i1 %22, label %30, label %23
23: ; preds = %21
store i16 80, i16* %3
br label %30
24: ; preds = %16
%25 = getelementptr inbounds i8, i8* %13, i64 1
%26 = ptrtoint i8* %14 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = icmp sgt i64 %28, 5
br i1 %29, label %55, label %30
30: ; preds = %24, %21, %23
%31 = phi i8* [ null, %23 ], [ null, %21 ], [ %13, %24 ]
%32 = phi i8* [ %14, %23 ], [ %14, %21 ], [ %13, %24 ]
%33 = phi i8* [ undef, %23 ], [ undef, %21 ], [ %25, %24 ]
%34 = icmp eq i8* %1, null
br i1 %34, label %42, label %35
35: ; preds = %30
%36 = ptrtoint i8* %32 to i64
%37 = ptrtoint [512 x i8]* %5 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
%40 = call i32 @strncpy(i8* %1, i8* %6, i32 %39)
%41 = getelementptr inbounds i8, i8* %1, i64 %38
store i8 0, i8* %41
br label %42
42: ; preds = %35, %30
%43 = icmp eq i8* %31, null
br i1 %43, label %51, label %44
44: ; preds = %42
%45 = call i32 (i8*, i8*, ...) @sscanf(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i16* %3)
%46 = icmp eq i32 %45, 1
br i1 %46, label %48, label %47
47: ; preds = %44
store i16 80, i16* %3
br label %51
48: ; preds = %44
%49 = load i16, i16* %3
%50 = icmp ugt i16 %49, 16383
br i1 %50, label %55, label %51
51: ; preds = %47, %48, %42
%52 = icmp eq i8* %2, null
br i1 %52, label %55, label %53
53: ; preds = %51
%54 = call i32 @strcpy(i8* %2, i8* %17)
br label %55
55: ; preds = %51, %53, %48, %24, %12, %9
%56 = phi i32 [ -894, %9 ], [ -894, %12 ], [ -894, %24 ], [ -894, %48 ], [ 0, %53 ], [ 0, %51 ]
ret i32 %56
}