#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 */
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strerror(scalar_t__);
char *strrchr(char *, char);
int resource_get_list(DIR *dirp, char list[][255 + 1], char *path_com,
                      char *type) {
  struct dirent *direntp;
  int list_len;
  char *p;
  errno = 0;
  list_len = 0;
  while ((direntp = readdir(dirp)) != NULL) {
    p = strrchr(direntp->d_name, '.') + 1;
    if (p != NULL) {
      if (strcmp(p, type) == 0) {
        memset(list[list_len], 0, 255 + 1);
        snprintf(list[list_len++], 255, "%s/%s", path_com, direntp->d_name);
      }
    }
  }
  if (errno != 0) {
    fprintf(stderr, "%s:%d: readdir failed: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/Airead/digit-box/refs/heads/master/"
            "resource.c",
            88, strerror(errno));
    return -1;
  }
  return list_len;
}


x86 assembly (clang, -O0):
<resource_get_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2e49(%rip),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1248 <resource_get_list+0xd8>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1243 <resource_get_list+0xd3>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    123e <resource_get_list+0xce>
mov    -0x18(%rbp),%rdi
movslq -0x34(%rbp),%rax
shl    $0x8,%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x34(%rbp)
cltq
shl    $0x8,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    (%rax),%r8
mov    $0xff,%esi
lea    0xdc7(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1243 <resource_get_list+0xd3>
jmp    119d <resource_get_list+0x2d>
mov    0x2d89(%rip),%rax
cmpq   $0x0,(%rax)
je     129e <resource_get_list+0x12e>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%r8
lea    0xd85(%rip),%rsi
lea    0xd99(%rip),%rdx
mov    $0x58,%ecx
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a4 <resource_get_list+0x134>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resource_get_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,(%rsp)
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x2e49(%rip),%rax
movq   $0x0,(%rax)
call   1080 <readdir@plt>
test   %rax,%rax
je     121d <resource_get_list+0xad>
mov    %rax,%rbp
xor    %r14d,%r14d
jmp    11c0 <resource_get_list+0x50>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1220 <resource_get_list+0xb0>
mov    0x0(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11b0 <resource_get_list+0x40>
movslq %r14d,%r14
mov    %r14,%rbx
shl    $0x8,%rbx
add    %r12,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
add    $0x1,%r14d
mov    0x0(%rbp),%r8
mov    %rbx,%rdi
mov    $0xff,%esi
lea    0xdee(%rip),%rdx
mov    (%rsp),%rcx
call   1030 <snprintf@plt>
jmp    11b0 <resource_get_list+0x40>
xor    %r14d,%r14d
mov    0x2db1(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     1260 <resource_get_list+0xf0>
mov    0x2daa(%rip),%rax
mov    (%rax),%ebx
call   1090 <strerror@plt>
lea    0xdc2(%rip),%rsi
lea    0xdd6(%rip),%rdx
mov    %ebx,%edi
mov    $0x58,%ecx
mov    %rax,%r8
call   1070 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@errno = global i64 0
@.str = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"%s:%d: readdir failed: %s\0A\00"
@.str.2 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Airead/digit-box/refs/heads/master/resource.c\00"
define i32 @resource_get_list(i32* %0, [256 x i8]* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [256 x i8]*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.dirent*
%11 = alloca i32
%12 = alloca i8*
store i32* %0, i32** %6
store [256 x i8]* %1, [256 x i8]** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i64 0, i64* @errno
store i32 0, i32* %11
br label %13
13: ; preds = %49, %4
%14 = load i32*, i32** %6
%15 = call %struct.dirent* @readdir(i32* %14)
store %struct.dirent* %15, %struct.dirent** %10
%16 = icmp ne %struct.dirent* %15, null
br i1 %16, label %17, label %50
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %10
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i8* @strrchr(i8* %20, i8 signext 46)
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %12
%23 = load i8*, i8** %12
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %49
25: ; preds = %17
%26 = load i8*, i8** %12
%27 = load i8*, i8** %9
%28 = call i64 @strcmp(i8* %26, i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %48
30: ; preds = %25
%31 = load [256 x i8]*, [256 x i8]** %7
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %31, i64 %33
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %34, i64 0, i64 0
%36 = call i32 @memset(i8* %35, i32 0, i32 256)
%37 = load [256 x i8]*, [256 x i8]** %7
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
store i32 %39, i32* %11
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %37, i64 %40
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %41, i64 0, i64 0
%43 = load i8*, i8** %8
%44 = load %struct.dirent*, %struct.dirent** %10
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = call i32 @snprintf(i8* %42, i32 255, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %43, i8* %46)
br label %48
48: ; preds = %30, %25
br label %49
49: ; preds = %48, %17
br label %13
50: ; preds = %13
%51 = load i64, i64* @errno
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = load i64, i64* @errno
%56 = call i8* @strerror(i64 %55)
%57 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 88, i8* %56)
store i32 -1, i32* %5
br label %60
58: ; preds = %50
%59 = load i32, i32* %11
store i32 %59, i32* %5
br label %60
60: ; preds = %58, %53
%61 = load i32, i32* %5
ret i32 %61
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@errno = global i64 0
@.str = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"%s:%d: readdir failed: %s\0A\00"
@.str.2 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Airead/digit-box/refs/heads/master/resource.c\00"
define i32 @resource_get_list(i32* %0, [256 x i8]* %1, i8* %2, i8* %3) {
store i64 0, i64* @errno
%5 = tail call %struct.dirent* @readdir(i32* %0)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %27, label %7
7: ; preds = %4, %23
%8 = phi %struct.dirent* [ %25, %23 ], [ %5, %4 ]
%9 = phi i32 [ %24, %23 ], [ 0, %4 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = tail call i8* @strrchr(i8* dereferenceable(1) %11, i8 signext 46)
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = tail call i64 @strcmp(i8* %13, i8* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %7
%17 = sext i32 %9 to i64
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 %17, i64 0
%19 = tail call i32 @memset(i8* %18, i32 0, i32 256)
%20 = add nsw i32 %9, 1
%21 = load i8*, i8** %10
%22 = tail call i32 @snprintf(i8* %18, i32 255, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %21)
br label %23
23: ; preds = %7, %16
%24 = phi i32 [ %20, %16 ], [ %9, %7 ]
%25 = tail call %struct.dirent* @readdir(i32* %0)
%26 = icmp eq %struct.dirent* %25, null
br i1 %26, label %27, label %7
27: ; preds = %23, %4
%28 = phi i32 [ 0, %4 ], [ %24, %23 ]
%29 = load i64, i64* @errno
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = tail call i8* @strerror(i64 %29)
%34 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 88, i8* %33)
br label %35
35: ; preds = %27, %31
%36 = phi i32 [ -1, %31 ], [ %28, %27 ]
ret i32 %36
}