#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 */
char *must_alloc(scalar_t__);
char *strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strrchr(char *, char);
char *create_outname(char *url) {
  char *fname;
  char *p = strrchr(url, '/');
  if (p) {
    ++p;
    if (*p)
      fname = p;
    else
      fname = "index.html";
  } else
    fname = url;
  char *outname = must_alloc(strlen(fname) + 4 + 1);
  return strcpy(outname, fname);
}


x86 assembly (clang, -O0):
<create_outname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119f <create_outname+0x5f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     118f <create_outname+0x4f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    119a <create_outname+0x5a>
lea    0xe6a(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11a7 <create_outname+0x67>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x4,%rdi
add    $0x1,%rdi
call   1060 <must_alloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_outname>:
push   %rbx
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1169 <create_outname+0x29>
mov    %rax,%rcx
add    $0x1,%rcx
cmpb   $0x0,0x1(%rax)
lea    0xe9b(%rip),%rbx
cmovne %rcx,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x5(%rax),%rdi
call   1060 <must_alloc@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1030 <strcpy@plt>

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

LLVM IR (-O2):
@.str = [11 x i8] c"index.html\00"
define i8* @create_outname(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
%8 = select i1 %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %5
br label %9
9: ; preds = %1, %4
%10 = phi i8* [ %8, %4 ], [ %0, %1 ]
%11 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%12 = add nsw i64 %11, 5
%13 = tail call i8* @must_alloc(i64 %12)
%14 = tail call i8* @strcpy(i8* dereferenceable(1) %13, i8* dereferenceable(1) %10)
ret i8* %13
}