#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 strchrcount(char *, char);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int url_depth(char url[]) {
  int len;
  if (strncmp(url, "http://", 7) != 0) {
    return -1;
  }
  len = strchrcount(url + 7, '/');
  if (url[strlen(url) - 1] == '/') {
    --len;
  }
  return len;
}


x86 assembly (clang, -O0):
<url_depth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1167 <url_depth+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <url_depth+0x85>
mov    -0x10(%rbp),%rdi
add    $0x7,%rdi
mov    $0x2f,%esi
call   1050 <strchrcount@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11af <url_depth+0x7f>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_depth>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec3(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1177 <url_depth+0x47>
lea    0x7(%rbx),%rdi
mov    $0x2f,%esi
call   1050 <strchrcount@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
xor    %ecx,%ecx
cmpb   $0x2f,-0x1(%rax,%rbx,1)
sete   %cl
sub    %ecx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
define i32 @url_depth(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %27
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 7
%12 = call i32 @strchrcount(i8* %11, i8 signext 47)
store i32 %12, i32* %4
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %13, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 47
br i1 %21, label %22, label %25
22: ; preds = %9
%23 = load i32, i32* %4
%24 = add nsw i32 %23, -1
store i32 %24, i32* %4
br label %25
25: ; preds = %22, %9
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %8
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
define i32 @url_depth(i8* %0) {
%2 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 7
%6 = tail call i32 @strchrcount(i8* %5, i8 signext 47)
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
%13 = sext i1 %12 to i32
%14 = add nsw i32 %6, %13
br label %15
15: ; preds = %1, %4
%16 = phi i32 [ %14, %4 ], [ -1, %1 ]
ret i32 %16
}