#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 *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
const char *rewrite_url(char *url) {
  if (strcmp(url, "/") == 0)
    return "/index.html";
  char *tmp = strchr(url, '?');
  if (tmp == NULL)
    return url;
  url[(tmp - url)] = '\0';
  return url;
}


x86 assembly (clang, -O0):
<rewrite_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec9(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1156 <rewrite_url+0x36>
lea    0xeb5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119b <rewrite_url+0x7b>
mov    -0x10(%rbp),%rdi
mov    $0x3f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1180 <rewrite_url+0x60>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119b <rewrite_url+0x7b>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rewrite_url>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     114c <rewrite_url+0x2c>
mov    %rbx,%rdi
mov    $0x3f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1153 <rewrite_url+0x33>
movb   $0x0,(%rax)
jmp    1153 <rewrite_url+0x33>
lea    0xeaf(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [12 x i8] c"/index.html\00"
define i8* @rewrite_url(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %25
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @strchr(i8* %10, i8 signext 63)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = load i8*, i8** %3
store i8* %15, i8** %2
br label %25
16: ; preds = %9
%17 = load i8*, i8** %3
%18 = load i8*, i8** %4
%19 = load i8*, i8** %3
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = getelementptr inbounds i8, i8* %17, i64 %22
store i8 0, i8* %23
%24 = load i8*, i8** %3
store i8* %24, i8** %2
br label %25
25: ; preds = %16, %14, %8
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [12 x i8] c"/index.html\00"
define i8* @rewrite_url(i8* %0) {
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 63)
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = ptrtoint i8* %5 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %7, %4, %1
%13 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %1 ], [ %0, %4 ], [ %0, %7 ]
ret i8* %13
}