char *find_build_path() {
  char *path = (char *)malloc(
      strlen("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/goldsborough/ipc-bench/refs/heads/"
             "master/source/common/process.c") +
      strlen("/build/source\0"));
  char *right;
  char *left;
  strcpy(path, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/goldsborough/ipc-bench/refs/"
               "heads/master/source/common/process.c");
  right =
      path + strlen("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/goldsborough/ipc-bench/"
                    "refs/heads/master/source/common/process.c");
  left = right - strlen("ipc-bench");
  for (--right; left >= path; --left, --right) {
    if (*left == 'i' && *right == 'h') {
      if (strncmp("ipc-bench", left, 9) == 0) {
        break;
      }
    }
  }
  strcpy(++right, "/build/source\0");
  return path;
}


x86 assembly (clang, -O0):
<find_build_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0xa7,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x9a,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0xfffffffffffffff7,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     11f4 <find_build_path+0xc4>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x69,%eax
jne    11d2 <find_build_path+0xa2>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x68,%eax
jne    11d2 <find_build_path+0xa2>
mov    -0x18(%rbp),%rsi
lea    0xee6(%rip),%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11cd <find_build_path+0x9d>
jmp    11f4 <find_build_path+0xc4>
jmp    11d2 <find_build_path+0xa2>
jmp    11d7 <find_build_path+0xa7>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    117c <find_build_path+0x4c>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x10(%rbp)
lea    0xe9e(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_build_path>:
push   %r15
push   %r14
push   %rbx
mov    $0xa7,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0xeb7(%rip),%rsi
mov    $0x9b,%edx
mov    %rax,%rdi
call   1040 <memcpy@plt>
lea    0x90(%r15),%rbx
mov    $0x70,%al
lea    0xf35(%rip),%r14
cmp    $0x69,%al
jne    118b <find_build_path+0x5b>
nopw   0x0(%rax,%rax,1)
cmpb   $0x68,0x9(%rbx)
jne    118b <find_build_path+0x5b>
lea    0x1(%rbx),%rsi
mov    $0x9,%edx
mov    %r14,%rdi
call   1030 <strncmp@plt>
test   %eax,%eax
je     11a3 <find_build_path+0x73>
cmp    %r15,%rbx
jb     119d <find_build_path+0x6d>
movzbl (%rbx),%eax
add    $0xffffffffffffffff,%rbx
cmp    $0x69,%al
je     1170 <find_build_path+0x40>
jmp    118b <find_build_path+0x5b>
add    $0x8,%rbx
jmp    11a7 <find_build_path+0x77>
add    $0x9,%rbx
movabs $0x656372756f732f,%rax
mov    %rax,0x7(%rbx)
movabs $0x732f646c6975622f,%rax
64 2f 73
mov    %rax,0x1(%rbx)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [155 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/goldsborough/ipc-bench/refs/heads/master/source/common/process.c\00"
@.str.1 = [10 x i8] c"ipc-bench\00"
@.str.2 = [15 x i8] c"/build/source\00\00"
define i8* @find_build_path() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @malloc(i64 167)
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = call i8* @strcpy(i8* %5, i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %1
%8 = getelementptr inbounds i8, i8* %7, i64 154
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 -9
store i8* %10, i8** %3
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i32 -1
store i8* %12, i8** %2
br label %13
13: ; preds = %34, %0
%14 = load i8*, i8** %3
%15 = load i8*, i8** %1
%16 = icmp uge i8* %14, %15
br i1 %16, label %17, label %39
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 105
br i1 %21, label %22, label %33
22: ; preds = %17
%23 = load i8*, i8** %2
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 104
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i8*, i8** %3
%29 = call i32 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %28, i64 9)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
br label %39
32: ; preds = %27
br label %33
33: ; preds = %32, %22, %17
br label %34
34: ; preds = %33
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 -1
store i8* %36, i8** %3
%37 = load i8*, i8** %2
%38 = getelementptr inbounds i8, i8* %37, i32 -1
store i8* %38, i8** %2
br label %13
39: ; preds = %31, %13
%40 = load i8*, i8** %2
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %2
%42 = call i8* @strcpy(i8* %41, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%43 = load i8*, i8** %1
ret i8* %43
}

LLVM IR (-O2):
@.str = [155 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/goldsborough/ipc-bench/refs/heads/master/source/common/process.c\00"
@.str.1 = [10 x i8] c"ipc-bench\00"
@.str.2 = [15 x i8] c"/build/source\00\00"
define i8* @find_build_path() {
%1 = tail call dereferenceable_or_null(167) i8* @malloc(i64 167)
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(155) %1, i8* align 1 dereferenceable(155) getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i64 155, i1 false)
%2 = getelementptr inbounds i8, i8* %1, i64 145
%3 = getelementptr inbounds i8, i8* %1, i64 153
br label %4
4: ; preds = %19, %0
%5 = phi i8 [ 112, %0 ], [ %20, %19 ]
%6 = phi i8* [ %2, %0 ], [ %16, %19 ]
%7 = phi i8* [ %3, %0 ], [ %17, %19 ]
%8 = icmp eq i8 %5, 105
br i1 %8, label %9, label %15
9: ; preds = %4
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 104
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @strncmp(i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %6, i64 9)
%14 = icmp eq i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %4, %9, %12
%16 = getelementptr inbounds i8, i8* %6, i64 -1
%17 = getelementptr inbounds i8, i8* %7, i64 -1
%18 = icmp ult i8* %16, %1
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = load i8, i8* %16
br label %4
21: ; preds = %12, %15
%22 = phi i8* [ %7, %12 ], [ %17, %15 ]
%23 = getelementptr inbounds i8, i8* %22, i64 1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(14) %23, i8* align 1 dereferenceable(14) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 14, i1 false)
ret i8* %1
}