#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 strlen(char *);
char *strrchr(char *, char);
int stripdown(char *path) {
  if (path[strlen(path) - 1] == '/')
    path[strlen(path) - 1] = '\0';
  if (!strrchr(path, '/'))
    return -1;
  if (strrchr(path, '/') != path + strlen("http:/"))
    *(strrchr(path, '/') + 1) = '\0';
}


x86 assembly (clang, -O0):
<stripdown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1177 <stripdown+0x57>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
cmp    $0x0,%rax
jne    119b <stripdown+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <stripdown+0xcc>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe44(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rcx
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq %edx,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
je     11ec <stripdown+0xcc>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
movb   $0x0,0x1(%rax)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripdown>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1144 <stripdown+0x24>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1180 <stripdown+0x60>
mov    %rax,%r14
lea    0xea0(%rip),%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
cmp    %rax,%r14
je     1180 <stripdown+0x60>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
movb   $0x0,0x1(%rax)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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