#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 const *);
char *strchr(char const *, char);
char *strndup(char const *, size_t);
int simplehttp_parse_url(const char *endpoint, size_t endpoint_len,
                         char **address, int *port, char **path) {
  const char *address_p, *path_p, *tmp_pointer, *tmp_port;
  size_t address_len;
  size_t path_len;
  if (endpoint_len < 9) {
    return 0;
  }
  address_p = strchr(endpoint, '/');
  if (!address_p) {
    return 0;
  }
  address_p += 2;
  tmp_pointer = strchr(address_p, ':');
  path_p = strchr(address_p, '/');
  if (!path_p) {
    return 0;
  }
  if (tmp_pointer) {
    address_len = tmp_pointer - address_p;
    tmp_port = address_p + address_len + 1;
    *port = atoi(tmp_port);
  } else {
    address_len = path_p - address_p;
    *port = 80;
  }
  path_len = (endpoint + endpoint_len) - path_p;
  *address = strndup(address_p, address_len);
  *path = strndup(path_p, path_len);
  return 1;
}


x86 assembly (clang, -O0):
<simplehttp_parse_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
cmpq   $0x9,-0x18(%rbp)
jae    1163 <simplehttp_parse_url+0x33>
movl   $0x0,-0x4(%rbp)
jmp    1274 <simplehttp_parse_url+0x144>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    118c <simplehttp_parse_url+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    1274 <simplehttp_parse_url+0x144>
mov    -0x38(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11d3 <simplehttp_parse_url+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    1274 <simplehttp_parse_url+0x144>
cmpq   $0x0,-0x48(%rbp)
je     1213 <simplehttp_parse_url+0xe3>
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rax
add    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    122c <simplehttp_parse_url+0xfc>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x50,(%rax)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1040 <strndup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rdi
mov    -0x60(%rbp),%rsi
call   1040 <strndup@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simplehttp_parse_url>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %r15d,%r15d
cmp    $0x9,%rsi
jb     1200 <simplehttp_parse_url+0xd0>
mov    %r8,%r13
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rcx,0x10(%rsp)
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1200 <simplehttp_parse_url+0xd0>
mov    %rax,%rbp
mov    %rbx,(%rsp)
mov    %r13,0x8(%rsp)
add    $0x2,%rbp
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1200 <simplehttp_parse_url+0xd0>
mov    %rax,%rbx
test   %r13,%r13
je     11bd <simplehttp_parse_url+0x8d>
mov    %r13,%r15
sub    %rbp,%r15
add    $0x1,%r13
mov    %r13,%rdi
call   1050 <atoi@plt>
jmp    11c8 <simplehttp_parse_url+0x98>
mov    %rbx,%r15
sub    %rbp,%r15
mov    $0x50,%eax
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx)
add    %r12,%r14
sub    %rbx,%r14
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <strndup@plt>
mov    (%rsp),%rcx
mov    %rax,(%rcx)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strndup@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @simplehttp_parse_url(i8* %0, i64 %1, i8** %2, i32* %3, i8** %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i8**
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
store i8* %0, i8** %7
store i64 %1, i64* %8
store i8** %2, i8*** %9
store i32* %3, i32** %10
store i8** %4, i8*** %11
%18 = load i64, i64* %8
%19 = icmp ult i64 %18, 9
br i1 %19, label %20, label %21
20: ; preds = %5
store i32 0, i32* %6
br label %76
21: ; preds = %5
%22 = load i8*, i8** %7
%23 = call i8* @strchr(i8* %22, i8 signext 47)
store i8* %23, i8** %12
%24 = load i8*, i8** %12
%25 = icmp ne i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %21
store i32 0, i32* %6
br label %76
27: ; preds = %21
%28 = load i8*, i8** %12
%29 = getelementptr inbounds i8, i8* %28, i64 2
store i8* %29, i8** %12
%30 = load i8*, i8** %12
%31 = call i8* @strchr(i8* %30, i8 signext 58)
store i8* %31, i8** %14
%32 = load i8*, i8** %12
%33 = call i8* @strchr(i8* %32, i8 signext 47)
store i8* %33, i8** %13
%34 = load i8*, i8** %13
%35 = icmp ne i8* %34, null
br i1 %35, label %37, label %36
36: ; preds = %27
store i32 0, i32* %6
br label %76
37: ; preds = %27
%38 = load i8*, i8** %14
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %53
40: ; preds = %37
%41 = load i8*, i8** %14
%42 = load i8*, i8** %12
%43 = ptrtoint i8* %41 to i64
%44 = ptrtoint i8* %42 to i64
%45 = sub i64 %43, %44
store i64 %45, i64* %16
%46 = load i8*, i8** %12
%47 = load i64, i64* %16
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = getelementptr inbounds i8, i8* %48, i64 1
store i8* %49, i8** %15
%50 = load i8*, i8** %15
%51 = call i32 @atoi(i8* %50)
%52 = load i32*, i32** %10
store i32 %51, i32* %52
br label %60
53: ; preds = %37
%54 = load i8*, i8** %13
%55 = load i8*, i8** %12
%56 = ptrtoint i8* %54 to i64
%57 = ptrtoint i8* %55 to i64
%58 = sub i64 %56, %57
store i64 %58, i64* %16
%59 = load i32*, i32** %10
store i32 80, i32* %59
br label %60
60: ; preds = %53, %40
%61 = load i8*, i8** %7
%62 = load i64, i64* %8
%63 = getelementptr inbounds i8, i8* %61, i64 %62
%64 = load i8*, i8** %13
%65 = ptrtoint i8* %63 to i64
%66 = ptrtoint i8* %64 to i64
%67 = sub i64 %65, %66
store i64 %67, i64* %17
%68 = load i8*, i8** %12
%69 = load i64, i64* %16
%70 = call i8* @strndup(i8* %68, i64 %69)
%71 = load i8**, i8*** %9
store i8* %70, i8** %71
%72 = load i8*, i8** %13
%73 = load i64, i64* %17
%74 = call i8* @strndup(i8* %72, i64 %73)
%75 = load i8**, i8*** %11
store i8* %74, i8** %75
store i32 1, i32* %6
br label %76
76: ; preds = %60, %36, %26, %20
%77 = load i32, i32* %6
ret i32 %77
}

LLVM IR (-O2):
define i32 @simplehttp_parse_url(i8* %0, i64 %1, i8** nocapture writeonly %2, i32* nocapture writeonly %3, i8** nocapture writeonly %4) {
%6 = icmp ult i64 %1, 9
br i1 %6, label %38, label %7
7: ; preds = %5
%8 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%9 = icmp eq i8* %8, null
br i1 %9, label %38, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %8, i64 2
%12 = tail call i8* @strchr(i8* %11, i8 signext 58)
%13 = tail call i8* @strchr(i8* %11, i8 signext 47)
%14 = icmp eq i8* %13, null
br i1 %14, label %38, label %15
15: ; preds = %10
%16 = icmp eq i8* %12, null
br i1 %16, label %25, label %17
17: ; preds = %15
%18 = ptrtoint i8* %12 to i64
%19 = ptrtoint i8* %11 to i64
%20 = sub i64 %18, %19
%21 = getelementptr inbounds i8, i8* %11, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = tail call i32 @atoi(i8* %22)
%24 = ptrtoint i8* %13 to i64
br label %29
25: ; preds = %15
%26 = ptrtoint i8* %13 to i64
%27 = ptrtoint i8* %11 to i64
%28 = sub i64 %26, %27
br label %29
29: ; preds = %25, %17
%30 = phi i64 [ %26, %25 ], [ %24, %17 ]
%31 = phi i32 [ 80, %25 ], [ %23, %17 ]
%32 = phi i64 [ %28, %25 ], [ %20, %17 ]
store i32 %31, i32* %3
%33 = getelementptr inbounds i8, i8* %0, i64 %1
%34 = ptrtoint i8* %33 to i64
%35 = sub i64 %34, %30
%36 = tail call i8* @strndup(i8* %11, i64 %32)
store i8* %36, i8** %2
%37 = tail call i8* @strndup(i8* %13, i64 %35)
store i8* %37, i8** %4
br label %38
38: ; preds = %10, %7, %5, %29
%39 = phi i32 [ 1, %29 ], [ 0, %5 ], [ 0, %7 ], [ 0, %10 ]
ret i32 %39
}