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

/* Variables and functions */
size_t ENOENT;
scalar_t__ S_ISREG(int /*<<< orphan*/);
int closedir(int /*<<< orphan*/ *);
size_t errno;
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int stat(char *, struct stat *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ *sys_errlist;
unsigned int sys_nerr;
int /*<<< orphan*/ system_log(char *, char *, int, char *, char *,
                              int /*<<< orphan*/);
void count_files(char *dirname, unsigned int *files, off_t *bytes) {
  DIR *dp;
  *files = 0;
  *bytes = 0;
  if ((dp = opendir(dirname)) == NULL) {
    system_log("<W>",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/hfs/afd/refs/heads/master/"
               "src/init_afd/count_files.c",
               67, ("Can't access directory %s : %s"), dirname,
               sys_errlist[((unsigned)(errno) < sys_nerr) ? (errno) : 0]);
  } else {
    char *ptr, fullname[1024];
    struct stat stat_buf;
    struct dirent *p_dir;
    (void)strcpy(fullname, dirname);
    ptr = fullname + strlen(fullname);
    *ptr++ = '/';
    errno = 0;
    while ((p_dir = readdir(dp)) != NULL) {
      if (p_dir->d_name[0] != '.') {
        (void)strcpy(ptr, p_dir->d_name);
        if (stat(fullname, &stat_buf) == -1) {
          if (errno != ENOENT) {
            system_log(
                "<W>",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/hfs/afd/refs/heads/master/"
                "src/init_afd/count_files.c",
                91, "Can't access file %s : %s", fullname,
                sys_errlist[((unsigned)(errno) < sys_nerr) ? (errno) : 0]);
          }
        } else {
          if (S_ISREG(stat_buf.st_mode)) {
            (*bytes) += stat_buf.st_size;
            (*files)++;
          }
        }
      }
      errno = 0;
    }
    if (errno) {
      system_log("<E>",
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/hfs/afd/refs/heads/master/"
                 "src/init_afd/count_files.c",
                 110, ("Could not readdir() %s : %s"), dirname,
                 sys_errlist[((unsigned)(errno) < sys_nerr) ? (errno) : 0]);
    }
    if (closedir(dp) == -1) {
      system_log("<E>",
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/hfs/afd/refs/heads/master/"
                 "src/init_afd/count_files.c",
                 116, ("Could not closedir() %s : %s"), dirname,
                 sys_errlist[((unsigned)(errno) < sys_nerr) ? (errno) : 0]);
    }
  }
  return;
}


x86 assembly (clang, -O0):
<count_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1259 <count_files+0xd9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x450(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%rax
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%eax
jae    120e <count_files+0x8e>
mov    0x2dd1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x460(%rbp)
jmp    121c <count_files+0x9c>
xor    %eax,%eax
mov    %rax,-0x460(%rbp)
jmp    121c <count_files+0x9c>
mov    -0x458(%rbp),%r8
mov    -0x450(%rbp),%rax
mov    -0x460(%rbp),%rcx
mov    (%rax,%rcx,4),%r9d
lea    0xdc4(%rip),%rdi
lea    0xdc1(%rip),%rsi
mov    $0x43,%edx
lea    0xe44(%rip),%rcx
call   1060 <system_log@plt>
jmp    1560 <count_files+0x3e0>
lea    -0x430(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x430(%rbp),%rax
mov    %rax,-0x468(%rbp)
lea    -0x430(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x468(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x2f,(%rax)
mov    0x2d21(%rip),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x448(%rbp)
cmp    $0x0,%rax
je     1416 <count_files+0x296>
mov    -0x448(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1403 <count_files+0x283>
mov    -0x28(%rbp),%rdi
mov    -0x448(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x430(%rbp),%rdi
lea    -0x440(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    13c8 <count_files+0x248>
mov    0x2cb4(%rip),%rax
mov    (%rax),%rax
mov    0x2c9a(%rip),%rcx
cmp    (%rcx),%rax
je     13c3 <count_files+0x243>
lea    -0x430(%rbp),%rax
mov    %rax,-0x478(%rbp)
mov    0x2cb4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x470(%rbp)
mov    0x2c7b(%rip),%rax
mov    (%rax),%rax
mov    0x2c89(%rip),%rcx
cmp    (%rcx),%eax
jae    137d <count_files+0x1fd>
mov    0x2c62(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x480(%rbp)
jmp    138b <count_files+0x20b>
xor    %eax,%eax
mov    %rax,-0x480(%rbp)
jmp    138b <count_files+0x20b>
mov    -0x478(%rbp),%r8
mov    -0x470(%rbp),%rax
mov    -0x480(%rbp),%rcx
mov    (%rax,%rcx,4),%r9d
lea    0xc55(%rip),%rdi
lea    0xc52(%rip),%rsi
mov    $0x5b,%edx
lea    0xcf4(%rip),%rcx
call   1060 <system_log@plt>
jmp    13fe <count_files+0x27e>
mov    -0x438(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     13f9 <count_files+0x279>
mov    -0x440(%rbp),%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    13fe <count_files+0x27e>
jmp    1403 <count_files+0x283>
mov    0x2bc6(%rip),%rax
movq   $0x0,(%rax)
jmp    12b6 <count_files+0x136>
mov    0x2bb3(%rip),%rax
cmpq   $0x0,(%rax)
je     14b8 <count_files+0x338>
mov    -0x8(%rbp),%rax
mov    %rax,-0x490(%rbp)
mov    0x2bbf(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x488(%rbp)
mov    0x2b86(%rip),%rax
mov    (%rax),%rax
mov    0x2b94(%rip),%rcx
cmp    (%rcx),%eax
jae    1472 <count_files+0x2f2>
mov    0x2b6d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x498(%rbp)
jmp    1480 <count_files+0x300>
xor    %eax,%eax
mov    %rax,-0x498(%rbp)
jmp    1480 <count_files+0x300>
mov    -0x490(%rbp),%r8
mov    -0x488(%rbp),%rax
mov    -0x498(%rbp),%rcx
mov    (%rax,%rcx,4),%r9d
lea    0xc2c(%rip),%rdi
lea    0xb5d(%rip),%rsi
mov    $0x6e,%edx
lea    0xc1d(%rip),%rcx
call   1060 <system_log@plt>
mov    -0x20(%rbp),%rdi
call   1070 <closedir@plt>
cmp    $0xffffffff,%eax
jne    155b <count_files+0x3db>
mov    -0x8(%rbp),%rax
mov    %rax,-0x4a8(%rbp)
mov    0x2b1c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x4a0(%rbp)
mov    0x2ae3(%rip),%rax
mov    (%rax),%rax
mov    0x2af1(%rip),%rcx
cmp    (%rcx),%eax
jae    1515 <count_files+0x395>
mov    0x2aca(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x4b0(%rbp)
jmp    1523 <count_files+0x3a3>
xor    %eax,%eax
mov    %rax,-0x4b0(%rbp)
jmp    1523 <count_files+0x3a3>
mov    -0x4a8(%rbp),%r8
mov    -0x4a0(%rbp),%rax
mov    -0x4b0(%rbp),%rcx
mov    (%rax,%rcx,4),%r9d
lea    0xb89(%rip),%rdi
lea    0xaba(%rip),%rsi
mov    $0x74,%edx
lea    0xb96(%rip),%rcx
call   1060 <system_log@plt>
jmp    1560 <count_files+0x3e0>
add    $0x4b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rsi,%r12
mov    %rdi,%rbp
movl   $0x0,(%rsi)
mov    %rdx,0x8(%rsp)
movq   $0x0,(%rdx)
call   1040 <opendir@plt>
test   %rax,%rax
je     137c <count_files+0x1fc>
mov    %rax,%rbx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %rbp,(%rsp)
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbp
movb   $0x2f,0x20(%rsp,%rbp,1)
mov    0x2deb(%rip),%r15
movq   $0x0,(%r15)
mov    %rbx,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12d0 <count_files+0x150>
lea    (%rsp,%rbp,1),%r13
add    $0x21,%r13
lea    0x20(%rsp),%rbp
lea    0x10(%rsp),%r14
jmp    1238 <count_files+0xb8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movq   $0x0,(%r15)
mov    %rbx,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12d0 <count_files+0x150>
mov    (%rax),%rsi
cmpb   $0x2e,(%rsi)
je     1220 <count_files+0xa0>
mov    %r13,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
je     127a <count_files+0xfa>
mov    0x18(%rsp),%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
je     1220 <count_files+0xa0>
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
add    %rax,(%rcx)
addl   $0x1,(%r12)
jmp    1220 <count_files+0xa0>
mov    (%r15),%rax
mov    0x2d3c(%rip),%rcx
cmp    (%rcx),%rax
je     1220 <count_files+0xa0>
mov    0x2d68(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2d4e(%rip),%rdx
cmp    %eax,(%rdx)
mov    $0x0,%edx
cmovbe %rdx,%rax
mov    (%rcx,%rax,4),%r9d
lea    0xd50(%rip),%rdi
lea    0xd4d(%rip),%rsi
mov    $0x5b,%edx
lea    0xdef(%rip),%rcx
mov    %rbp,%r8
call   1060 <system_log@plt>
jmp    1220 <count_files+0xa0>
mov    (%r15),%rax
test   %rax,%rax
mov    (%rsp),%rbp
je     131b <count_files+0x19b>
mov    0x2d15(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2cfb(%rip),%rdx
xor    %esi,%esi
cmp    %eax,(%rdx)
cmova  %rax,%rsi
mov    (%rcx,%rsi,4),%r9d
lea    0xdcc(%rip),%rdi
lea    0xcfd(%rip),%rsi
lea    0xdc2(%rip),%rcx
mov    $0x6e,%edx
mov    %rbp,%r8
call   1060 <system_log@plt>
mov    %rbx,%rdi
call   1070 <closedir@plt>
cmp    $0xffffffff,%eax
jne    136a <count_files+0x1ea>
mov    0x2cc9(%rip),%rax
mov    (%rax),%rax
mov    (%r15),%rcx
mov    0x2cac(%rip),%rdx
xor    %esi,%esi
cmp    %ecx,(%rdx)
cmova  %rcx,%rsi
mov    (%rax,%rsi,4),%r9d
lea    0xd7d(%rip),%rdi
lea    0xcae(%rip),%rsi
lea    0xd8f(%rip),%rcx
mov    $0x74,%edx
mov    %rbp,%r8
call   1060 <system_log@plt>
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c75(%rip),%rax
mov    (%rax),%rax
mov    0x2c43(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2c51(%rip),%rdx
xor    %esi,%esi
cmp    %ecx,(%rdx)
cmova  %rcx,%rsi
mov    (%rax,%rsi,4),%r9d
lea    0xc56(%rip),%rdi
lea    0xc53(%rip),%rsi
lea    0xcdb(%rip),%rcx
mov    $0x43,%edx
mov    %rbp,%r8
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <system_log@plt>

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
%struct.dirent = type { i8* }
@.str = [4 x i8] c"<W>\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/hfs/afd/refs/heads/master/src/init_afd/count_files.c\00"
@.str.2 = [31 x i8] c"Can't access directory %s : %s\00"
@sys_errlist = global i32* null
@errno = global i64 0
@sys_nerr = global i32 0
@ENOENT = global i64 0
@.str.3 = [26 x i8] c"Can't access file %s : %s\00"
@.str.4 = [4 x i8] c"<E>\00"
@.str.5 = [28 x i8] c"Could not readdir() %s : %s\00"
@.str.6 = [29 x i8] c"Could not closedir() %s : %s\00"
define void @count_files(i8* %0, i32* %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca [1024 x i8]
%10 = alloca %struct.stat
%11 = alloca %struct.dirent*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i64* %2, i64** %6
%12 = load i32*, i32** %5
store i32 0, i32* %12
%13 = load i64*, i64** %6
store i64 0, i64* %13
%14 = load i8*, i8** %4
%15 = call i32* @opendir(i8* %14)
store i32* %15, i32** %7
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %32
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = load i32*, i32** @sys_errlist
%20 = load i64, i64* @errno
%21 = trunc i64 %20 to i32
%22 = load i32, i32* @sys_nerr
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = load i64, i64* @errno
br label %27
26: ; preds = %17
br label %27
27: ; preds = %26, %24
%28 = phi i64 [ %25, %24 ], [ 0, %26 ]
%29 = getelementptr inbounds i32, i32* %19, i64 %28
%30 = load i32, i32* %29
%31 = call i32 @system_log(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 67, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %18, i32 %30)
br label %139
32: ; preds = %3
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%34 = load i8*, i8** %4
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8* %40, i8** %8
%41 = load i8*, i8** %8
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %8
store i8 47, i8* %41
store i64 0, i64* @errno
br label %43
43: ; preds = %100, %32
%44 = load i32*, i32** %7
%45 = call %struct.dirent* @readdir(i32* %44)
store %struct.dirent* %45, %struct.dirent** %11
%46 = icmp ne %struct.dirent* %45, null
br i1 %46, label %47, label %101
47: ; preds = %43
%48 = load %struct.dirent*, %struct.dirent** %11
%49 = getelementptr inbounds %struct.dirent, %struct.dirent* %48, i32 0, i32 0
%50 = load i8*, i8** %49
%51 = getelementptr inbounds i8, i8* %50, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 46
br i1 %54, label %55, label %100
55: ; preds = %47
%56 = load i8*, i8** %8
%57 = load %struct.dirent*, %struct.dirent** %11
%58 = getelementptr inbounds %struct.dirent, %struct.dirent* %57, i32 0, i32 0
%59 = load i8*, i8** %58
%60 = call i32 @strcpy(i8* %56, i8* %59)
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%62 = call i32 @stat(i8* %61, %struct.stat* %10)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %84
64: ; preds = %55
%65 = load i64, i64* @errno
%66 = load i64, i64* @ENOENT
%67 = icmp ne i64 %65, %66
br i1 %67, label %68, label %83
68: ; preds = %64
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%70 = load i32*, i32** @sys_errlist
%71 = load i64, i64* @errno
%72 = trunc i64 %71 to i32
%73 = load i32, i32* @sys_nerr
%74 = icmp ult i32 %72, %73
br i1 %74, label %75, label %77
75: ; preds = %68
%76 = load i64, i64* @errno
br label %78
77: ; preds = %68
br label %78
78: ; preds = %77, %75
%79 = phi i64 [ %76, %75 ], [ 0, %77 ]
%80 = getelementptr inbounds i32, i32* %70, i64 %79
%81 = load i32, i32* %80
%82 = call i32 @system_log(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 91, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %69, i32 %81)
br label %83
83: ; preds = %78, %64
br label %99
84: ; preds = %55
%85 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%86 = load i32, i32* %85
%87 = call i64 @S_ISREG(i32 %86)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %98
89: ; preds = %84
%90 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%91 = load i64, i64* %90
%92 = load i64*, i64** %6
%93 = load i64, i64* %92
%94 = add nsw i64 %93, %91
store i64 %94, i64* %92
%95 = load i32*, i32** %5
%96 = load i32, i32* %95
%97 = add i32 %96, 1
store i32 %97, i32* %95
br label %98
98: ; preds = %89, %84
br label %99
99: ; preds = %98, %83
br label %100
100: ; preds = %99, %47
store i64 0, i64* @errno
br label %43
101: ; preds = %43
%102 = load i64, i64* @errno
%103 = icmp ne i64 %102, 0
br i1 %103, label %104, label %119
104: ; preds = %101
%105 = load i8*, i8** %4
%106 = load i32*, i32** @sys_errlist
%107 = load i64, i64* @errno
%108 = trunc i64 %107 to i32
%109 = load i32, i32* @sys_nerr
%110 = icmp ult i32 %108, %109
br i1 %110, label %111, label %113
111: ; preds = %104
%112 = load i64, i64* @errno
br label %114
113: ; preds = %104
br label %114
114: ; preds = %113, %111
%115 = phi i64 [ %112, %111 ], [ 0, %113 ]
%116 = getelementptr inbounds i32, i32* %106, i64 %115
%117 = load i32, i32* %116
%118 = call i32 @system_log(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 110, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %105, i32 %117)
br label %119
119: ; preds = %114, %101
%120 = load i32*, i32** %7
%121 = call i32 @closedir(i32* %120)
%122 = icmp eq i32 %121, -1
br i1 %122, label %123, label %138
123: ; preds = %119
%124 = load i8*, i8** %4
%125 = load i32*, i32** @sys_errlist
%126 = load i64, i64* @errno
%127 = trunc i64 %126 to i32
%128 = load i32, i32* @sys_nerr
%129 = icmp ult i32 %127, %128
br i1 %129, label %130, label %132
130: ; preds = %123
%131 = load i64, i64* @errno
br label %133
132: ; preds = %123
br label %133
133: ; preds = %132, %130
%134 = phi i64 [ %131, %130 ], [ 0, %132 ]
%135 = getelementptr inbounds i32, i32* %125, i64 %134
%136 = load i32, i32* %135
%137 = call i32 @system_log(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 116, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %124, i32 %136)
br label %138
138: ; preds = %133, %119
br label %139
139: ; preds = %138, %27
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
%struct.dirent = type { i8* }
@.str = [4 x i8] c"<W>\00"
@.str.1 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/hfs/afd/refs/heads/master/src/init_afd/count_files.c\00"
@.str.2 = [31 x i8] c"Can't access directory %s : %s\00"
@sys_errlist = global i32* null
@errno = global i64 0
@sys_nerr = global i32 0
@ENOENT = global i64 0
@.str.3 = [26 x i8] c"Can't access file %s : %s\00"
@.str.4 = [4 x i8] c"<E>\00"
@.str.5 = [28 x i8] c"Could not readdir() %s : %s\00"
@.str.6 = [29 x i8] c"Could not closedir() %s : %s\00"
define void @count_files(i8* %0, i32* nocapture %1, i64* nocapture %2) {
%4 = alloca [1024 x i8]
%5 = alloca %struct.stat
store i32 0, i32* %1
store i64 0, i64* %2
%6 = tail call i32* @opendir(i8* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %18
8: ; preds = %3
%9 = load i32*, i32** @sys_errlist
%10 = load i64, i64* @errno
%11 = trunc i64 %10 to i32
%12 = load i32, i32* @sys_nerr
%13 = icmp ugt i32 %12, %11
%14 = select i1 %13, i64 %10, i64 0
%15 = getelementptr inbounds i32, i32* %9, i64 %14
%16 = load i32, i32* %15
%17 = tail call i32 @system_log(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 67, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %16)
br label %93
18: ; preds = %3
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%20 = bitcast %struct.stat* %5 to i8*
%21 = call i32 @strcpy(i8* %19, i8* %0)
%22 = call i32 @strlen(i8* %19)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 47, i8* %24
store i64 0, i64* @errno
%26 = call %struct.dirent* @readdir(i32* %6)
%27 = icmp eq %struct.dirent* %26, null
br i1 %27, label %67, label %28
28: ; preds = %18
%29 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 1
%30 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
br label %31
31: ; preds = %28, %64
%32 = phi %struct.dirent* [ %26, %28 ], [ %65, %64 ]
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i64 0, i32 0
%34 = load i8*, i8** %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 46
br i1 %36, label %64, label %37
37: ; preds = %31
%38 = call i32 @strcpy(i8* %25, i8* %34)
%39 = call i32 @stat(i8* %19, %struct.stat* %5)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %54
41: ; preds = %37
%42 = load i64, i64* @errno
%43 = load i64, i64* @ENOENT
%44 = icmp eq i64 %42, %43
br i1 %44, label %64, label %45
45: ; preds = %41
%46 = load i32*, i32** @sys_errlist
%47 = trunc i64 %42 to i32
%48 = load i32, i32* @sys_nerr
%49 = icmp ugt i32 %48, %47
%50 = select i1 %49, i64 %42, i64 0
%51 = getelementptr inbounds i32, i32* %46, i64 %50
%52 = load i32, i32* %51
%53 = call i32 @system_log(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 91, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %19, i32 %52)
br label %64
54: ; preds = %37
%55 = load i32, i32* %29
%56 = call i64 @S_ISREG(i32 %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %64, label %58
58: ; preds = %54
%59 = load i64, i64* %30
%60 = load i64, i64* %2
%61 = add nsw i64 %60, %59
store i64 %61, i64* %2
%62 = load i32, i32* %1
%63 = add i32 %62, 1
store i32 %63, i32* %1
br label %64
64: ; preds = %45, %41, %58, %54, %31
store i64 0, i64* @errno
%65 = call %struct.dirent* @readdir(i32* %6)
%66 = icmp eq %struct.dirent* %65, null
br i1 %66, label %67, label %31
67: ; preds = %64, %18
%68 = load i64, i64* @errno
%69 = icmp eq i64 %68, 0
br i1 %69, label %79, label %70
70: ; preds = %67
%71 = load i32*, i32** @sys_errlist
%72 = trunc i64 %68 to i32
%73 = load i32, i32* @sys_nerr
%74 = icmp ugt i32 %73, %72
%75 = select i1 %74, i64 %68, i64 0
%76 = getelementptr inbounds i32, i32* %71, i64 %75
%77 = load i32, i32* %76
%78 = call i32 @system_log(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 110, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %0, i32 %77)
br label %79
79: ; preds = %70, %67
%80 = call i32 @closedir(i32* %6)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %92
82: ; preds = %79
%83 = load i32*, i32** @sys_errlist
%84 = load i64, i64* @errno
%85 = trunc i64 %84 to i32
%86 = load i32, i32* @sys_nerr
%87 = icmp ugt i32 %86, %85
%88 = select i1 %87, i64 %84, i64 0
%89 = getelementptr inbounds i32, i32* %83, i64 %88
%90 = load i32, i32* %89
%91 = call i32 @system_log(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.1, i64 0, i64 0), i32 116, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %0, i32 %90)
br label %92
92: ; preds = %82, %79
br label %93
93: ; preds = %92, %8
ret void
}