#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*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *getenv(char *);
int /*<<< orphan*/ peos_set_error_msg(char *, int, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *find_file(char *file) {
  char result[BUFSIZ];
  char *env;
  FILE *f;
  if (!file) {
    peos_set_error_msg(
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/CS4098Group/Project/refs/heads/master/peos/"
        "os/kernel/peos_util.c",
        14, "find_file: no filename specified");
    return NULL;
  }
  if ((strlen(file) > 0 && file[0] == '/') ||
      (strlen(file) > 1 && strncmp(file, "./", 2) == 0)) {
    strcpy(result, file);
  } else {
    sprintf(result, "./%s", file);
  }
  if ((f = fopen(result, "r"))) {
    fclose(f);
    return strdup(result);
  }
  if ((env = getenv("COMPILER_DIR"))) {
    if (!(strlen(file) > 0 && file[0] == '/') &&
        !(strlen(file) > 1 && strncmp(file, "./", 2) == 0)) {
      sprintf(result, "%s/%s", env, file);
      if ((f = fopen(result, "r"))) {
        fclose(f);
        return strdup(result);
      }
    }
  }
  peos_set_error_msg("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                     "outputs/2022-01-22/02-19-57/repos/CS4098Group/Project/"
                     "refs/heads/master/peos/os/kernel/peos_util.c",
                     40, "find_file: file %s not found", file);
  return NULL;
}


x86 assembly (clang, -O0):
<find_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1201 <find_file+0x71>
lea    0xe26(%rip),%rdi
mov    $0xe,%esi
lea    0xeb5(%rip),%rdx
mov    $0x0,%al
call   1080 <peos_set_error_msg@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    13ba <find_file+0x22a>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x0,%eax
jle    1223 <find_file+0x93>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1254 <find_file+0xc4>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x1,%eax
jle    1266 <find_file+0xd6>
mov    -0x10(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1266 <find_file+0xd6>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
jmp    127c <find_file+0xec>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12bc <find_file+0x12c>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    13ba <find_file+0x22a>
lea    0xe03(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     138d <find_file+0x1fd>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x0,%eax
jle    12f8 <find_file+0x168>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1388 <find_file+0x1f8>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x1,%eax
jle    1329 <find_file+0x199>
mov    -0x10(%rbp),%rdi
lea    0xda7(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1388 <find_file+0x1f8>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd97(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xd76(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1383 <find_file+0x1f3>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    13ba <find_file+0x22a>
jmp    1388 <find_file+0x1f8>
jmp    138d <find_file+0x1fd>
mov    -0x10(%rbp),%rcx
lea    0xc68(%rip),%rdi
mov    $0x28,%esi
lea    0xd35(%rip),%rdx
mov    $0x0,%al
call   1080 <peos_set_error_msg@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %rdi,%rdi
je     1207 <find_file+0x77>
mov    %rdi,%r14
call   1070 <strlen@plt>
test   %eax,%eax
jle    11cb <find_file+0x3b>
cmpb   $0x2f,(%r14)
je     1228 <find_file+0x98>
mov    %r14,%rdi
call   1070 <strlen@plt>
cmp    $0x2,%eax
jl     11f1 <find_file+0x61>
lea    0xedd(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1228 <find_file+0x98>
lea    0xec7(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <sprintf@plt>
jmp    1233 <find_file+0xa3>
lea    0xdf2(%rip),%rdi
lea    0xe86(%rip),%rdx
xor    %ebx,%ebx
mov    $0xe,%esi
xor    %eax,%eax
call   1080 <peos_set_error_msg@plt>
jmp    12f9 <find_file+0x169>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     125f <find_file+0xcf>
mov    %rax,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   10b0 <strdup@plt>
mov    %rax,%rbx
jmp    12f9 <find_file+0x169>
lea    0xe60(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12da <find_file+0x14a>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <strlen@plt>
test   %eax,%eax
jle    1285 <find_file+0xf5>
cmpb   $0x2f,(%r14)
je     12da <find_file+0x14a>
mov    %r14,%rdi
call   1070 <strlen@plt>
cmp    $0x2,%eax
jl     12ab <find_file+0x11b>
lea    0xe23(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     12da <find_file+0x14a>
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   10a0 <sprintf@plt>
lea    0xdfb(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
jne    1247 <find_file+0xb7>
lea    0xd1f(%rip),%rdi
lea    0xdf1(%rip),%rdx
xor    %ebx,%ebx
mov    $0x28,%esi
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <peos_set_error_msg@plt>
mov    %rbx,%rax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [155 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/CS4098Group/Project/refs/heads/master/peos/os/kernel/peos_util.c\00"
@.str.1 = [33 x i8] c"find_file: no filename specified\00"
@.str.2 = [3 x i8] c"./\00"
@.str.3 = [5 x i8] c"./%s\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [13 x i8] c"COMPILER_DIR\00"
@.str.6 = [6 x i8] c"%s/%s\00"
@.str.7 = [29 x i8] c"find_file: file %s not found\00"
define i8* @find_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %1
%16 = call i32 (i8*, i32, i8*, ...) @peos_set_error_msg(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i32 14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
store i32 1, i32* %8
br label %84
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* %18)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 47
br i1 %26, label %35, label %27
27: ; preds = %21, %17
%28 = load i8*, i8** %3
%29 = call i32 @strlen(i8* %28)
%30 = icmp sgt i32 %29, 1
br i1 %30, label %31, label %38
31: ; preds = %27
%32 = load i8*, i8** %3
%33 = call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31, %21
%36 = load i8*, i8** %3
%37 = call i32 @strcpy(i8* %12, i8* %36)
br label %41
38: ; preds = %31, %27
%39 = load i8*, i8** %3
%40 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38, %35
%42 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %42, i32** %7
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32*, i32** %7
%46 = call i32 @fclose(i32* %45)
%47 = call i8* @strdup(i8* %12)
store i8* %47, i8** %2
store i32 1, i32* %8
br label %84
48: ; preds = %41
%49 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i8* %49, i8** %6
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %81
51: ; preds = %48
%52 = load i8*, i8** %3
%53 = call i32 @strlen(i8* %52)
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %61
55: ; preds = %51
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i64 0
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 47
br i1 %60, label %80, label %61
61: ; preds = %55, %51
%62 = load i8*, i8** %3
%63 = call i32 @strlen(i8* %62)
%64 = icmp sgt i32 %63, 1
br i1 %64, label %65, label %69
65: ; preds = %61
%66 = load i8*, i8** %3
%67 = call i64 @strncmp(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%68 = icmp eq i64 %67, 0
br i1 %68, label %80, label %69
69: ; preds = %65, %61
%70 = load i8*, i8** %6
%71 = load i8*, i8** %3
%72 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %70, i8* %71)
%73 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %73, i32** %7
%74 = icmp ne i32* %73, null
br i1 %74, label %75, label %79
75: ; preds = %69
%76 = load i32*, i32** %7
%77 = call i32 @fclose(i32* %76)
%78 = call i8* @strdup(i8* %12)
store i8* %78, i8** %2
store i32 1, i32* %8
br label %84
79: ; preds = %69
br label %80
80: ; preds = %79, %65, %55
br label %81
81: ; preds = %80, %48
%82 = load i8*, i8** %3
%83 = call i32 (i8*, i32, i8*, ...) @peos_set_error_msg(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i32 40, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %82)
store i8* null, i8** %2
store i32 1, i32* %8
br label %84
84: ; preds = %81, %75, %44, %15
%85 = load i8*, i8** %4
%86 = load i8*, i8** %2
ret i8* %86
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [155 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/CS4098Group/Project/refs/heads/master/peos/os/kernel/peos_util.c\00"
@.str.1 = [33 x i8] c"find_file: no filename specified\00"
@.str.2 = [3 x i8] c"./\00"
@.str.3 = [5 x i8] c"./%s\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [13 x i8] c"COMPILER_DIR\00"
@.str.6 = [6 x i8] c"%s/%s\00"
@.str.7 = [29 x i8] c"find_file: file %s not found\00"
define noalias i8* @find_file(i8* %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (i8*, i32, i8*, ...) @peos_set_error_msg(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i32 14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %54
8: ; preds = %1
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 47
br i1 %13, label %20, label %14
14: ; preds = %11, %8
%15 = tail call i32 @strlen(i8* %0)
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17, %11
%21 = call i32 @strcpy(i8* %4, i8* %0)
br label %24
22: ; preds = %17, %14
%23 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %24
24: ; preds = %22, %20
%25 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = call i32 @fclose(i32* %25)
%29 = call i8* @strdup(i8* %4)
br label %54
30: ; preds = %24
%31 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %52, label %33
33: ; preds = %30
%34 = call i32 @strlen(i8* %0)
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i8, i8* %0
%38 = icmp eq i8 %37, 47
br i1 %38, label %52, label %39
39: ; preds = %36, %33
%40 = call i32 @strlen(i8* %0)
%41 = icmp sgt i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%44 = icmp eq i64 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %42, %39
%46 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %31, i8* %0)
%47 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%48 = icmp eq i32* %47, null
br i1 %48, label %52, label %49
49: ; preds = %45
%50 = call i32 @fclose(i32* %47)
%51 = call i8* @strdup(i8* %4)
br label %54
52: ; preds = %36, %42, %45, %30
%53 = call i32 (i8*, i32, i8*, ...) @peos_set_error_msg(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i32 40, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %0)
br label %54
54: ; preds = %52, %49, %27, %6
%55 = phi i8* [ %29, %27 ], [ null, %52 ], [ %51, %49 ], [ null, %6 ]
ret i8* %55
}