#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 ((long)fp <= 0) {
        if ((long)fp < 0)
          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 ((long)fp <= 0) {
        if ((long)fp < 0)
          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 ((long)fp <= 0) {
        if ((long)fp < 0)
          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     16a0 <list_disks+0x4f0>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    169b <list_disks+0x4eb>
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    169b <list_disks+0x4eb>
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),%rax
cmp    $0x0,%rax
jg     12c1 <list_disks+0x111>
mov    -0x48(%rbp),%rax
cmp    $0x0,%rax
jge    12b5 <list_disks+0x105>
movl   $0x4,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
movl   $0x2,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
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     12eb <list_disks+0x13b>
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    136c <list_disks+0x1bc>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     131c <list_disks+0x16c>
movl   $0x2,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
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     1360 <list_disks+0x1b0>
cmpl   $0x0,-0x4c(%rbp)
jge    1355 <list_disks+0x1a5>
movl   $0x4,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x4,%ecx
mov    %ecx,(%rax)
movl   $0x3,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
mov    -0x70(%rbp),%rax
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xc94(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x70(%rbp),%rcx
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
jge    13a5 <list_disks+0x1f5>
cmpl   $0x0,-0x4c(%rbp)
jge    13b1 <list_disks+0x201>
movl   $0x4,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
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     13e2 <list_disks+0x232>
movl   $0x4,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
cmpl   $0x0,-0x4c(%rbp)
jge    141e <list_disks+0x26e>
mov    0x2bed(%rip),%rax
mov    (%rax),%rax
mov    0x2bd3(%rip),%rcx
cmp    (%rcx),%rax
je     1412 <list_disks+0x262>
movl   $0x4,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
movl   $0x2,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
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     144b <list_disks+0x29b>
mov    -0x40(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1457 <list_disks+0x2a7>
movl   $0x2,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
mov    -0x40(%rbp),%rsi
lea    0xbcb(%rip),%rdi
call   10c0 <hdopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    $0x0,%rax
jg     1498 <list_disks+0x2e8>
mov    -0x48(%rbp),%rax
cmp    $0x0,%rax
jge    1493 <list_disks+0x2e3>
movl   $0x4,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
jmp    14d3 <list_disks+0x323>
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     14ce <list_disks+0x31e>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x10,%ecx
mov    %ecx,(%rax)
movl   $0x2,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
jmp    14d3 <list_disks+0x323>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xb76(%rip),%rdi
call   10c0 <hdopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    $0x0,%rax
jg     151e <list_disks+0x36e>
mov    -0x48(%rbp),%rax
cmp    $0x0,%rax
jge    1512 <list_disks+0x362>
movl   $0x4,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
movl   $0x2,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
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    1555 <list_disks+0x3a5>
movl   $0x2,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
mov    -0x68(%rbp),%rdi
call   1090 <strstrip@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    157e <list_disks+0x3ce>
movl   $0x2,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
mov    -0x68(%rbp),%rdi
mov    -0x70(%rbp),%rax
mov    %eax,%edx
lea    0xae4(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    160c <list_disks+0x45c>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     15bc <list_disks+0x40c>
movl   $0x2,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
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     1600 <list_disks+0x450>
cmpl   $0x0,-0x4c(%rbp)
jge    15f5 <list_disks+0x445>
movl   $0x4,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x4,%ecx
mov    %ecx,(%rax)
movl   $0x3,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0x8,%eax
cmp    $0x0,%eax
jne    162a <list_disks+0x47a>
movl   $0x2,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <flush_cache_ext@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
je     1663 <list_disks+0x4b3>
cmpl   $0x0,-0x4c(%rbp)
jge    1658 <list_disks+0x4a8>
movl   $0x4,-0x50(%rbp)
jmp    166a <list_disks+0x4ba>
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    1685 <list_disks+0x4d5>
mov    -0x74(%rbp),%eax
sub    $0x3,%eax
je     16a0 <list_disks+0x4f0>
jmp    1696 <list_disks+0x4e6>
jmp    16c0 <list_disks+0x510>
jmp    11c3 <list_disks+0x13>
cmpq   $0x0,-0x20(%rbp)
jne    16b0 <list_disks+0x500>
jmp    16c0 <list_disks+0x510>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    16c8 <list_disks+0x518>
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     143b <list_disks+0x28b>
mov    %rax,%rbx
mov    %r12,-0x48(%rbp)
jmp    11fc <list_disks+0x4c>
js     1437 <list_disks+0x287>
mov    -0x40(%rbp),%rsp
mov    %r12,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     143b <list_disks+0x28b>
movl   $0x0,0x0(%r13)
mov    (%rbx),%rax
cmpb   $0x64,0x1(%rax)
jne    11e8 <list_disks+0x38>
movzbl (%rax),%eax
cmp    $0x73,%al
je     1218 <list_disks+0x68>
cmp    $0x68,%al
jne    11e8 <list_disks+0x38>
mov    %rsp,-0x40(%rbp)
mov    0x2da5(%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    0xd93(%rip),%rdi
call   10c0 <hdopen@plt>
test   %rax,%rax
jle    11de <list_disks+0x2e>
mov    %rax,%r15
mov    %rax,%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     12a2 <list_disks+0xf2>
orb    $0x8,0x0(%r13)
mov    (%rbx),%rcx
cmpb   $0x68,(%rcx)
jne    12bf <list_disks+0x10f>
mov    0x0(%r13),%eax
test   $0x8,%al
mov    -0x48(%rbp),%r12
jne    11e4 <list_disks+0x34>
jmp    1414 <list_disks+0x264>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    0xd4a(%rip),%rdx
call   1070 <snprintf@plt>
cmp    -0x60(%rbp),%eax
mov    -0x48(%rbp),%r12
jg     1437 <list_disks+0x287>
test   %eax,%eax
js     1437 <list_disks+0x287>
mov    -0x30(%rbp),%rdi
mov    %r14,%rsi
mov    -0x50(%rbp),%rdx
call   1050 <readlink@plt>
cmp    -0x58(%rbp),%eax
jg     1437 <list_disks+0x287>
test   %eax,%eax
js     1341 <list_disks+0x191>
mov    %eax,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
call   10a0 <basename@plt>
test   %rax,%rax
je     11e4 <list_disks+0x34>
cmpb   $0x0,(%rax)
je     11e4 <list_disks+0x34>
lea    0xd00(%rip),%rdi
mov    %rax,%rsi
call   10c0 <hdopen@plt>
test   %rax,%rax
jg     1360 <list_disks+0x1b0>
jns    137c <list_disks+0x1cc>
jmp    1437 <list_disks+0x287>
mov    0x2c98(%rip),%rax
mov    (%rax),%rax
mov    0x2c7e(%rip),%rcx
cmp    (%rcx),%rax
je     11e4 <list_disks+0x34>
jmp    1437 <list_disks+0x287>
mov    %rax,%r14
mov    %rax,%rdi
call   10d0 <getc@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1060 <fclose@plt>
cmp    $0x30,%r15d
jne    13f5 <list_disks+0x245>
mov    (%rbx),%rsi
lea    0xcd1(%rip),%rdi
call   10c0 <hdopen@plt>
test   %rax,%rax
jle    11de <list_disks+0x2e>
mov    %rax,%r14
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
call   1080 <fgets@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1060 <fclose@plt>
test   %r15,%r15
je     11e4 <list_disks+0x34>
mov    -0x30(%rbp),%rdi
call   1090 <strstrip@plt>
cmpb   $0x0,(%rax)
je     11e4 <list_disks+0x34>
mov    -0x30(%rbp),%rdi
lea    0xc9b(%rip),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <strncmp@plt>
mov    0x0(%r13),%ecx
test   %rax,%rax
je     13ff <list_disks+0x24f>
test   $0x8,%cl
je     11e4 <list_disks+0x34>
jmp    140f <list_disks+0x25f>
orb    $0x10,0x0(%r13)
jmp    11e4 <list_disks+0x34>
test   $0x8,%cl
jne    11e4 <list_disks+0x34>
or     $0x3,%ecx
mov    %ecx,0x0(%r13)
mov    (%rbx),%rdi
jmp    141e <list_disks+0x26e>
or     $0x1,%eax
mov    %eax,0x0(%r13)
mov    %rcx,%rdi
call   1040 <flush_cache_ext@plt>
test   %eax,%eax
je     142e <list_disks+0x27e>
js     1437 <list_disks+0x287>
orb    $0x4,0x0(%r13)
mov    -0x40(%rbp),%rsp
mov    (%rbx),%rax
jmp    143d <list_disks+0x28d>
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 = %256, %253, %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 %257
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 %256
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 %256
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 sle i64 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %43
%61 = load i32*, i32** %11
%62 = ptrtoint i32* %61 to i64
%63 = icmp slt i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %60
store i32 4, i32* %13
br label %253
65: ; preds = %60
store i32 2, i32* %13
br label %253
66: ; preds = %43
%67 = load i32*, i32** %11
%68 = call i32 @getc(i32* %67)
store i32 %68, i32* %12
%69 = load i32*, i32** %11
%70 = call i32 @fclose(i32* %69)
%71 = load i32, i32* %12
%72 = icmp ne i32 %71, 48
br i1 %72, label %73, label %77
73: ; preds = %66
%74 = load i32*, i32** %5
%75 = load i32, i32* %74
%76 = or i32 %75, 8
store i32 %76, i32* %74
br label %77
77: ; preds = %73, %66
%78 = load %struct.dirent*, %struct.dirent** %6
%79 = getelementptr inbounds %struct.dirent, %struct.dirent* %78, i32 0, i32 0
%80 = load i8*, i8** %79
%81 = getelementptr inbounds i8, i8* %80, i64 0
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = icmp eq i32 %83, 104
br i1 %84, label %85, label %109
85: ; preds = %77
%86 = load i32*, i32** %5
%87 = load i32, i32* %86
%88 = and i32 %87, 8
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %91
90: ; preds = %85
store i32 2, i32* %13
br label %253
91: ; preds = %85
%92 = load i32*, i32** %5
%93 = load i32, i32* %92
%94 = or i32 %93, 1
store i32 %94, i32* %92
%95 = load %struct.dirent*, %struct.dirent** %6
%96 = getelementptr inbounds %struct.dirent, %struct.dirent* %95, i32 0, i32 0
%97 = load i8*, i8** %96
%98 = call i32 @flush_cache_ext(i8* %97)
store i32 %98, i32* %12
%99 = icmp ne i32 %98, 0
br i1 %99, label %100, label %108
100: ; preds = %91
%101 = load i32, i32* %12
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %104
103: ; preds = %100
store i32 4, i32* %13
br label %253
104: ; preds = %100
%105 = load i32*, i32** %5
%106 = load i32, i32* %105
%107 = or i32 %106, 4
store i32 %107, i32* %105
br label %108
108: ; preds = %104, %91
store i32 3, i32* %13
br label %253
109: ; preds = %77
%110 = trunc i64 %46 to i32
%111 = load %struct.dirent*, %struct.dirent** %6
%112 = getelementptr inbounds %struct.dirent, %struct.dirent* %111, i32 0, i32 0
%113 = load i8*, i8** %112
%114 = call i32 @snprintf(i8* %48, i32 %110, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %113)
store i32 %114, i32* %12
%115 = load i32, i32* %12
%116 = trunc i64 %46 to i32
%117 = icmp sge i32 %115, %116
br i1 %117, label %121, label %118
118: ; preds = %109
%119 = load i32, i32* %12
%120 = icmp slt i32 %119, 0
br i1 %120, label %121, label %122
121: ; preds = %118, %109
store i32 4, i32* %13
br label %253
122: ; preds = %118
%123 = trunc i64 %51 to i32
%124 = call i32 @readlink(i8* %48, i8* %52, i32 %123)
store i32 %124, i32* %12
%125 = load i32, i32* %12
%126 = trunc i64 %51 to i32
%127 = icmp sge i32 %125, %126
br i1 %127, label %128, label %129
128: ; preds = %122
store i32 4, i32* %13
br label %253
129: ; preds = %122
%130 = load i32, i32* %12
%131 = icmp slt i32 %130, 0
br i1 %131, label %132, label %138
132: ; preds = %129
%133 = load i64, i64* @errno
%134 = load i64, i64* @ENOENT
%135 = icmp ne i64 %133, %134
br i1 %135, label %136, label %137
136: ; preds = %132
store i32 4, i32* %13
br label %253
137: ; preds = %132
store i32 2, i32* %13
br label %253
138: ; preds = %129
%139 = load i32, i32* %12
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i8, i8* %52, i64 %140
store i8 0, i8* %141
%142 = call i8* @basename(i8* %52)
store i8* %142, i8** %10
%143 = load i8*, i8** %10
%144 = icmp ne i8* %143, null
br i1 %144, label %145, label %149
145: ; preds = %138
%146 = load i8*, i8** %10
%147 = load i8, i8* %146
%148 = icmp ne i8 %147, 0
br i1 %148, label %150, label %149
149: ; preds = %145, %138
store i32 2, i32* %13
br label %253
150: ; preds = %145
%151 = load i8*, i8** %10
%152 = call i32* @hdopen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %151)
store i32* %152, i32** %11
%153 = load i32*, i32** %11
%154 = ptrtoint i32* %153 to i64
%155 = icmp sle i64 %154, 0
br i1 %155, label %156, label %162
156: ; preds = %150
%157 = load i32*, i32** %11
%158 = ptrtoint i32* %157 to i64
%159 = icmp slt i64 %158, 0
br i1 %159, label %160, label %161
160: ; preds = %156
store i32 4, i32* %13
br label %253
161: ; preds = %156
br label %174
162: ; preds = %150
%163 = load i32*, i32** %11
%164 = call i32 @getc(i32* %163)
store i32 %164, i32* %12
%165 = load i32*, i32** %11
%166 = call i32 @fclose(i32* %165)
%167 = load i32, i32* %12
%168 = icmp ne i32 %167, 48
br i1 %168, label %169, label %173
169: ; preds = %162
%170 = load i32*, i32** %5
%171 = load i32, i32* %170
%172 = or i32 %171, 16
store i32 %172, i32* %170
store i32 2, i32* %13
br label %253
173: ; preds = %162
br label %174
174: ; preds = %173, %161
%175 = load %struct.dirent*, %struct.dirent** %6
%176 = getelementptr inbounds %struct.dirent, %struct.dirent* %175, i32 0, i32 0
%177 = load i8*, i8** %176
%178 = call i32* @hdopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %177)
store i32* %178, i32** %11
%179 = load i32*, i32** %11
%180 = ptrtoint i32* %179 to i64
%181 = icmp sle i64 %180, 0
br i1 %181, label %182, label %188
182: ; preds = %174
%183 = load i32*, i32** %11
%184 = ptrtoint i32* %183 to i64
%185 = icmp slt i64 %184, 0
br i1 %185, label %186, label %187
186: ; preds = %182
store i32 4, i32* %13
br label %253
187: ; preds = %182
store i32 2, i32* %13
br label %253
188: ; preds = %174
%189 = trunc i64 %46 to i32
%190 = load i32*, i32** %11
%191 = call i8* @fgets(i8* %48, i32 %189, i32* %190)
store i8* %191, i8** %10
%192 = load i32*, i32** %11
%193 = call i32 @fclose(i32* %192)
%194 = load i8*, i8** %10
%195 = icmp eq i8* %194, null
br i1 %195, label %196, label %197
196: ; preds = %188
store i32 2, i32* %13
br label %253
197: ; preds = %188
%198 = call i8* @strstrip(i8* %48)
store i8* %198, i8** %10
%199 = load i8*, i8** %10
%200 = load i8, i8* %199
%201 = sext i8 %200 to i32
%202 = icmp eq i32 %201, 0
br i1 %202, label %203, label %204
203: ; preds = %197
store i32 2, i32* %13
br label %253
204: ; preds = %197
%205 = trunc i64 %46 to i32
%206 = call i64 @strncmp(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %205)
%207 = icmp eq i64 %206, 0
br i1 %207, label %208, label %232
208: ; preds = %204
%209 = load i32*, i32** %5
%210 = load i32, i32* %209
%211 = and i32 %210, 8
%212 = icmp ne i32 %211, 0
br i1 %212, label %213, label %214
213: ; preds = %208
store i32 2, i32* %13
br label %253
214: ; preds = %208
%215 = load i32*, i32** %5
%216 = load i32, i32* %215
%217 = or i32 %216, 3
store i32 %217, i32* %215
%218 = load %struct.dirent*, %struct.dirent** %6
%219 = getelementptr inbounds %struct.dirent, %struct.dirent* %218, i32 0, i32 0
%220 = load i8*, i8** %219
%221 = call i32 @flush_cache_ext(i8* %220)
store i32 %221, i32* %12
%222 = icmp ne i32 %221, 0
br i1 %222, label %223, label %231
223: ; preds = %214
%224 = load i32, i32* %12
%225 = icmp slt i32 %224, 0
br i1 %225, label %226, label %227
226: ; preds = %223
store i32 4, i32* %13
br label %253
227: ; preds = %223
%228 = load i32*, i32** %5
%229 = load i32, i32* %228
%230 = or i32 %229, 4
store i32 %230, i32* %228
br label %231
231: ; preds = %227, %214
store i32 3, i32* %13
br label %253
232: ; preds = %204
%233 = load i32*, i32** %5
%234 = load i32, i32* %233
%235 = and i32 %234, 8
%236 = icmp eq i32 %235, 0
br i1 %236, label %237, label %238
237: ; preds = %232
store i32 2, i32* %13
br label %253
238: ; preds = %232
%239 = load %struct.dirent*, %struct.dirent** %6
%240 = getelementptr inbounds %struct.dirent, %struct.dirent* %239, i32 0, i32 0
%241 = load i8*, i8** %240
%242 = call i32 @flush_cache_ext(i8* %241)
store i32 %242, i32* %12
%243 = icmp ne i32 %242, 0
br i1 %243, label %244, label %252
244: ; preds = %238
%245 = load i32, i32* %12
%246 = icmp slt i32 %245, 0
br i1 %246, label %247, label %248
247: ; preds = %244
store i32 4, i32* %13
br label %253
248: ; preds = %244
%249 = load i32*, i32** %5
%250 = load i32, i32* %249
%251 = or i32 %250, 4
store i32 %251, i32* %249
br label %252
252: ; preds = %248, %238
store i32 3, i32* %13
br label %253
253: ; preds = %247, %226, %186, %160, %136, %128, %121, %103, %64, %252, %237, %231, %213, %203, %196, %187, %169, %149, %137, %108, %90, %65
%254 = load i8*, i8** %7
%255 = load i32, i32* %13
switch i32 %255, label %268 [
i32 2, label %14
i32 3, label %257
i32 4, label %265
]
256: ; preds = %35, %18
br label %14
257: ; preds = %253, %14
%258 = load %struct.dirent*, %struct.dirent** %6
%259 = icmp eq %struct.dirent* %258, null
br i1 %259, label %260, label %261
260: ; preds = %257
br label %265
261: ; preds = %257
%262 = load %struct.dirent*, %struct.dirent** %6
%263 = getelementptr inbounds %struct.dirent, %struct.dirent* %262, i32 0, i32 0
%264 = load i8*, i8** %263
store i8* %264, i8** %3
br label %266
265: ; preds = %260, %253
store i8* null, i8** %3
br label %266
266: ; preds = %265, %261
%267 = load i8*, i8** %3
ret i8* %267
268: ; preds = %253
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 %129, label %5
5: ; preds = %2, %121
%6 = phi %struct.dirent* [ %122, %121 ], [ %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 %121
12: ; preds = %5
%13 = load i8, i8* %8
switch i8 %13, label %121 [
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 = icmp slt i32* %25, inttoptr (i64 1 to i32*)
br i1 %26, label %27, label %29
27: ; preds = %14
%28 = icmp slt i32* %25, null
br i1 %28, label %119, label %120
29: ; preds = %14
%30 = call i32 @getc(i32* %25)
%31 = call i32 @fclose(i32* %25)
%32 = icmp eq i32 %30, 48
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = load i32, i32* %1
%35 = or i32 %34, 8
store i32 %35, i32* %1
br label %36
36: ; preds = %33, %29
%37 = load i8*, i8** %7
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 104
br i1 %39, label %40, label %50
40: ; preds = %36
%41 = load i32, i32* %1
%42 = and i32 %41, 8
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %120
44: ; preds = %40
%45 = or i32 %41, 1
store i32 %45, i32* %1
%46 = call i32 @flush_cache_ext(i8* %37)
%47 = icmp eq i32 %46, 0
br i1 %47, label %127, label %48
48: ; preds = %44
%49 = icmp slt i32 %46, 0
br i1 %49, label %119, label %124
50: ; preds = %36
%51 = call i32 @snprintf(i8* %19, i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%52 = icmp sgt i32 %51, %15
%53 = icmp slt i32 %51, 0
%54 = or i1 %52, %53
br i1 %54, label %119, label %55
55: ; preds = %50
%56 = call i32 @readlink(i8* %19, i8* %23, i32 %21)
%57 = icmp sgt i32 %56, %20
br i1 %57, label %119, label %58
58: ; preds = %55
%59 = icmp slt i32 %56, 0
br i1 %59, label %60, label %64
60: ; preds = %58
%61 = load i64, i64* @errno
%62 = load i64, i64* @ENOENT
%63 = icmp eq i64 %61, %62
br i1 %63, label %120, label %119
64: ; preds = %58
%65 = zext i32 %56 to i64
%66 = getelementptr inbounds i8, i8* %23, i64 %65
store i8 0, i8* %66
%67 = call i8* @basename(i8* %23)
%68 = icmp eq i8* %67, null
br i1 %68, label %120, label %69
69: ; preds = %64
%70 = load i8, i8* %67
%71 = icmp eq i8 %70, 0
br i1 %71, label %120, label %72
72: ; preds = %69
%73 = call i32* @hdopen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %67)
%74 = icmp slt i32* %73, inttoptr (i64 1 to i32*)
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = icmp slt i32* %73, null
br i1 %76, label %119, label %84
77: ; preds = %72
%78 = call i32 @getc(i32* %73)
%79 = call i32 @fclose(i32* %73)
%80 = icmp eq i32 %78, 48
br i1 %80, label %84, label %81
81: ; preds = %77
%82 = load i32, i32* %1
%83 = or i32 %82, 16
store i32 %83, i32* %1
br label %120
84: ; preds = %77, %75
%85 = load i8*, i8** %7
%86 = call i32* @hdopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %85)
%87 = icmp slt i32* %86, inttoptr (i64 1 to i32*)
br i1 %87, label %88, label %90
88: ; preds = %84
%89 = icmp slt i32* %86, null
br i1 %89, label %119, label %120
90: ; preds = %84
%91 = call i8* @fgets(i8* %19, i32 %16, i32* %86)
%92 = call i32 @fclose(i32* %86)
%93 = icmp eq i8* %91, null
br i1 %93, label %120, label %94
94: ; preds = %90
%95 = call i8* @strstrip(i8* %19)
%96 = load i8, i8* %95
%97 = icmp eq i8 %96, 0
br i1 %97, label %120, label %98
98: ; preds = %94
%99 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%100 = icmp eq i64 %99, 0
%101 = load i32, i32* %1
%102 = and i32 %101, 8
%103 = icmp eq i32 %102, 0
br i1 %100, label %104, label %112
104: ; preds = %98
br i1 %103, label %105, label %120
105: ; preds = %104
%106 = or i32 %101, 3
store i32 %106, i32* %1
%107 = load i8*, i8** %7
%108 = call i32 @flush_cache_ext(i8* %107)
%109 = icmp eq i32 %108, 0
br i1 %109, label %127, label %110
110: ; preds = %105
%111 = icmp slt i32 %108, 0
br i1 %111, label %119, label %124
112: ; preds = %98
br i1 %103, label %120, label %113
113: ; preds = %112
%114 = load i8*, i8** %7
%115 = call i32 @flush_cache_ext(i8* %114)
%116 = icmp eq i32 %115, 0
br i1 %116, label %127, label %117
117: ; preds = %113
%118 = icmp slt i32 %115, 0
br i1 %118, label %119, label %124
119: ; preds = %50, %55, %60, %75, %27, %88, %48, %110, %117
br label %129
120: ; preds = %60, %88, %27, %112, %104, %94, %90, %64, %69, %40, %81
br label %121
121: ; preds = %5, %12, %120
%122 = call %struct.dirent* @readdir(i32* %0)
%123 = icmp eq %struct.dirent* %122, null
br i1 %123, label %129, label %5
124: ; preds = %117, %110, %48
%125 = load i32, i32* %1
%126 = or i32 %125, 4
store i32 %126, i32* %1
br label %127
127: ; preds = %124, %113, %105, %44
%128 = load i8*, i8** %7
br label %129
129: ; preds = %121, %2, %119, %127
%130 = phi i8* [ %128, %127 ], [ null, %119 ], [ null, %2 ], [ null, %121 ]
ret i8* %130
}