#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*/ printf(char *, char *, int /*<<< orphan*/);
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
char *strstr(char const *, char *);
int parse_url(const char *uri, char **host, char **path) {
  char *pos;
  pos = strstr(uri, "//");
  if (!pos) {
    return 1;
  }
  *host = pos + 2;
  pos = strchr(*host, '/');
  if (!pos) {
    *path = NULL;
  } else {
    *pos = '\0';
    *path = pos + 1;
    printf("DEBUG: path = %s, len = %zd\n", *path, strlen(*path));
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_url>:
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    0xea1(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117f <parse_url+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    1204 <parse_url+0xc4>
mov    -0x28(%rbp),%rcx
add    $0x2,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11be <parse_url+0x7e>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
jmp    11fd <parse_url+0xbd>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xe0b(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_url>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xeaf(%rip),%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     119c <parse_url+0x5c>
add    $0x2,%rax
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a3 <parse_url+0x63>
mov    %rax,%rbx
movb   $0x0,(%rax)
add    $0x1,%rbx
mov    %rbx,(%r14)
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xe73(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
jmp    11aa <parse_url+0x6a>
mov    $0x1,%eax
jmp    11ac <parse_url+0x6c>
movq   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"//\00"
@.str.1 = [29 x i8] c"DEBUG: path = %s, len = %zd\0A\00"
define i32 @parse_url(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%9 = load i8*, i8** %5
%10 = call i8* @strstr(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %3
store i32 1, i32* %4
br label %37
14: ; preds = %3
%15 = load i8*, i8** %8
%16 = getelementptr inbounds i8, i8* %15, i64 2
%17 = load i8**, i8*** %6
store i8* %16, i8** %17
%18 = load i8**, i8*** %6
%19 = load i8*, i8** %18
%20 = call i8* @strchr(i8* %19, i8 signext 47)
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = icmp ne i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %14
%24 = load i8**, i8*** %7
store i8* null, i8** %24
br label %36
25: ; preds = %14
%26 = load i8*, i8** %8
store i8 0, i8* %26
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8**, i8*** %7
store i8* %28, i8** %29
%30 = load i8**, i8*** %7
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %7
%33 = load i8*, i8** %32
%34 = call i32 @strlen(i8* %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %31, i32 %34)
br label %36
36: ; preds = %25, %23
store i32 0, i32* %4
br label %37
37: ; preds = %36, %13
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@.str = [3 x i8] c"//\00"
@.str.1 = [29 x i8] c"DEBUG: path = %s, len = %zd\0A\00"
define i32 @parse_url(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 2
store i8* %7, i8** %1
%8 = tail call i8* @strchr(i8* %7, i8 signext 47)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %6
store i8* null, i8** %2
br label %15
11: ; preds = %6
store i8 0, i8* %8
%12 = getelementptr inbounds i8, i8* %8, i64 1
store i8* %12, i8** %2
%13 = tail call i32 @strlen(i8* %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %13)
br label %15
15: ; preds = %10, %11, %3
%16 = phi i32 [ 1, %3 ], [ 0, %11 ], [ 0, %10 ]
ret i32 %16
}