#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*/ path_com;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *opendir(char *);
int resource_get_list(int /*<<< orphan*/ *, char **, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int resource_common_list(char *usbpath, char list[][255 + 1], char *type) {
  DIR *dirp;
  char path_com[255 + 1];
  char *root;
  int list_len;
  root = "digitbox";
  memset(path_com, 0, sizeof(path_com));
  snprintf(path_com, sizeof(path_com) - 1, "%s/%s/%s", usbpath, root, type);
  if ((dirp = opendir(path_com)) == NULL) {
    fprintf(stderr, "%s:%d: opendir %s 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",
            46, path_com, strerror(errno));
    return -1;
  }
  list_len = resource_get_list(dirp, list, path_com, type);
  closedir(dirp);
  return list_len;
}


x86 assembly (clang, -O0):
<resource_common_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xe72(%rip),%rax
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x138(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    $0xff,%esi
lea    0xe3f(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x130(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1248 <resource_common_list+0xd8>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14c(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x14c(%rbp),%edi
mov    -0x148(%rbp),%r8
mov    %rax,%r9
lea    0xde7(%rip),%rsi
lea    0xdfe(%rip),%rdx
mov    $0x2e,%ecx
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1278 <resource_common_list+0x108>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x130(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1080 <resource_get_list@plt>
mov    %eax,-0x13c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x13c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resource_common_list>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    0xe6a(%rip),%rdx
lea    0xe5a(%rip),%r8
mov    %rbp,%rdi
mov    $0xff,%esi
mov    %rbx,%rcx
mov    %r15,%r9
call   1040 <snprintf@plt>
mov    %rbp,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11e6 <resource_common_list+0x76>
mov    %rax,%rbx
mov    %rsp,%rdx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rcx
call   1080 <resource_get_list@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <closedir@plt>
jmp    1222 <resource_common_list+0xb2>
mov    0x2df3(%rip),%rax
mov    (%rax),%ebx
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe0e(%rip),%rsi
lea    0xe25(%rip),%rdx
mov    %rsp,%r8
mov    %ebx,%edi
mov    $0x2e,%ecx
mov    %rax,%r9
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"digitbox\00"
@.str.1 = [9 x i8] c"%s/%s/%s\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"%s:%d: opendir %s failed: %s\0A\00"
@.str.3 = [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"
@errno = global i32 0
define i32 @resource_common_list(i8* %0, [256 x i8]* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [256 x i8]*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca [256 x i8]
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store [256 x i8]* %1, [256 x i8]** %6
store i8* %2, i8** %7
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %10
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 256)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = load i8*, i8** %10
%17 = load i8*, i8** %7
%18 = call i32 @snprintf(i8* %14, i32 255, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16, i8* %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%20 = call i32* @opendir(i8* %19)
store i32* %20, i32** %8
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %28
22: ; preds = %3
%23 = load i32, i32* @stderr
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.3, i64 0, i64 0), i32 46, i8* %24, i8* %26)
store i32 -1, i32* %4
br label %38
28: ; preds = %3
%29 = load i32*, i32** %8
%30 = load [256 x i8]*, [256 x i8]** %6
%31 = bitcast [256 x i8]* %30 to i8**
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%33 = load i8*, i8** %7
%34 = call i32 @resource_get_list(i32* %29, i8** %31, i8* %32, i8* %33)
store i32 %34, i32* %11
%35 = load i32*, i32** %8
%36 = call i32 @closedir(i32* %35)
%37 = load i32, i32* %11
store i32 %37, i32* %4
br label %38
38: ; preds = %28, %22
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [9 x i8] c"digitbox\00"
@.str.1 = [9 x i8] c"%s/%s/%s\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"%s:%d: opendir %s failed: %s\0A\00"
@.str.3 = [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"
@errno = global i32 0
define i32 @resource_common_list(i8* %0, [256 x i8]* %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 256)
%7 = call i32 @snprintf(i8* %5, i32 255, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %2)
%8 = call i32* @opendir(i8* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.3, i64 0, i64 0), i32 46, i8* %5, i8* %13)
br label %19
15: ; preds = %3
%16 = bitcast [256 x i8]* %1 to i8**
%17 = call i32 @resource_get_list(i32* %8, i8** %16, i8* %5, i8* %2)
%18 = call i32 @closedir(i32* %8)
br label %19
19: ; preds = %15, %10
%20 = phi i32 [ -1, %10 ], [ %17, %15 ]
ret i32 %20
}