#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*/ gsft_strlcpy(char *, char const *, size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char const *);
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char const *, size_t const);
void gsft_file_abs_to_rel(const char *path_abs, const char *path_root,
                          char *path_rel, size_t path_rel_len) {
  const size_t path_root_len = strlen(path_root);
  if (strncmp(path_abs, path_root, path_root_len) != 0) {
    gsft_strlcpy(path_rel, path_abs, path_rel_len);
    return;
  }
  do {
    snprintf(path_rel, path_rel_len,
             "."
             "/"
             "%s",
             &path_abs[path_root_len]);
    path_rel[path_rel_len - 1] = 0x00;
  } while (0);
  return;
}


x86 assembly (clang, -O0):
<gsft_file_abs_to_rel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1196 <gsft_file_abs_to_rel+0x56>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <gsft_strlcpy@plt>
jmp    11cc <gsft_file_abs_to_rel+0x8c>
jmp    119b <gsft_file_abs_to_rel+0x5b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rcx
add    -0x28(%rbp),%rcx
lea    0xe4e(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11cc <gsft_file_abs_to_rel+0x8c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gsft_file_abs_to_rel>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     118a <gsft_file_abs_to_rel+0x4a>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <gsft_strlcpy@plt>
add    %r12,%r13
lea    0xe6c(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13,%rcx
call   1050 <snprintf@plt>
movb   $0x0,-0x1(%r14,%r15,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"./%s\00"
define void @gsft_file_abs_to_rel(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = tail call i64 @strncmp(i8* %0, i8* %1, i64 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @gsft_strlcpy(i8* %2, i8* %0, i64 %3)
br label %15
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %0, i64 %5
%12 = tail call i32 @snprintf(i8* %2, i64 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = add i64 %3, -1
%14 = getelementptr inbounds i8, i8* %2, i64 %13
store i8 0, i8* %14
br label %15
15: ; preds = %10, %8
ret void
}