#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 {
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ label_file;
typedef int /*<<< orphan*/ input_line;
typedef int /*<<< orphan*/ err;
typedef int /*<<< orphan*/ base_file;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ abort();
int /*<<< orphan*/ add_error_msg(char *);
int atoi(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int strnlen(char *, int);
int get_xio_base(void) {
  char label_file[128];
  FILE *label_fp;
  char base_file[128];
  FILE *base_fp;
  static int xio_base_address = -1;
  DIR *dir;
  struct dirent *ent;
  struct stat sbuf;
  if (xio_base_address != -1)
    return xio_base_address;
  dir = opendir("/sys/class/gpio");
  if (dir == NULL) {
    char err[256];
    snprintf(err, sizeof(err), "get_xio_base: could not open '%s' (%s)",
             "/sys/class/gpio", strerror(errno));
    add_error_msg(err);
    return -1;
  }
  while (xio_base_address == -1 && (ent = readdir(dir)) != NULL) {
    lstat(ent->d_name, &sbuf);
    if (S_ISDIR(sbuf.st_mode)) {
      if (strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0) {
        continue;
      }
      snprintf(label_file, sizeof(label_file), "%s/%s/label", "/sys/class/gpio",
               ent->d_name);
      do {
        do {
          if (!(strnlen(label_file, sizeof(label_file)) <
                sizeof(label_file) - 1)) {
            fprintf(stderr, "ASSRT failed at %s:%d (%s)\n",
                    "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/xtacocorex/CHIP_IO/refs/"
                    "heads/master/source/common.c",
                    194,
                    "strnlen(label_file, sizeof(label_file)) < "
                    "sizeof(label_file)-1");
            fflush(stderr);
            abort();
          }
        } while (0);
      } while (0);
      label_fp = fopen(label_file, "r");
      if (label_fp != NULL) {
        char input_line[80];
        input_line[0] = '\0';
        char *s = fgets(input_line, sizeof(input_line), label_fp);
        do {
          do {
            if (!(strnlen(input_line, sizeof(input_line)) <
                  sizeof(input_line) - 1)) {
              fprintf(stderr, "ASSRT failed at %s:%d (%s)\n",
                      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/xtacocorex/CHIP_IO/"
                      "refs/heads/master/source/common.c",
                      198,
                      "strnlen(input_line, sizeof(input_line)) < "
                      "sizeof(input_line)-1");
              fflush(stderr);
              abort();
            }
          } while (0);
        } while (0);
        fclose(label_fp);
        if (s != NULL && strcmp(input_line, "pcf8574a\n") == 0) {
          snprintf(base_file, sizeof(base_file), "%s/%s/base",
                   "/sys/class/gpio", ent->d_name);
          do {
            do {
              if (!(strnlen(base_file, sizeof(base_file)) <
                    sizeof(base_file) - 1)) {
                fprintf(stderr, "ASSRT failed at %s:%d (%s)\n",
                        "/scratch/repos/new/home/jordi_armengol_estape/"
                        "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                        "xtacocorex/CHIP_IO/refs/heads/master/source/common.c",
                        202,
                        "strnlen(base_file, sizeof(base_file)) < "
                        "sizeof(base_file)-1");
                fflush(stderr);
                abort();
              }
            } while (0);
          } while (0);
          base_fp = fopen(base_file, "r");
          if (base_fp == NULL) {
            char err[256];
            snprintf(err, sizeof(err), "get_xio_base: could not open '%s' (%s)",
                     base_file, strerror(errno));
            add_error_msg(err);
            break;
          }
          s = fgets(input_line, sizeof(input_line), base_fp);
          do {
            do {
              if (!(strnlen(input_line, sizeof(input_line)) <
                    sizeof(input_line) - 1)) {
                fprintf(stderr, "ASSRT failed at %s:%d (%s)\n",
                        "/scratch/repos/new/home/jordi_armengol_estape/"
                        "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                        "xtacocorex/CHIP_IO/refs/heads/master/source/common.c",
                        210,
                        "strnlen(input_line, sizeof(input_line)) < "
                        "sizeof(input_line)-1");
                fflush(stderr);
                abort();
              }
            } while (0);
          } while (0);
          fclose(base_fp);
          if (s == NULL) {
            char err[256];
            snprintf(err, sizeof(err), "get_xio_base: could not read '%s' (%s)",
                     base_file, strerror(errno));
            add_error_msg(err);
            break;
          }
          xio_base_address = atoi(input_line);
        }
      }
    }
  }
  closedir(dir);
  return xio_base_address;
}


x86 assembly (clang, -O0):
<get_xio_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4d0,%rsp
cmpl   $0xffffffff,0x2e86(%rip)
je     1236 <get_xio_base+0x26>
mov    0x2e7a(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    1736 <get_xio_base+0x526>
lea    0xdc3(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    12ad <get_xio_base+0x9d>
lea    -0x240(%rbp),%rax
mov    %rax,-0x4a8(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x4a8(%rbp),%rdi
mov    %rax,%r8
mov    $0x100,%esi
lea    0xd87(%rip),%rdx
lea    0xd70(%rip),%rcx
call   1070 <snprintf@plt>
lea    -0x240(%rbp),%rdi
call   10f0 <add_error_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1736 <get_xio_base+0x526>
jmp    12b2 <get_xio_base+0xa2>
xor    %eax,%eax
cmpl   $0xffffffff,0x2ded(%rip)
mov    %al,-0x4a9(%rbp)
jne    12e7 <get_xio_base+0xd7>
mov    -0x130(%rbp),%rdi
call   10e0 <readdir@plt>
mov    %rax,-0x138(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x4a9(%rbp)
mov    -0x4a9(%rbp),%al
test   $0x1,%al
jne    12fa <get_xio_base+0xea>
jmp    1721 <get_xio_base+0x511>
mov    -0x138(%rbp),%rax
mov    (%rax),%rdi
lea    -0x140(%rbp),%rsi
call   10a0 <lstat@plt>
mov    -0x140(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     171c <get_xio_base+0x50c>
mov    -0x138(%rbp),%rax
mov    (%rax),%rsi
lea    0xd02(%rip),%rdi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
je     1365 <get_xio_base+0x155>
mov    -0x138(%rbp),%rax
mov    (%rax),%rsi
lea    0xce1(%rip),%rdi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    136a <get_xio_base+0x15a>
jmp    12b2 <get_xio_base+0xa2>
lea    -0x90(%rbp),%rdi
mov    -0x138(%rbp),%rax
mov    (%rax),%r8
mov    $0x80,%esi
lea    0xcb3(%rip),%rdx
lea    0xc72(%rip),%rcx
call   1070 <snprintf@plt>
jmp    1398 <get_xio_base+0x188>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1080 <strnlen@plt>
cltq
cmp    $0x7f,%rax
jb     13f2 <get_xio_base+0x1e2>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
lea    0xc81(%rip),%rsi
lea    0xc96(%rip),%rdx
mov    $0xc2,%ecx
lea    0xd19(%rip),%r8
call   10d0 <fprintf@plt>
mov    0x2bfc(%rip),%rax
mov    (%rax),%edi
call   1100 <fflush@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    13f7 <get_xio_base+0x1e7>
jmp    13fc <get_xio_base+0x1ec>
lea    -0x90(%rbp),%rdi
lea    0xd26(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
je     1717 <get_xio_base+0x507>
movb   $0x0,-0x290(%rbp)
lea    -0x290(%rbp),%rdi
mov    -0x98(%rbp),%rdx
mov    $0x50,%esi
call   10b0 <fgets@plt>
mov    %rax,-0x298(%rbp)
jmp    144f <get_xio_base+0x23f>
lea    -0x290(%rbp),%rdi
mov    $0x50,%esi
call   1080 <strnlen@plt>
cltq
cmp    $0x4f,%rax
jb     14a9 <get_xio_base+0x299>
mov    0x2b6d(%rip),%rax
mov    (%rax),%edi
lea    0xbca(%rip),%rsi
lea    0xbdf(%rip),%rdx
mov    $0xc6,%ecx
lea    0xca3(%rip),%r8
call   10d0 <fprintf@plt>
mov    0x2b45(%rip),%rax
mov    (%rax),%edi
call   1100 <fflush@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    14ae <get_xio_base+0x29e>
jmp    14b3 <get_xio_base+0x2a3>
mov    -0x98(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x298(%rbp)
je     1712 <get_xio_base+0x502>
lea    -0x290(%rbp),%rdi
lea    0xc96(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1712 <get_xio_base+0x502>
lea    -0x120(%rbp),%rdi
mov    -0x138(%rbp),%rax
mov    (%rax),%r8
mov    $0x80,%esi
lea    0xc74(%rip),%rdx
lea    0xaf2(%rip),%rcx
call   1070 <snprintf@plt>
jmp    1518 <get_xio_base+0x308>
lea    -0x120(%rbp),%rdi
mov    $0x80,%esi
call   1080 <strnlen@plt>
cltq
cmp    $0x7f,%rax
jb     1572 <get_xio_base+0x362>
mov    0x2aa4(%rip),%rax
mov    (%rax),%edi
lea    0xb01(%rip),%rsi
lea    0xb16(%rip),%rdx
mov    $0xca,%ecx
lea    0xc2e(%rip),%r8
call   10d0 <fprintf@plt>
mov    0x2a7c(%rip),%rax
mov    (%rax),%edi
call   1100 <fflush@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1577 <get_xio_base+0x367>
jmp    157c <get_xio_base+0x36c>
lea    -0x120(%rbp),%rdi
lea    0xba6(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    1601 <get_xio_base+0x3f1>
lea    -0x3a0(%rbp),%rax
mov    %rax,-0x4c0(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x4b8(%rbp)
mov    0x2a11(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x4c0(%rbp),%rdi
mov    -0x4b8(%rbp),%rcx
mov    %rax,%r8
mov    $0x100,%esi
lea    0xa25(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x3a0(%rbp),%rdi
call   10f0 <add_error_msg@plt>
jmp    1721 <get_xio_base+0x511>
lea    -0x290(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x50,%esi
call   10b0 <fgets@plt>
mov    %rax,-0x298(%rbp)
jmp    1625 <get_xio_base+0x415>
lea    -0x290(%rbp),%rdi
mov    $0x50,%esi
call   1080 <strnlen@plt>
cltq
cmp    $0x4f,%rax
jb     167f <get_xio_base+0x46f>
mov    0x2997(%rip),%rax
mov    (%rax),%edi
lea    0x9f4(%rip),%rsi
lea    0xa09(%rip),%rdx
mov    $0xd2,%ecx
lea    0xacd(%rip),%r8
call   10d0 <fprintf@plt>
mov    0x296f(%rip),%rax
mov    (%rax),%edi
call   1100 <fflush@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1684 <get_xio_base+0x474>
jmp    1689 <get_xio_base+0x479>
mov    -0x128(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x298(%rbp)
jne    1700 <get_xio_base+0x4f0>
lea    -0x4a0(%rbp),%rax
mov    %rax,-0x4d0(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x4c8(%rbp)
mov    0x2912(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x4d0(%rbp),%rdi
mov    -0x4c8(%rbp),%rcx
mov    %rax,%r8
mov    $0x100,%esi
lea    0xad8(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x4a0(%rbp),%rdi
call   10f0 <add_error_msg@plt>
jmp    1721 <get_xio_base+0x511>
lea    -0x290(%rbp),%rdi
call   1120 <atoi@plt>
mov    %eax,0x2996(%rip)
jmp    1717 <get_xio_base+0x507>
jmp    171c <get_xio_base+0x50c>
jmp    12b2 <get_xio_base+0xa2>
mov    -0x130(%rbp),%rdi
call   1090 <closedir@plt>
mov    0x2975(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_xio_base>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x268,%rsp
mov    0x2e81(%rip),%eax
cmp    $0xffffffff,%eax
jne    129a <get_xio_base+0x8a>
lea    0xdcd(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1259 <get_xio_base+0x49>
mov    %rax,%r13
cmpl   $0xffffffff,0x2e61(%rip)
je     12ac <get_xio_base+0x9c>
mov    %r13,%rdi
call   1090 <closedir@plt>
mov    0x2e51(%rip),%eax
jmp    129a <get_xio_base+0x8a>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xda2(%rip),%rdx
lea    0xd8b(%rip),%rcx
lea    0xe0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%r8
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   10f0 <add_error_msg@plt>
mov    $0xffffffff,%eax
add    $0x268,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8(%rsp),%rbx
lea    0xd80(%rip),%r14
lea    0xd78(%rip),%r15
jmp    12dd <get_xio_base+0xcd>
mov    %rbx,%r14
lea    0xd6c(%rip),%r15
lea    0x8(%rsp),%rbx
cmpl   $0xffffffff,0x2dd1(%rip)
jne    1249 <get_xio_base+0x39>
mov    %r13,%rdi
call   10e0 <readdir@plt>
test   %rax,%rax
je     1249 <get_xio_base+0x39>
mov    %rax,%r12
mov    (%rax),%rdi
mov    %rbx,%rsi
call   10a0 <lstat@plt>
mov    0x8(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     12d0 <get_xio_base+0xc0>
mov    (%r12),%rsi
mov    %r14,%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     12d0 <get_xio_base+0xc0>
mov    (%r12),%rsi
mov    %r15,%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     12d0 <get_xio_base+0xc0>
mov    (%r12),%r8
lea    0x1e0(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x80,%esi
lea    0xcf3(%rip),%rdx
lea    0xcb2(%rip),%rcx
call   1070 <snprintf@plt>
mov    %rbp,%rdi
mov    $0x80,%esi
call   1080 <strnlen@plt>
cmp    $0x7f,%eax
jae    14d3 <get_xio_base+0x2c3>
mov    %rbp,%rdi
lea    0xdbd(%rip),%rsi
call   1110 <fopen@plt>
test   %rax,%rax
je     12d0 <get_xio_base+0xc0>
mov    %rax,%rbp
mov    %r14,%rbx
movb   $0x0,0x10(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   10b0 <fgets@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x50,%esi
call   1080 <strnlen@plt>
cmp    $0x4f,%eax
jae    14f8 <get_xio_base+0x2e8>
mov    %rbp,%rdi
call   1040 <fclose@plt>
test   %r15,%r15
je     12c1 <get_xio_base+0xb1>
mov    %r14,%rdi
lea    0xd9c(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
jne    12c1 <get_xio_base+0xb1>
mov    (%r12),%r8
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x80,%esi
lea    0xd80(%rip),%rdx
lea    0xbfe(%rip),%rcx
call   1070 <snprintf@plt>
mov    %rbp,%rdi
mov    $0x80,%esi
call   1080 <strnlen@plt>
cmp    $0x7f,%eax
jae    152e <get_xio_base+0x31e>
mov    %rbp,%rdi
lea    0xd09(%rip),%rsi
call   1110 <fopen@plt>
test   %rax,%rax
je     147d <get_xio_base+0x26d>
mov    %rax,%rbp
mov    %r14,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   10b0 <fgets@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x50,%esi
call   1080 <strnlen@plt>
cmp    $0x4f,%eax
jae    1553 <get_xio_base+0x343>
mov    %rbp,%rdi
call   1040 <fclose@plt>
test   %r15,%r15
je     1494 <get_xio_base+0x284>
mov    %r14,%rdi
call   1120 <atoi@plt>
mov    %eax,0x2c30(%rip)
jmp    12c1 <get_xio_base+0xb1>
mov    0x2b54(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb7e(%rip),%rdx
jmp    14a9 <get_xio_base+0x299>
mov    0x2b3d(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xd19(%rip),%rdx
lea    0xe0(%rsp),%rbp
lea    0x60(%rsp),%rcx
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rax,%r8
call   1070 <snprintf@plt>
mov    %rbp,%rdi
call   10f0 <add_error_msg@plt>
jmp    1249 <get_xio_base+0x39>
mov    0x2b06(%rip),%rbx
mov    (%rbx),%edi
lea    0xb63(%rip),%rsi
lea    0xb78(%rip),%rdx
lea    0xc00(%rip),%r8
mov    $0xc2,%ecx
jmp    151b <get_xio_base+0x30b>
mov    0x2ae1(%rip),%rbx
mov    (%rbx),%edi
lea    0xb3e(%rip),%rsi
lea    0xb53(%rip),%rdx
lea    0xc1c(%rip),%r8
mov    $0xc6,%ecx
call   10d0 <fprintf@plt>
mov    (%rbx),%edi
call   1100 <fflush@plt>
xor    %eax,%eax
call   1030 <abort@plt>
mov    0x2aab(%rip),%rbx
mov    (%rbx),%edi
lea    0xb08(%rip),%rsi
lea    0xb1d(%rip),%rdx
lea    0xc3a(%rip),%r8
mov    $0xca,%ecx
jmp    151b <get_xio_base+0x30b>
mov    0x2a86(%rip),%rbx
mov    (%rbx),%edi
lea    0xae3(%rip),%rsi
lea    0xaf8(%rip),%rdx
lea    0xbc1(%rip),%r8
mov    $0xd2,%ecx
jmp    151b <get_xio_base+0x30b>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@get_xio_base.xio_base_address = internal global i32 -1
@.str = [16 x i8] c"/sys/class/gpio\00"
@.str.1 = [39 x i8] c"get_xio_base: could not open '%s' (%s)\00"
@errno = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [12 x i8] c"%s/%s/label\00"
@stderr = global i32 0
@.str.5 = [28 x i8] c"ASSRT failed at %s:%d (%s)\0A\00"
@.str.6 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/xtacocorex/CHIP_IO/refs/heads/master/source/common.c\00"
@.str.7 = [63 x i8] c"strnlen(label_file, sizeof(label_file)) < sizeof(label_file)-1\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [63 x i8] c"strnlen(input_line, sizeof(input_line)) < sizeof(input_line)-1\00"
@.str.10 = [10 x i8] c"pcf8574a\0A\00"
@.str.11 = [11 x i8] c"%s/%s/base\00"
@.str.12 = [60 x i8] c"strnlen(base_file, sizeof(base_file)) < sizeof(base_file)-1\00"
@.str.13 = [39 x i8] c"get_xio_base: could not read '%s' (%s)\00"
define i32 @get_xio_base() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca i32*
%4 = alloca [128 x i8]
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca %struct.stat
%9 = alloca [256 x i8]
%10 = alloca [80 x i8]
%11 = alloca i8*
%12 = alloca [256 x i8]
%13 = alloca [256 x i8]
%14 = load i32, i32* @get_xio_base.xio_base_address
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = load i32, i32* @get_xio_base.xio_base_address
store i32 %17, i32* %1
br label %188
18: ; preds = %0
%19 = call i32* @opendir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %29
22: ; preds = %18
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @snprintf(i8* %23, i32 256, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%28 = call i32 @add_error_msg(i8* %27)
store i32 -1, i32* %1
br label %188
29: ; preds = %18
br label %30
30: ; preds = %183, %60, %29
%31 = load i32, i32* @get_xio_base.xio_base_address
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32*, i32** %6
%35 = call %struct.dirent* @readdir(i32* %34)
store %struct.dirent* %35, %struct.dirent** %7
%36 = icmp ne %struct.dirent* %35, null
br label %37
37: ; preds = %33, %30
%38 = phi i1 [ false, %30 ], [ %36, %33 ]
br i1 %38, label %39, label %184
39: ; preds = %37
%40 = load %struct.dirent*, %struct.dirent** %7
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = call i32 @lstat(i8* %42, %struct.stat* %8)
%44 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%45 = load i32, i32* %44
%46 = call i64 @S_ISDIR(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %183
48: ; preds = %39
%49 = load %struct.dirent*, %struct.dirent** %7
%50 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i32 0, i32 0
%51 = load i8*, i8** %50
%52 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %48
%55 = load %struct.dirent*, %struct.dirent** %7
%56 = getelementptr inbounds %struct.dirent, %struct.dirent* %55, i32 0, i32 0
%57 = load i8*, i8** %56
%58 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %54, %48
br label %30
61: ; preds = %54
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%63 = load %struct.dirent*, %struct.dirent** %7
%64 = getelementptr inbounds %struct.dirent, %struct.dirent* %63, i32 0, i32 0
%65 = load i8*, i8** %64
%66 = call i32 @snprintf(i8* %62, i32 128, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %61
br label %68
68: ; preds = %67
%69 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%70 = call i32 @strnlen(i8* %69, i32 128)
%71 = sext i32 %70 to i64
%72 = icmp ult i64 %71, 127
br i1 %72, label %79, label %73
73: ; preds = %68
%74 = load i32, i32* @stderr
%75 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.6, i64 0, i64 0), i32 194, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.7, i64 0, i64 0))
%76 = load i32, i32* @stderr
%77 = call i32 @fflush(i32 %76)
%78 = call i32 (...) @abort()
unreachable
79: ; preds = %68
br label %80
80: ; preds = %79
br label %81
81: ; preds = %80
%82 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%83 = call i32* @fopen(i8* %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %83, i32** %3
%84 = load i32*, i32** %3
%85 = icmp ne i32* %84, null
br i1 %85, label %86, label %182
86: ; preds = %81
%87 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
store i8 0, i8* %87
%88 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%89 = load i32*, i32** %3
%90 = call i8* @fgets(i8* %88, i32 80, i32* %89)
store i8* %90, i8** %11
br label %91
91: ; preds = %86
br label %92
92: ; preds = %91
%93 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%94 = call i32 @strnlen(i8* %93, i32 80)
%95 = sext i32 %94 to i64
%96 = icmp ult i64 %95, 79
br i1 %96, label %103, label %97
97: ; preds = %92
%98 = load i32, i32* @stderr
%99 = call i32 @fprintf(i32 %98, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.6, i64 0, i64 0), i32 198, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.9, i64 0, i64 0))
%100 = load i32, i32* @stderr
%101 = call i32 @fflush(i32 %100)
%102 = call i32 (...) @abort()
unreachable
103: ; preds = %92
br label %104
104: ; preds = %103
br label %105
105: ; preds = %104
%106 = load i32*, i32** %3
%107 = call i32 @fclose(i32* %106)
%108 = load i8*, i8** %11
%109 = icmp ne i8* %108, null
br i1 %109, label %110, label %181
110: ; preds = %105
%111 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%112 = call i64 @strcmp(i8* %111, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
%113 = icmp eq i64 %112, 0
br i1 %113, label %114, label %181
114: ; preds = %110
%115 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%116 = load %struct.dirent*, %struct.dirent** %7
%117 = getelementptr inbounds %struct.dirent, %struct.dirent* %116, i32 0, i32 0
%118 = load i8*, i8** %117
%119 = call i32 @snprintf(i8* %115, i32 128, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %118)
br label %120
120: ; preds = %114
br label %121
121: ; preds = %120
%122 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%123 = call i32 @strnlen(i8* %122, i32 128)
%124 = sext i32 %123 to i64
%125 = icmp ult i64 %124, 127
br i1 %125, label %132, label %126
126: ; preds = %121
%127 = load i32, i32* @stderr
%128 = call i32 @fprintf(i32 %127, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.6, i64 0, i64 0), i32 202, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.12, i64 0, i64 0))
%129 = load i32, i32* @stderr
%130 = call i32 @fflush(i32 %129)
%131 = call i32 (...) @abort()
unreachable
132: ; preds = %121
br label %133
133: ; preds = %132
br label %134
134: ; preds = %133
%135 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%136 = call i32* @fopen(i8* %135, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %136, i32** %5
%137 = load i32*, i32** %5
%138 = icmp eq i32* %137, null
br i1 %138, label %139, label %147
139: ; preds = %134
%140 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%141 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%142 = load i32, i32* @errno
%143 = call i8* @strerror(i32 %142)
%144 = call i32 @snprintf(i8* %140, i32 256, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %141, i8* %143)
%145 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%146 = call i32 @add_error_msg(i8* %145)
br label %184
147: ; preds = %134
%148 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%149 = load i32*, i32** %5
%150 = call i8* @fgets(i8* %148, i32 80, i32* %149)
store i8* %150, i8** %11
br label %151
151: ; preds = %147
br label %152
152: ; preds = %151
%153 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%154 = call i32 @strnlen(i8* %153, i32 80)
%155 = sext i32 %154 to i64
%156 = icmp ult i64 %155, 79
br i1 %156, label %163, label %157
157: ; preds = %152
%158 = load i32, i32* @stderr
%159 = call i32 @fprintf(i32 %158, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.6, i64 0, i64 0), i32 210, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.9, i64 0, i64 0))
%160 = load i32, i32* @stderr
%161 = call i32 @fflush(i32 %160)
%162 = call i32 (...) @abort()
unreachable
163: ; preds = %152
br label %164
164: ; preds = %163
br label %165
165: ; preds = %164
%166 = load i32*, i32** %5
%167 = call i32 @fclose(i32* %166)
%168 = load i8*, i8** %11
%169 = icmp eq i8* %168, null
br i1 %169, label %170, label %178
170: ; preds = %165
%171 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%172 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%173 = load i32, i32* @errno
%174 = call i8* @strerror(i32 %173)
%175 = call i32 @snprintf(i8* %171, i32 256, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.13, i64 0, i64 0), i8* %172, i8* %174)
%176 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%177 = call i32 @add_error_msg(i8* %176)
br label %184
178: ; preds = %165
%179 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%180 = call i32 @atoi(i8* %179)
store i32 %180, i32* @get_xio_base.xio_base_address
br label %181
181: ; preds = %178, %110, %105
br label %182
182: ; preds = %181, %81
br label %183
183: ; preds = %182, %39
br label %30
184: ; preds = %170, %139, %37
%185 = load i32*, i32** %6
%186 = call i32 @closedir(i32* %185)
%187 = load i32, i32* @get_xio_base.xio_base_address
store i32 %187, i32* %1
br label %188
188: ; preds = %184, %22, %16
%189 = load i32, i32* %1
ret i32 %189
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@get_xio_base.xio_base_address = internal unnamed_addr global i32 -1
@.str = [16 x i8] c"/sys/class/gpio\00"
@.str.1 = [39 x i8] c"get_xio_base: could not open '%s' (%s)\00"
@errno = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [12 x i8] c"%s/%s/label\00"
@stderr = global i32 0
@.str.5 = [28 x i8] c"ASSRT failed at %s:%d (%s)\0A\00"
@.str.6 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/xtacocorex/CHIP_IO/refs/heads/master/source/common.c\00"
@.str.7 = [63 x i8] c"strnlen(label_file, sizeof(label_file)) < sizeof(label_file)-1\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [63 x i8] c"strnlen(input_line, sizeof(input_line)) < sizeof(input_line)-1\00"
@.str.10 = [10 x i8] c"pcf8574a\0A\00"
@.str.11 = [11 x i8] c"%s/%s/base\00"
@.str.12 = [60 x i8] c"strnlen(base_file, sizeof(base_file)) < sizeof(base_file)-1\00"
@.str.13 = [39 x i8] c"get_xio_base: could not read '%s' (%s)\00"
define i32 @get_xio_base() {
%1 = alloca [128 x i8]
%2 = alloca [128 x i8]
%3 = alloca %struct.stat
%4 = alloca [256 x i8]
%5 = alloca [80 x i8]
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%10 = bitcast %struct.stat* %3 to i8*
%11 = load i32, i32* @get_xio_base.xio_base_address
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %125
13: ; preds = %0
%14 = tail call i32* @opendir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = load i32, i32* @get_xio_base.xio_base_address
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %122
19: ; preds = %16
%20 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
br label %28
22: ; preds = %13
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = call i32 @snprintf(i8* %23, i32 256, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = call i32 @add_error_msg(i8* %23)
br label %125
28: ; preds = %19, %46
%29 = call %struct.dirent* @readdir(i32* %14)
%30 = icmp eq %struct.dirent* %29, null
br i1 %30, label %122, label %31
31: ; preds = %28
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i64 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @lstat(i8* %33, %struct.stat* %3)
%35 = load i32, i32* %20
%36 = call i64 @S_ISDIR(i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %46, label %38
38: ; preds = %31
%39 = load i8*, i8** %32
%40 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %38
%43 = load i8*, i8** %32
%44 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %31, %60, %120, %38, %42
%47 = load i32, i32* @get_xio_base.xio_base_address
%48 = icmp eq i32 %47, -1
br i1 %48, label %28, label %122
49: ; preds = %42
%50 = load i8*, i8** %32
%51 = call i32 @snprintf(i8* %8, i32 128, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %50)
%52 = call i32 @strnlen(i8* %8, i32 128)
%53 = icmp ult i32 %52, 127
br i1 %53, label %60, label %54
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.6, i64 0, i64 0), i32 194, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.7, i64 0, i64 0))
%57 = load i32, i32* @stderr
%58 = call i32 @fflush(i32 %57)
%59 = call i32 (...) @abort()
unreachable
60: ; preds = %49
%61 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%62 = icmp eq i32* %61, null
br i1 %62, label %46, label %63
63: ; preds = %60
store i8 0, i8* %21
%64 = call i8* @fgets(i8* %21, i32 80, i32* %61)
%65 = call i32 @strnlen(i8* %21, i32 80)
%66 = icmp ult i32 %65, 79
br i1 %66, label %73, label %67
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.6, i64 0, i64 0), i32 198, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.9, i64 0, i64 0))
%70 = load i32, i32* @stderr
%71 = call i32 @fflush(i32 %70)
%72 = call i32 (...) @abort()
unreachable
73: ; preds = %63
%74 = call i32 @fclose(i32* %61)
%75 = icmp eq i8* %64, null
br i1 %75, label %120, label %76
76: ; preds = %73
%77 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %120
79: ; preds = %76
%80 = load i8*, i8** %32
%81 = call i32 @snprintf(i8* %9, i32 128, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %80)
%82 = call i32 @strnlen(i8* %9, i32 128)
%83 = icmp ult i32 %82, 127
br i1 %83, label %90, label %84
84: ; preds = %79
%85 = load i32, i32* @stderr
%86 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.6, i64 0, i64 0), i32 202, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.12, i64 0, i64 0))
%87 = load i32, i32* @stderr
%88 = call i32 @fflush(i32 %87)
%89 = call i32 (...) @abort()
unreachable
90: ; preds = %79
%91 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%92 = icmp eq i32* %91, null
br i1 %92, label %93, label %99
93: ; preds = %90
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%95 = load i32, i32* @errno
%96 = call i8* @strerror(i32 %95)
%97 = call i32 @snprintf(i8* %94, i32 256, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %96)
%98 = call i32 @add_error_msg(i8* %94)
br label %121
99: ; preds = %90
%100 = call i8* @fgets(i8* %21, i32 80, i32* %91)
%101 = call i32 @strnlen(i8* %21, i32 80)
%102 = icmp ult i32 %101, 79
br i1 %102, label %109, label %103
103: ; preds = %99
%104 = load i32, i32* @stderr
%105 = call i32 @fprintf(i32 %104, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.6, i64 0, i64 0), i32 210, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.9, i64 0, i64 0))
%106 = load i32, i32* @stderr
%107 = call i32 @fflush(i32 %106)
%108 = call i32 (...) @abort()
unreachable
109: ; preds = %99
%110 = call i32 @fclose(i32* %91)
%111 = icmp eq i8* %100, null
br i1 %111, label %112, label %118
112: ; preds = %109
%113 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%114 = load i32, i32* @errno
%115 = call i8* @strerror(i32 %114)
%116 = call i32 @snprintf(i8* %113, i32 256, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.13, i64 0, i64 0), i8* %9, i8* %115)
%117 = call i32 @add_error_msg(i8* %113)
br label %121
118: ; preds = %109
%119 = call i32 @atoi(i8* %21)
store i32 %119, i32* @get_xio_base.xio_base_address
br label %120
120: ; preds = %118, %76, %73
br label %46
121: ; preds = %112, %93
br label %122
122: ; preds = %28, %46, %16, %121
%123 = call i32 @closedir(i32* %14)
%124 = load i32, i32* @get_xio_base.xio_base_address
br label %125
125: ; preds = %0, %122, %22
%126 = phi i32 [ -1, %22 ], [ %124, %122 ], [ %11, %0 ]
ret i32 %126
}