#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*/ fz_strlcat(char *, char *, int);
int /*<<< orphan*/ fz_strlcpy(char *, char *, int);
char *strrchr(char *, char);
void xps_rels_for_part(char *buf, char *name, int buflen) {
  char *p, *basename;
  p = strrchr(name, '/');
  basename = p ? p + 1 : name;
  fz_strlcpy(buf, name, buflen);
  p = strrchr(buf, '/');
  if (p)
    *p = 0;
  fz_strlcat(buf, "/_rels/", buflen);
  fz_strlcat(buf, basename, buflen);
  fz_strlcat(buf, ".rels", buflen);
}


x86 assembly (clang, -O0):
<xps_rels_for_part>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1171 <xps_rels_for_part+0x41>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1179 <xps_rels_for_part+0x49>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <fz_strlcpy@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b5 <xps_rels_for_part+0x85>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe3d(%rip),%rsi
call   1040 <fz_strlcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <fz_strlcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe22(%rip),%rsi
call   1040 <fz_strlcat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xps_rels_for_part>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1030 <fz_strlcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1174 <xps_rels_for_part+0x44>
movb   $0x0,(%rax)
lea    0x1(%r15),%rbp
test   %r15,%r15
cmove  %r12,%rbp
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1040 <fz_strlcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1040 <fz_strlcat@plt>
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fz_strlcat@plt>

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

LLVM IR (-O2):
@.str = [8 x i8] c"/_rels/\00"
@.str.1 = [6 x i8] c".rels\00"
define void @xps_rels_for_part(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%5 = tail call i32 @fz_strlcpy(i8* %0, i8* %1, i32 %2)
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %3
store i8 0, i8* %6
br label %9
9: ; preds = %8, %3
%10 = icmp eq i8* %4, null
%11 = getelementptr inbounds i8, i8* %4, i64 1
%12 = select i1 %10, i8* %1, i8* %11
%13 = tail call i32 @fz_strlcat(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %2)
%14 = tail call i32 @fz_strlcat(i8* %0, i8* %12, i32 %2)
%15 = tail call i32 @fz_strlcat(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %2)
ret void
}