#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 */
typedef int /*<<< orphan*/ suffixes;
typedef int /*<<< orphan*/ bases;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ is_valid_test(char *);
int /*<<< orphan*/ snprintf(char *, unsigned int, char *, char const *,
                            char const *, char const *);
int strlen(char const *);
char *x_malloc(unsigned int, char *, int);
char *x_strdup(char const *, char *, int);
char *find_test(const char *name, const char *source, const char *build) {
  char *path;
  const char *bases[3], *suffix, *base;
  unsigned int i, j;
  const char *suffixes[3] = {"-t", ".t", ""};
  bases[0] = ".";
  bases[1] = build;
  bases[2] = source;
  for (i = 0; i < (sizeof(suffixes) / sizeof((suffixes)[0])); i++) {
    suffix = suffixes[i];
    for (j = 0; j < (sizeof(bases) / sizeof((bases)[0])); j++) {
      unsigned int path_len;
      base = bases[j];
      if (base == NULL)
        continue;
      path_len = strlen(base) + strlen(name) + strlen(suffix) + 2;
      path = x_malloc((path_len),
                      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/dnstap/knot/refs/"
                      "heads/branches/dnstap/libtap/runtests.c",
                      1037);
      snprintf(path, path_len, "%s/%s%s", base, name, suffix);
      if (is_valid_test(path))
        return path;
      free(path);
      path = NULL;
    }
  }
  if (path == NULL)
    path = x_strdup((name),
                    "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/dnstap/knot/refs/heads/"
                    "branches/dnstap/libtap/runtests.c",
                    1046);
  return path;
}


x86 assembly (clang, -O0):
<find_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2c82(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0x2c7f(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0x2c7c(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe67(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    $0x3,%rax
jae    12c1 <find_test+0x161>
mov    -0x54(%rbp),%eax
mov    -0x70(%rbp,%rax,8),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    $0x3,%rax
jae    12ae <find_test+0x14e>
mov    -0x58(%rbp),%eax
mov    -0x40(%rbp,%rax,8),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1203 <find_test+0xa3>
jmp    12a0 <find_test+0x140>
mov    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x78(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x78(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%edi
lea    0xdc6(%rip),%rsi
mov    $0x40d,%edx
call   1070 <x_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x74(%rbp),%esi
mov    -0x50(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x48(%rbp),%r9
lea    0xe31(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <is_valid_test@plt>
cmp    $0x0,%rax
je     128f <find_test+0x12f>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12ed <find_test+0x18d>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11da <find_test+0x7a>
jmp    12b3 <find_test+0x153>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11ba <find_test+0x5a>
cmpq   $0x0,-0x28(%rbp)
jne    12e5 <find_test+0x185>
mov    -0x10(%rbp),%rdi
lea    0xd31(%rip),%rsi
mov    $0x416,%edx
call   1080 <x_strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,(%rsp)
mov    %rdi,%r15
xor    %r14d,%r14d
mov    %rdi,0x8(%rsp)
jmp    11a6 <find_test+0x46>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
call   1030 <free@plt>
add    $0x8,%r14
cmp    $0x18,%r14
je     1326 <find_test+0x1c6>
lea    0x2c53(%rip),%rax
mov    (%r14,%rax,1),%r12
lea    0xe4e(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1040 <strlen@plt>
add    %ebp,%ebx
add    %eax,%ebx
add    $0x2,%ebx
mov    %ebx,%edi
lea    0xe27(%rip),%rsi
mov    $0x40d,%edx
call   1070 <x_malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %ebx,%esi
lea    0xea1(%rip),%rdx
lea    0xe05(%rip),%rcx
mov    %r15,%r8
mov    %r12,%r9
call   1060 <snprintf@plt>
mov    %r13,%rdi
call   1050 <is_valid_test@plt>
test   %rax,%rax
jne    1314 <find_test+0x1b4>
mov    %r13,%rdi
call   1030 <free@plt>
cmpq   $0x0,0x10(%rsp)
je     12a2 <find_test+0x142>
mov    0x10(%rsp),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1040 <strlen@plt>
add    %ebx,%ebp
lea    (%rax,%rbp,1),%ebx
add    $0x2,%ebx
mov    %ebx,%edi
lea    0xda7(%rip),%rsi
mov    $0x40d,%edx
call   1070 <x_malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %ebx,%esi
lea    0xe21(%rip),%rdx
mov    %r15,%rcx
mov    0x8(%rsp),%r15
mov    %r15,%r8
mov    %r12,%r9
call   1060 <snprintf@plt>
mov    %r13,%rdi
call   1050 <is_valid_test@plt>
test   %rax,%rax
jne    1314 <find_test+0x1b4>
mov    %r13,%rdi
call   1030 <free@plt>
cmpq   $0x0,(%rsp)
je     1198 <find_test+0x38>
mov    (%rsp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1040 <strlen@plt>
add    %ebx,%ebp
lea    (%rax,%rbp,1),%ebx
add    $0x2,%ebx
mov    %ebx,%edi
lea    0xd2d(%rip),%rsi
mov    $0x40d,%edx
call   1070 <x_malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %ebx,%esi
lea    0xda7(%rip),%rdx
mov    (%rsp),%rcx
mov    %r15,%r8
mov    %r12,%r9
call   1060 <snprintf@plt>
mov    %r13,%rdi
call   1050 <is_valid_test@plt>
test   %rax,%rax
je     1190 <find_test+0x30>
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcdb(%rip),%rsi
mov    %r15,%rdi
mov    $0x416,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <x_strdup@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-t\00"
@.str.1 = [3 x i8] c".t\00"
@.str.2 = [1 x i8] zeroinitializer
@__const.find_test.suffixes = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [2 x i8] c".\00"
@.str.4 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dnstap/knot/refs/heads/branches/dnstap/libtap/runtests.c\00"
@.str.5 = [8 x i8] c"%s/%s%s\00"
define i8* @find_test(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [3 x i8*]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca [3 x i8*]
%15 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%16 = bitcast [3 x i8*]* %14 to i8*
%17 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %17
%18 = load i8*, i8** %7
%19 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 1
store i8* %18, i8** %19
%20 = load i8*, i8** %6
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 2
store i8* %20, i8** %21
store i32 0, i32* %12
br label %22
22: ; preds = %73, %3
%23 = load i32, i32* %12
%24 = zext i32 %23 to i64
%25 = icmp ult i64 %24, 3
br i1 %25, label %26, label %76
26: ; preds = %22
%27 = load i32, i32* %12
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [3 x i8*], [3 x i8*]* %14, i64 0, i64 %28
%30 = load i8*, i8** %29
store i8* %30, i8** %10
store i32 0, i32* %13
br label %31
31: ; preds = %69, %26
%32 = load i32, i32* %13
%33 = zext i32 %32 to i64
%34 = icmp ult i64 %33, 3
br i1 %34, label %35, label %72
35: ; preds = %31
%36 = load i32, i32* %13
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 %37
%39 = load i8*, i8** %38
store i8* %39, i8** %11
%40 = load i8*, i8** %11
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %43
42: ; preds = %35
br label %69
43: ; preds = %35
%44 = load i8*, i8** %11
%45 = call i32 @strlen(i8* %44)
%46 = load i8*, i8** %5
%47 = call i32 @strlen(i8* %46)
%48 = add nsw i32 %45, %47
%49 = load i8*, i8** %10
%50 = call i32 @strlen(i8* %49)
%51 = add nsw i32 %48, %50
%52 = add nsw i32 %51, 2
store i32 %52, i32* %15
%53 = load i32, i32* %15
%54 = call i8* @x_malloc(i32 %53, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.4, i64 0, i64 0), i32 1037)
store i8* %54, i8** %8
%55 = load i8*, i8** %8
%56 = load i32, i32* %15
%57 = load i8*, i8** %11
%58 = load i8*, i8** %5
%59 = load i8*, i8** %10
%60 = call i32 @snprintf(i8* %55, i32 %56, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %57, i8* %58, i8* %59)
%61 = load i8*, i8** %8
%62 = call i64 @is_valid_test(i8* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %43
%65 = load i8*, i8** %8
store i8* %65, i8** %4
br label %84
66: ; preds = %43
%67 = load i8*, i8** %8
%68 = call i32 @free(i8* %67)
store i8* null, i8** %8
br label %69
69: ; preds = %66, %42
%70 = load i32, i32* %13
%71 = add i32 %70, 1
store i32 %71, i32* %13
br label %31
72: ; preds = %31
br label %73
73: ; preds = %72
%74 = load i32, i32* %12
%75 = add i32 %74, 1
store i32 %75, i32* %12
br label %22
76: ; preds = %22
%77 = load i8*, i8** %8
%78 = icmp eq i8* %77, null
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = load i8*, i8** %5
%81 = call i8* @x_strdup(i8* %80, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.4, i64 0, i64 0), i32 1046)
store i8* %81, i8** %8
br label %82
82: ; preds = %79, %76
%83 = load i8*, i8** %8
store i8* %83, i8** %4
br label %84
84: ; preds = %82, %64
%85 = load i8*, i8** %4
ret i8* %85
}

LLVM IR (-O2):
@.str = [3 x i8] c"-t\00"
@.str.1 = [3 x i8] c".t\00"
@.str.2 = [1 x i8] zeroinitializer
@__const.find_test.suffixes = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [2 x i8] c".\00"
@.str.4 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dnstap/knot/refs/heads/branches/dnstap/libtap/runtests.c\00"
@.str.5 = [8 x i8] c"%s/%s%s\00"
define i8* @find_test(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %2, null
%5 = icmp eq i8* %1, null
br label %6
6: ; preds = %49, %3
%7 = phi i64 [ 0, %3 ], [ %50, %49 ]
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.find_test.suffixes, i64 0, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @strlen(i8* %0)
%12 = tail call i32 @strlen(i8* %9)
%13 = add i32 %10, 2
%14 = add i32 %13, %11
%15 = add i32 %14, %12
%16 = tail call i8* @x_malloc(i32 %15, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.4, i64 0, i64 0), i32 1037)
%17 = tail call i32 @snprintf(i8* %16, i32 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %9)
%18 = tail call i64 @is_valid_test(i8* %16)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %54
20: ; preds = %6
%21 = tail call i32 @free(i8* %16)
br i1 %4, label %35, label %22
22: ; preds = %20
%23 = tail call i32 @strlen(i8* %2)
%24 = tail call i32 @strlen(i8* %0)
%25 = tail call i32 @strlen(i8* %9)
%26 = add i32 %23, 2
%27 = add i32 %26, %24
%28 = add i32 %27, %25
%29 = tail call i8* @x_malloc(i32 %28, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.4, i64 0, i64 0), i32 1037)
%30 = tail call i32 @snprintf(i8* %29, i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* %0, i8* %9)
%31 = tail call i64 @is_valid_test(i8* %29)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %54
33: ; preds = %22
%34 = tail call i32 @free(i8* %29)
br label %35
35: ; preds = %33, %20
br i1 %5, label %49, label %36
36: ; preds = %35
%37 = tail call i32 @strlen(i8* %1)
%38 = tail call i32 @strlen(i8* %0)
%39 = tail call i32 @strlen(i8* %9)
%40 = add i32 %37, 2
%41 = add i32 %40, %38
%42 = add i32 %41, %39
%43 = tail call i8* @x_malloc(i32 %42, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.4, i64 0, i64 0), i32 1037)
%44 = tail call i32 @snprintf(i8* %43, i32 %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %1, i8* %0, i8* %9)
%45 = tail call i64 @is_valid_test(i8* %43)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %36
%48 = tail call i32 @free(i8* %43)
br label %49
49: ; preds = %47, %35
%50 = add nuw nsw i64 %7, 1
%51 = icmp eq i64 %50, 3
br i1 %51, label %52, label %6
52: ; preds = %49
%53 = tail call i8* @x_strdup(i8* %0, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.4, i64 0, i64 0), i32 1046)
br label %54
54: ; preds = %6, %22, %36, %52
%55 = phi i8* [ %53, %52 ], [ %43, %36 ], [ %29, %22 ], [ %16, %6 ]
ret i8* %55
}