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

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ NAME_MAX;
char *basename(char *);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int flush_cache_ext(char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *hdopen(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int readlink(char *, char *, int);
int snprintf(char *, int, char *, char *);
scalar_t__ strncmp(char *, char *, int);
char *strstrip(char *);
char *list_disks(DIR *blk, unsigned int *flags) {
  struct dirent *d;
  while ((d = readdir(blk))) {
    (*flags) = 0;
    if (d->d_name[1] == 'd' && (d->d_name[0] == 'h' || d->d_name[0] == 's')) {
      char buf[NAME_MAX + 1], lnk[NAME_MAX + 1], *ptr;
      FILE *fp;
      int ret;
      fp = hdopen("/sys/block"
                  "/%s/removable",
                  d->d_name);
      if (0 == (long)fp || -1 == (long)fp) {
        if (-1 == (long)fp)
          goto empty;
        continue;
      }
      ret = getc(fp);
      fclose(fp);
      if (ret != '0')
        (*flags) |= 0x00000008;
      if (d->d_name[0] == 'h') {
        if ((*flags) & 0x00000008)
          continue;
        (*flags) |= 0x00000001;
        if ((ret = flush_cache_ext(d->d_name))) {
          if (ret < 0)
            goto empty;
          (*flags) |= 0x00000004;
        }
        break;
      }
      ret = snprintf(buf, sizeof(buf),
                     "/sys/block"
                     "/%s/device",
                     d->d_name);
      if ((ret >= (int)sizeof(buf)) || (ret < 0))
        goto empty;
      ret = readlink(buf, lnk, sizeof(lnk));
      if (ret >= (int)sizeof(lnk))
        goto empty;
      if (ret < 0) {
        if (errno != ENOENT)
          goto empty;
        continue;
      }
      lnk[ret] = '\0';
      ptr = basename(lnk);
      if (!ptr || !*ptr)
        continue;
      fp = hdopen("/sys/class/scsi_disk"
                  "/%s/manage_start_stop",
                  ptr);
      if (0 == (long)fp || -1 == (long)fp) {
        if (-1 == (long)fp)
          goto empty;
      } else {
        ret = getc(fp);
        fclose(fp);
        if (ret != '0') {
          (*flags) |= 0x00000010;
          continue;
        }
      }
      fp = hdopen("/sys/block"
                  "/%s/device/vendor",
                  d->d_name);
      if (0 == (long)fp || -1 == (long)fp) {
        if (-1 == (long)fp)
          goto empty;
        continue;
      }
      ptr = fgets(buf, sizeof(buf), fp);
      fclose(fp);
      if (ptr == (char *)0)
        continue;
      ptr = strstrip(buf);
      if (*ptr == '\0')
        continue;
      if (strncmp(buf, "ATA", sizeof(buf)) == 0) {
        if ((*flags) & 0x00000008)
          continue;
        (*flags) |= (0x00000001 | 0x00000002);
        if ((ret = flush_cache_ext(d->d_name))) {
          if (ret < 0)
            goto empty;
          (*flags) |= 0x00000004;
        }
        break;
      }
      if (((*flags) & 0x00000008) == 0)
        continue;
      if ((ret = flush_cache_ext(d->d_name))) {
        if (ret < 0)
          goto empty;
        (*flags) |= 0x00000004;
      }
      break;
    }
  }
  if (d == (struct dirent *)0)
    goto empty;
  return d->d_name;
empty:
  return (char *)0;
}


x86 assembly (clang, -O0):
<list_disks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     16f1 <list_disks+0x541>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    16ec <list_disks+0x53c>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x68,%eax
je     121e <list_disks+0x6e>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x73,%eax
jne    16ec <list_disks+0x53c>
mov    0x2da3(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rcx,-0x70(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x68(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x60(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xd7c(%rip),%rdi
call   10c0 <hdopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12b0 <list_disks+0x100>
mov    -0x48(%rbp),%rcx
mov    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jne    12dc <list_disks+0x12c>
mov    -0x48(%rbp),%rcx
mov    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jne    12d0 <list_disks+0x120>
movl   $0x4,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
movl   $0x2,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x48(%rbp),%rdi
call   10d0 <getc@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x30,-0x4c(%rbp)
je     1306 <list_disks+0x156>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x8,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x68,%eax
jne    1387 <list_disks+0x1d7>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1337 <list_disks+0x187>
movl   $0x2,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <flush_cache_ext@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
je     137b <list_disks+0x1cb>
cmpl   $0x0,-0x4c(%rbp)
jge    1370 <list_disks+0x1c0>
movl   $0x4,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x4,%ecx
mov    %ecx,(%rax)
movl   $0x3,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x70(%rbp),%rax
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xc79(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x70(%rbp),%rcx
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
jge    13c0 <list_disks+0x210>
cmpl   $0x0,-0x4c(%rbp)
jge    13cc <list_disks+0x21c>
movl   $0x4,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x60(%rbp),%rax
mov    -0x58(%rbp),%rsi
mov    -0x68(%rbp),%rdi
mov    %eax,%edx
call   1050 <readlink@plt>
mov    -0x60(%rbp),%rcx
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
jl     13fd <list_disks+0x24d>
movl   $0x4,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
cmpl   $0x0,-0x4c(%rbp)
jge    1439 <list_disks+0x289>
mov    0x2bd2(%rip),%rax
mov    (%rax),%rax
mov    0x2bb8(%rip),%rcx
cmp    (%rcx),%rax
je     142d <list_disks+0x27d>
movl   $0x4,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
movl   $0x2,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x58(%rbp),%rdi
movslq -0x4c(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
call   10a0 <basename@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1466 <list_disks+0x2b6>
mov    -0x40(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1472 <list_disks+0x2c2>
movl   $0x2,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x40(%rbp),%rsi
lea    0xbb0(%rip),%rdi
call   10c0 <hdopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     14a9 <list_disks+0x2f9>
mov    -0x48(%rbp),%rcx
mov    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jne    14ce <list_disks+0x31e>
mov    -0x48(%rbp),%rcx
mov    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jne    14c9 <list_disks+0x319>
movl   $0x4,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
jmp    1509 <list_disks+0x359>
mov    -0x48(%rbp),%rdi
call   10d0 <getc@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x30,-0x4c(%rbp)
je     1504 <list_disks+0x354>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x10,%ecx
mov    %ecx,(%rax)
movl   $0x2,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
jmp    1509 <list_disks+0x359>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xb40(%rip),%rdi
call   10c0 <hdopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1543 <list_disks+0x393>
mov    -0x48(%rbp),%rcx
mov    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jne    156f <list_disks+0x3bf>
mov    -0x48(%rbp),%rcx
mov    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jne    1563 <list_disks+0x3b3>
movl   $0x4,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
movl   $0x2,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x68(%rbp),%rdi
mov    -0x70(%rbp),%rax
mov    %eax,%esi
mov    -0x48(%rbp),%rdx
call   1080 <fgets@plt>
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
cmpq   $0x0,-0x40(%rbp)
jne    15a6 <list_disks+0x3f6>
movl   $0x2,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x68(%rbp),%rdi
call   1090 <strstrip@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    15cf <list_disks+0x41f>
movl   $0x2,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x68(%rbp),%rdi
mov    -0x70(%rbp),%rax
mov    %eax,%edx
lea    0xa93(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    165d <list_disks+0x4ad>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     160d <list_disks+0x45d>
movl   $0x2,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x3,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <flush_cache_ext@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
je     1651 <list_disks+0x4a1>
cmpl   $0x0,-0x4c(%rbp)
jge    1646 <list_disks+0x496>
movl   $0x4,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x4,%ecx
mov    %ecx,(%rax)
movl   $0x3,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0x8,%eax
cmp    $0x0,%eax
jne    167b <list_disks+0x4cb>
movl   $0x2,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <flush_cache_ext@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
je     16b4 <list_disks+0x504>
cmpl   $0x0,-0x4c(%rbp)
jge    16a9 <list_disks+0x4f9>
movl   $0x4,-0x50(%rbp)
jmp    16bb <list_disks+0x50b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x4,%ecx
mov    %ecx,(%rax)
movl   $0x3,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x50(%rbp),%eax
mov    %eax,-0x74(%rbp)
sub    $0x2,%eax
je     11c3 <list_disks+0x13>
jmp    16d6 <list_disks+0x526>
mov    -0x74(%rbp),%eax
sub    $0x3,%eax
je     16f1 <list_disks+0x541>
jmp    16e7 <list_disks+0x537>
jmp    1711 <list_disks+0x561>
jmp    11c3 <list_disks+0x13>
cmpq   $0x0,-0x20(%rbp)
jne    1701 <list_disks+0x551>
jmp    1711 <list_disks+0x561>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1719 <list_disks+0x569>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_disks>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r13
mov    %rdi,%r12
call   10b0 <readdir@plt>
test   %rax,%rax
je     1450 <list_disks+0x2a0>
mov    %rax,%rbx
mov    %r12,-0x48(%rbp)
jmp    1206 <list_disks+0x56>
mov    0x0(%r13),%eax
test   $0x8,%al
mov    -0x48(%rbp),%r12
je     1429 <list_disks+0x279>
mov    -0x40(%rbp),%rsp
mov    %r12,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1450 <list_disks+0x2a0>
movl   $0x0,0x0(%r13)
mov    (%rbx),%rax
cmpb   $0x64,0x1(%rax)
jne    11f2 <list_disks+0x42>
movzbl (%rax),%eax
cmp    $0x73,%al
je     1222 <list_disks+0x72>
cmp    $0x68,%al
jne    11f2 <list_disks+0x42>
mov    %rsp,-0x40(%rbp)
mov    0x2d9b(%rip),%rcx
mov    (%rcx),%eax
mov    %rax,-0x60(%rbp)
add    $0x1,%eax
mov    %rsp,%rdx
mov    %rax,-0x38(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rdx,%rsp
mov    (%rcx),%eax
mov    %rax,-0x58(%rbp)
add    $0x1,%eax
mov    %rsp,%r14
mov    %rax,-0x50(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    (%rbx),%rsi
lea    0xd89(%rip),%rdi
call   10c0 <hdopen@plt>
test   %rax,%rax
je     11ee <list_disks+0x3e>
mov    %rax,%r15
cmp    $0xffffffffffffffff,%rax
je     144c <list_disks+0x29c>
mov    %r15,%rdi
call   10d0 <getc@plt>
mov    %r13,%r12
mov    %eax,%r13d
mov    %r15,%rdi
call   1060 <fclose@plt>
cmp    $0x30,%r13d
mov    %r12,%r13
je     12b6 <list_disks+0x106>
orb    $0x8,0x0(%r13)
mov    (%rbx),%rcx
cmpb   $0x68,(%rcx)
je     11de <list_disks+0x2e>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    0xd47(%rip),%rdx
call   1070 <snprintf@plt>
cmp    -0x60(%rbp),%eax
mov    -0x48(%rbp),%r12
jg     144c <list_disks+0x29c>
test   %eax,%eax
js     144c <list_disks+0x29c>
mov    -0x30(%rbp),%rdi
mov    %r14,%rsi
mov    -0x50(%rbp),%rdx
call   1050 <readlink@plt>
cmp    -0x58(%rbp),%eax
jg     144c <list_disks+0x29c>
test   %eax,%eax
js     13ee <list_disks+0x23e>
mov    %eax,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
call   10a0 <basename@plt>
test   %rax,%rax
je     11ee <list_disks+0x3e>
cmpb   $0x0,(%rax)
je     11ee <list_disks+0x3e>
lea    0xcf9(%rip),%rdi
mov    %rax,%rsi
call   10c0 <hdopen@plt>
test   %rax,%rax
je     136b <list_disks+0x1bb>
mov    %rax,%r14
cmp    $0xffffffffffffffff,%rax
je     144c <list_disks+0x29c>
mov    %r14,%rdi
call   10d0 <getc@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1060 <fclose@plt>
cmp    $0x30,%r15d
jne    140a <list_disks+0x25a>
mov    (%rbx),%rsi
lea    0xce2(%rip),%rdi
call   10c0 <hdopen@plt>
test   %rax,%rax
je     11ee <list_disks+0x3e>
mov    %rax,%r14
cmp    $0xffffffffffffffff,%rax
je     144c <list_disks+0x29c>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %r14,%rdx
call   1080 <fgets@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1060 <fclose@plt>
test   %r15,%r15
je     11ee <list_disks+0x3e>
mov    -0x30(%rbp),%rdi
call   1090 <strstrip@plt>
cmpb   $0x0,(%rax)
je     11ee <list_disks+0x3e>
mov    -0x30(%rbp),%rdi
lea    0xca2(%rip),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <strncmp@plt>
mov    0x0(%r13),%ecx
test   %rax,%rax
je     1414 <list_disks+0x264>
test   $0x8,%cl
je     11ee <list_disks+0x3e>
jmp    1424 <list_disks+0x274>
mov    0x2beb(%rip),%rax
mov    (%rax),%rax
mov    0x2bd1(%rip),%rcx
cmp    (%rcx),%rax
je     11ee <list_disks+0x3e>
jmp    144c <list_disks+0x29c>
orb    $0x10,0x0(%r13)
jmp    11ee <list_disks+0x3e>
test   $0x8,%cl
jne    11ee <list_disks+0x3e>
or     $0x3,%ecx
mov    %ecx,0x0(%r13)
mov    (%rbx),%rdi
jmp    1433 <list_disks+0x283>
or     $0x1,%eax
mov    %eax,0x0(%r13)
mov    %rcx,%rdi
call   1040 <flush_cache_ext@plt>
test   %eax,%eax
je     1443 <list_disks+0x293>
js     144c <list_disks+0x29c>
orb    $0x4,0x0(%r13)
mov    -0x40(%rbp),%rsp
mov    (%rbx),%rax
jmp    1452 <list_disks+0x2a2>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@NAME_MAX = global i32 0
@.str = [24 x i8] c"/sys/block/%s/removable\00"
@.str.1 = [21 x i8] c"/sys/block/%s/device\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [42 x i8] c"/sys/class/scsi_disk/%s/manage_start_stop\00"
@.str.3 = [28 x i8] c"/sys/block/%s/device/vendor\00"
@.str.4 = [4 x i8] c"ATA\00"
define i8* @list_disks(i32* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca %struct.dirent*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
br label %14
14: ; preds = %268, %265, %2
%15 = load i32*, i32** %4
%16 = call %struct.dirent* @readdir(i32* %15)
store %struct.dirent* %16, %struct.dirent** %6
%17 = icmp ne %struct.dirent* %16, null
br i1 %17, label %18, label %269
18: ; preds = %14
%19 = load i32*, i32** %5
store i32 0, i32* %19
%20 = load %struct.dirent*, %struct.dirent** %6
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 100
br i1 %26, label %27, label %268
27: ; preds = %18
%28 = load %struct.dirent*, %struct.dirent** %6
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 104
br i1 %34, label %43, label %35
35: ; preds = %27
%36 = load %struct.dirent*, %struct.dirent** %6
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = getelementptr inbounds i8, i8* %38, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 115
br i1 %42, label %43, label %268
43: ; preds = %35, %27
%44 = load i32, i32* @NAME_MAX
%45 = add nsw i32 %44, 1
%46 = zext i32 %45 to i64
%47 = call i8* @llvm.stacksave()
store i8* %47, i8** %7
%48 = alloca i8, i64 %46
store i64 %46, i64* %8
%49 = load i32, i32* @NAME_MAX
%50 = add nsw i32 %49, 1
%51 = zext i32 %50 to i64
%52 = alloca i8, i64 %51
store i64 %51, i64* %9
%53 = load %struct.dirent*, %struct.dirent** %6
%54 = getelementptr inbounds %struct.dirent, %struct.dirent* %53, i32 0, i32 0
%55 = load i8*, i8** %54
%56 = call i32* @hdopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %55)
store i32* %56, i32** %11
%57 = load i32*, i32** %11
%58 = ptrtoint i32* %57 to i64
%59 = icmp eq i64 0, %58
br i1 %59, label %64, label %60
60: ; preds = %43
%61 = load i32*, i32** %11
%62 = ptrtoint i32* %61 to i64
%63 = icmp eq i64 -1, %62
br i1 %63, label %64, label %70
64: ; preds = %60, %43
%65 = load i32*, i32** %11
%66 = ptrtoint i32* %65 to i64
%67 = icmp eq i64 -1, %66
br i1 %67, label %68, label %69
68: ; preds = %64
store i32 4, i32* %13
br label %265
69: ; preds = %64
store i32 2, i32* %13
br label %265
70: ; preds = %60
%71 = load i32*, i32** %11
%72 = call i32 @getc(i32* %71)
store i32 %72, i32* %12
%73 = load i32*, i32** %11
%74 = call i32 @fclose(i32* %73)
%75 = load i32, i32* %12
%76 = icmp ne i32 %75, 48
br i1 %76, label %77, label %81
77: ; preds = %70
%78 = load i32*, i32** %5
%79 = load i32, i32* %78
%80 = or i32 %79, 8
store i32 %80, i32* %78
br label %81
81: ; preds = %77, %70
%82 = load %struct.dirent*, %struct.dirent** %6
%83 = getelementptr inbounds %struct.dirent, %struct.dirent* %82, i32 0, i32 0
%84 = load i8*, i8** %83
%85 = getelementptr inbounds i8, i8* %84, i64 0
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = icmp eq i32 %87, 104
br i1 %88, label %89, label %113
89: ; preds = %81
%90 = load i32*, i32** %5
%91 = load i32, i32* %90
%92 = and i32 %91, 8
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %95
94: ; preds = %89
store i32 2, i32* %13
br label %265
95: ; preds = %89
%96 = load i32*, i32** %5
%97 = load i32, i32* %96
%98 = or i32 %97, 1
store i32 %98, i32* %96
%99 = load %struct.dirent*, %struct.dirent** %6
%100 = getelementptr inbounds %struct.dirent, %struct.dirent* %99, i32 0, i32 0
%101 = load i8*, i8** %100
%102 = call i32 @flush_cache_ext(i8* %101)
store i32 %102, i32* %12
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %112
104: ; preds = %95
%105 = load i32, i32* %12
%106 = icmp slt i32 %105, 0
br i1 %106, label %107, label %108
107: ; preds = %104
store i32 4, i32* %13
br label %265
108: ; preds = %104
%109 = load i32*, i32** %5
%110 = load i32, i32* %109
%111 = or i32 %110, 4
store i32 %111, i32* %109
br label %112
112: ; preds = %108, %95
store i32 3, i32* %13
br label %265
113: ; preds = %81
%114 = trunc i64 %46 to i32
%115 = load %struct.dirent*, %struct.dirent** %6
%116 = getelementptr inbounds %struct.dirent, %struct.dirent* %115, i32 0, i32 0
%117 = load i8*, i8** %116
%118 = call i32 @snprintf(i8* %48, i32 %114, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %117)
store i32 %118, i32* %12
%119 = load i32, i32* %12
%120 = trunc i64 %46 to i32
%121 = icmp sge i32 %119, %120
br i1 %121, label %125, label %122
122: ; preds = %113
%123 = load i32, i32* %12
%124 = icmp slt i32 %123, 0
br i1 %124, label %125, label %126
125: ; preds = %122, %113
store i32 4, i32* %13
br label %265
126: ; preds = %122
%127 = trunc i64 %51 to i32
%128 = call i32 @readlink(i8* %48, i8* %52, i32 %127)
store i32 %128, i32* %12
%129 = load i32, i32* %12
%130 = trunc i64 %51 to i32
%131 = icmp sge i32 %129, %130
br i1 %131, label %132, label %133
132: ; preds = %126
store i32 4, i32* %13
br label %265
133: ; preds = %126
%134 = load i32, i32* %12
%135 = icmp slt i32 %134, 0
br i1 %135, label %136, label %142
136: ; preds = %133
%137 = load i64, i64* @errno
%138 = load i64, i64* @ENOENT
%139 = icmp ne i64 %137, %138
br i1 %139, label %140, label %141
140: ; preds = %136
store i32 4, i32* %13
br label %265
141: ; preds = %136
store i32 2, i32* %13
br label %265
142: ; preds = %133
%143 = load i32, i32* %12
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds i8, i8* %52, i64 %144
store i8 0, i8* %145
%146 = call i8* @basename(i8* %52)
store i8* %146, i8** %10
%147 = load i8*, i8** %10
%148 = icmp ne i8* %147, null
br i1 %148, label %149, label %153
149: ; preds = %142
%150 = load i8*, i8** %10
%151 = load i8, i8* %150
%152 = icmp ne i8 %151, 0
br i1 %152, label %154, label %153
153: ; preds = %149, %142
store i32 2, i32* %13
br label %265
154: ; preds = %149
%155 = load i8*, i8** %10
%156 = call i32* @hdopen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %155)
store i32* %156, i32** %11
%157 = load i32*, i32** %11
%158 = ptrtoint i32* %157 to i64
%159 = icmp eq i64 0, %158
br i1 %159, label %164, label %160
160: ; preds = %154
%161 = load i32*, i32** %11
%162 = ptrtoint i32* %161 to i64
%163 = icmp eq i64 -1, %162
br i1 %163, label %164, label %170
164: ; preds = %160, %154
%165 = load i32*, i32** %11
%166 = ptrtoint i32* %165 to i64
%167 = icmp eq i64 -1, %166
br i1 %167, label %168, label %169
168: ; preds = %164
store i32 4, i32* %13
br label %265
169: ; preds = %164
br label %182
170: ; preds = %160
%171 = load i32*, i32** %11
%172 = call i32 @getc(i32* %171)
store i32 %172, i32* %12
%173 = load i32*, i32** %11
%174 = call i32 @fclose(i32* %173)
%175 = load i32, i32* %12
%176 = icmp ne i32 %175, 48
br i1 %176, label %177, label %181
177: ; preds = %170
%178 = load i32*, i32** %5
%179 = load i32, i32* %178
%180 = or i32 %179, 16
store i32 %180, i32* %178
store i32 2, i32* %13
br label %265
181: ; preds = %170
br label %182
182: ; preds = %181, %169
%183 = load %struct.dirent*, %struct.dirent** %6
%184 = getelementptr inbounds %struct.dirent, %struct.dirent* %183, i32 0, i32 0
%185 = load i8*, i8** %184
%186 = call i32* @hdopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %185)
store i32* %186, i32** %11
%187 = load i32*, i32** %11
%188 = ptrtoint i32* %187 to i64
%189 = icmp eq i64 0, %188
br i1 %189, label %194, label %190
190: ; preds = %182
%191 = load i32*, i32** %11
%192 = ptrtoint i32* %191 to i64
%193 = icmp eq i64 -1, %192
br i1 %193, label %194, label %200
194: ; preds = %190, %182
%195 = load i32*, i32** %11
%196 = ptrtoint i32* %195 to i64
%197 = icmp eq i64 -1, %196
br i1 %197, label %198, label %199
198: ; preds = %194
store i32 4, i32* %13
br label %265
199: ; preds = %194
store i32 2, i32* %13
br label %265
200: ; preds = %190
%201 = trunc i64 %46 to i32
%202 = load i32*, i32** %11
%203 = call i8* @fgets(i8* %48, i32 %201, i32* %202)
store i8* %203, i8** %10
%204 = load i32*, i32** %11
%205 = call i32 @fclose(i32* %204)
%206 = load i8*, i8** %10
%207 = icmp eq i8* %206, null
br i1 %207, label %208, label %209
208: ; preds = %200
store i32 2, i32* %13
br label %265
209: ; preds = %200
%210 = call i8* @strstrip(i8* %48)
store i8* %210, i8** %10
%211 = load i8*, i8** %10
%212 = load i8, i8* %211
%213 = sext i8 %212 to i32
%214 = icmp eq i32 %213, 0
br i1 %214, label %215, label %216
215: ; preds = %209
store i32 2, i32* %13
br label %265
216: ; preds = %209
%217 = trunc i64 %46 to i32
%218 = call i64 @strncmp(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %217)
%219 = icmp eq i64 %218, 0
br i1 %219, label %220, label %244
220: ; preds = %216
%221 = load i32*, i32** %5
%222 = load i32, i32* %221
%223 = and i32 %222, 8
%224 = icmp ne i32 %223, 0
br i1 %224, label %225, label %226
225: ; preds = %220
store i32 2, i32* %13
br label %265
226: ; preds = %220
%227 = load i32*, i32** %5
%228 = load i32, i32* %227
%229 = or i32 %228, 3
store i32 %229, i32* %227
%230 = load %struct.dirent*, %struct.dirent** %6
%231 = getelementptr inbounds %struct.dirent, %struct.dirent* %230, i32 0, i32 0
%232 = load i8*, i8** %231
%233 = call i32 @flush_cache_ext(i8* %232)
store i32 %233, i32* %12
%234 = icmp ne i32 %233, 0
br i1 %234, label %235, label %243
235: ; preds = %226
%236 = load i32, i32* %12
%237 = icmp slt i32 %236, 0
br i1 %237, label %238, label %239
238: ; preds = %235
store i32 4, i32* %13
br label %265
239: ; preds = %235
%240 = load i32*, i32** %5
%241 = load i32, i32* %240
%242 = or i32 %241, 4
store i32 %242, i32* %240
br label %243
243: ; preds = %239, %226
store i32 3, i32* %13
br label %265
244: ; preds = %216
%245 = load i32*, i32** %5
%246 = load i32, i32* %245
%247 = and i32 %246, 8
%248 = icmp eq i32 %247, 0
br i1 %248, label %249, label %250
249: ; preds = %244
store i32 2, i32* %13
br label %265
250: ; preds = %244
%251 = load %struct.dirent*, %struct.dirent** %6
%252 = getelementptr inbounds %struct.dirent, %struct.dirent* %251, i32 0, i32 0
%253 = load i8*, i8** %252
%254 = call i32 @flush_cache_ext(i8* %253)
store i32 %254, i32* %12
%255 = icmp ne i32 %254, 0
br i1 %255, label %256, label %264
256: ; preds = %250
%257 = load i32, i32* %12
%258 = icmp slt i32 %257, 0
br i1 %258, label %259, label %260
259: ; preds = %256
store i32 4, i32* %13
br label %265
260: ; preds = %256
%261 = load i32*, i32** %5
%262 = load i32, i32* %261
%263 = or i32 %262, 4
store i32 %263, i32* %261
br label %264
264: ; preds = %260, %250
store i32 3, i32* %13
br label %265
265: ; preds = %259, %238, %198, %168, %140, %132, %125, %107, %68, %264, %249, %243, %225, %215, %208, %199, %177, %153, %141, %112, %94, %69
%266 = load i8*, i8** %7
%267 = load i32, i32* %13
switch i32 %267, label %280 [
i32 2, label %14
i32 3, label %269
i32 4, label %277
]
268: ; preds = %35, %18
br label %14
269: ; preds = %265, %14
%270 = load %struct.dirent*, %struct.dirent** %6
%271 = icmp eq %struct.dirent* %270, null
br i1 %271, label %272, label %273
272: ; preds = %269
br label %277
273: ; preds = %269
%274 = load %struct.dirent*, %struct.dirent** %6
%275 = getelementptr inbounds %struct.dirent, %struct.dirent* %274, i32 0, i32 0
%276 = load i8*, i8** %275
store i8* %276, i8** %3
br label %278
277: ; preds = %272, %265
store i8* null, i8** %3
br label %278
278: ; preds = %277, %273
%279 = load i8*, i8** %3
ret i8* %279
280: ; preds = %265
unreachable
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@NAME_MAX = global i32 0
@.str = [24 x i8] c"/sys/block/%s/removable\00"
@.str.1 = [21 x i8] c"/sys/block/%s/device\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [42 x i8] c"/sys/class/scsi_disk/%s/manage_start_stop\00"
@.str.3 = [28 x i8] c"/sys/block/%s/device/vendor\00"
@.str.4 = [4 x i8] c"ATA\00"
define i8* @list_disks(i32* %0, i32* nocapture %1) {
%3 = call %struct.dirent* @readdir(i32* %0)
%4 = icmp eq %struct.dirent* %3, null
br i1 %4, label %123, label %5
5: ; preds = %2, %115
%6 = phi %struct.dirent* [ %116, %115 ], [ %3, %2 ]
store i32 0, i32* %1
%7 = getelementptr inbounds %struct.dirent, %struct.dirent* %6, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 100
br i1 %11, label %12, label %115
12: ; preds = %5
%13 = load i8, i8* %8
switch i8 %13, label %115 [
i8 104, label %14
i8 115, label %14
]
14: ; preds = %12, %12
%15 = load i32, i32* @NAME_MAX
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
%19 = alloca i8, i64 %17
%20 = load i32, i32* @NAME_MAX
%21 = add nsw i32 %20, 1
%22 = zext i32 %21 to i64
%23 = alloca i8, i64 %22
%24 = load i8*, i8** %7
%25 = call i32* @hdopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = ptrtoint i32* %25 to i64
switch i64 %26, label %27 [
i64 -1, label %113
i64 0, label %114
]
27: ; preds = %14
%28 = call i32 @getc(i32* %25)
%29 = call i32 @fclose(i32* %25)
%30 = icmp eq i32 %28, 48
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = load i32, i32* %1
%33 = or i32 %32, 8
store i32 %33, i32* %1
br label %34
34: ; preds = %31, %27
%35 = load i8*, i8** %7
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 104
br i1 %37, label %38, label %48
38: ; preds = %34
%39 = load i32, i32* %1
%40 = and i32 %39, 8
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %114
42: ; preds = %38
%43 = or i32 %39, 1
store i32 %43, i32* %1
%44 = call i32 @flush_cache_ext(i8* %35)
%45 = icmp eq i32 %44, 0
br i1 %45, label %121, label %46
46: ; preds = %42
%47 = icmp slt i32 %44, 0
br i1 %47, label %113, label %118
48: ; preds = %34
%49 = call i32 @snprintf(i8* %19, i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%50 = icmp sgt i32 %49, %15
%51 = icmp slt i32 %49, 0
%52 = or i1 %50, %51
br i1 %52, label %113, label %53
53: ; preds = %48
%54 = call i32 @readlink(i8* %19, i8* %23, i32 %21)
%55 = icmp sgt i32 %54, %20
br i1 %55, label %113, label %56
56: ; preds = %53
%57 = icmp slt i32 %54, 0
br i1 %57, label %58, label %62
58: ; preds = %56
%59 = load i64, i64* @errno
%60 = load i64, i64* @ENOENT
%61 = icmp eq i64 %59, %60
br i1 %61, label %114, label %113
62: ; preds = %56
%63 = zext i32 %54 to i64
%64 = getelementptr inbounds i8, i8* %23, i64 %63
store i8 0, i8* %64
%65 = call i8* @basename(i8* %23)
%66 = icmp eq i8* %65, null
br i1 %66, label %114, label %67
67: ; preds = %62
%68 = load i8, i8* %65
%69 = icmp eq i8 %68, 0
br i1 %69, label %114, label %70
70: ; preds = %67
%71 = call i32* @hdopen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %65)
%72 = ptrtoint i32* %71 to i64
switch i64 %72, label %73 [
i64 -1, label %113
i64 0, label %80
]
73: ; preds = %70
%74 = call i32 @getc(i32* %71)
%75 = call i32 @fclose(i32* %71)
%76 = icmp eq i32 %74, 48
br i1 %76, label %80, label %77
77: ; preds = %73
%78 = load i32, i32* %1
%79 = or i32 %78, 16
store i32 %79, i32* %1
br label %114
80: ; preds = %70, %73
%81 = load i8*, i8** %7
%82 = call i32* @hdopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %81)
%83 = ptrtoint i32* %82 to i64
switch i64 %83, label %84 [
i64 -1, label %113
i64 0, label %114
]
84: ; preds = %80
%85 = call i8* @fgets(i8* %19, i32 %16, i32* %82)
%86 = call i32 @fclose(i32* %82)
%87 = icmp eq i8* %85, null
br i1 %87, label %114, label %88
88: ; preds = %84
%89 = call i8* @strstrip(i8* %19)
%90 = load i8, i8* %89
%91 = icmp eq i8 %90, 0
br i1 %91, label %114, label %92
92: ; preds = %88
%93 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%94 = icmp eq i64 %93, 0
%95 = load i32, i32* %1
%96 = and i32 %95, 8
%97 = icmp eq i32 %96, 0
br i1 %94, label %98, label %106
98: ; preds = %92
br i1 %97, label %99, label %114
99: ; preds = %98
%100 = or i32 %95, 3
store i32 %100, i32* %1
%101 = load i8*, i8** %7
%102 = call i32 @flush_cache_ext(i8* %101)
%103 = icmp eq i32 %102, 0
br i1 %103, label %121, label %104
104: ; preds = %99
%105 = icmp slt i32 %102, 0
br i1 %105, label %113, label %118
106: ; preds = %92
br i1 %97, label %114, label %107
107: ; preds = %106
%108 = load i8*, i8** %7
%109 = call i32 @flush_cache_ext(i8* %108)
%110 = icmp eq i32 %109, 0
br i1 %110, label %121, label %111
111: ; preds = %107
%112 = icmp slt i32 %109, 0
br i1 %112, label %113, label %118
113: ; preds = %14, %48, %53, %58, %70, %80, %46, %104, %111
br label %123
114: ; preds = %58, %80, %14, %106, %98, %88, %84, %62, %67, %38, %77
br label %115
115: ; preds = %5, %12, %114
%116 = call %struct.dirent* @readdir(i32* %0)
%117 = icmp eq %struct.dirent* %116, null
br i1 %117, label %123, label %5
118: ; preds = %111, %104, %46
%119 = load i32, i32* %1
%120 = or i32 %119, 4
store i32 %120, i32* %1
br label %121
121: ; preds = %118, %107, %99, %42
%122 = load i8*, i8** %7
br label %123
123: ; preds = %115, %2, %113, %121
%124 = phi i8* [ %122, %121 ], [ null, %113 ], [ null, %2 ], [ null, %115 ]
ret i8* %124
}