#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*/ getfilename(char *, int, char *);
size_t strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncmp(char *, char *, size_t);
char *addfilename(char *url, int size, char *pagefile) {
  char buff[512];
  getfilename(buff, 512, pagefile);
  if (!strncmp(url + strlen(url) - strlen(buff), buff,
               size - strlen(url) + strlen(buff)))
    return url;
  if (!(url[strlen(url) - 1] == '/'))
    strncat(url, "/", size);
  strncat(url, buff, size);
  return url;
}


x86 assembly (clang, -O0):
<addfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x200,%esi
call   1040 <getfilename@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x250(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x250(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x248(%rbp)
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdx
mov    -0x248(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x230(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x228(%rbp)
movslq -0x14(%rbp),%rax
mov    %rax,-0x240(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x240(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x238(%rbp)
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x238(%rbp),%rdx
mov    -0x230(%rbp),%rdi
mov    -0x228(%rbp),%rsi
add    %rax,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    122d <addfilename+0xed>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    128a <addfilename+0x14a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x258(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x258(%rbp),%rax
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     126f <addfilename+0x12f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xd96(%rip),%rsi
call   1060 <strncat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <strncat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addfilename>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %esi,%r14d
mov    %rdi,%r12
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x200,%esi
call   1040 <getfilename@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
lea    (%r12,%rax,1),%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
sub    %rax,%rbx
movslq %r14d,%rdx
sub    %rbp,%rdx
add    %rax,%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strncmp@plt>
test   %eax,%eax
je     11bf <addfilename+0x7f>
cmpb   $0x2f,-0x1(%rbp,%r12,1)
je     11b1 <addfilename+0x71>
lea    0xe5a(%rip),%rsi
mov    %r12,%rdi
mov    %r14d,%edx
call   1060 <strncat@plt>
mov    %rsp,%rsi
mov    %r12,%rdi
mov    %r14d,%edx
call   1060 <strncat@plt>
mov    %r12,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @addfilename(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [512 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %7
%11 = call i32 @getfilename(i8* %9, i32 512, i8* %10)
%12 = load i8*, i8** %5
%13 = load i8*, i8** %5
%14 = call i64 @strlen(i8* %13)
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
%18 = sub i64 0, %17
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = load i8*, i8** %5
%24 = call i64 @strlen(i8* %23)
%25 = sub i64 %22, %24
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%27 = call i64 @strlen(i8* %26)
%28 = add i64 %25, %27
%29 = call i32 @strncmp(i8* %19, i8* %20, i64 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %3
%32 = load i8*, i8** %5
store i8* %32, i8** %4
br label %52
33: ; preds = %3
%34 = load i8*, i8** %5
%35 = load i8*, i8** %5
%36 = call i64 @strlen(i8* %35)
%37 = sub i64 %36, 1
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 47
br i1 %41, label %46, label %42
42: ; preds = %33
%43 = load i8*, i8** %5
%44 = load i32, i32* %6
%45 = call i32 @strncat(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %42, %33
%47 = load i8*, i8** %5
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%49 = load i32, i32* %6
%50 = call i32 @strncat(i8* %47, i8* %48, i32 %49)
%51 = load i8*, i8** %5
store i8* %51, i8** %4
br label %52
52: ; preds = %46, %31
%53 = load i8*, i8** %4
ret i8* %53
}

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