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

/* Variables and functions */
scalar_t__ EISDIR;
scalar_t__ ENOENT;
int /*<<< orphan*/ SEEK_CUR;
int closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
int fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int ret;
  FILE *f;
  DIR *dir;
  struct dirent *dirent;
  char buf[64];
  f = fopen("/dummy-pseudo-fs", "r");
  if (f != NULL || errno != ENOENT) {
    perror("(sanity check) fopen of dummy non-existing pseudo-FS did not fail "
           "with ENOENT");
    return 1;
  }
  f = fopen("/dev", "r+");
  if (f != NULL || errno != EISDIR) {
    perror("(sanity check) fopen of /dev did not fail with EISDIR");
    return 1;
  }
  f = fopen("/dev/dummy", "r");
  if (f != NULL || errno != ENOENT) {
    perror("(sanity check) fopen of /dev/dummy (non-existing file) did not "
           "fail with ENOENT");
    return 1;
  }
  printf("===== Contents of /dev\n");
  dir = opendir("/dev");
  if (!dir) {
    perror("opendir /dev");
    return 1;
  }
  errno = 0;
  while ((dirent = readdir(dir))) {
    printf("/dev/%s\n", dirent->d_name);
  }
  if (errno) {
    perror("readdir /dev");
    return 1;
  }
  ret = closedir(dir);
  if (ret < 0) {
    perror("closedir /dev");
    return 1;
  }
  printf("===== Read from /dev/urandom\n");
  f = fopen("/dev/urandom", "r");
  if (!f) {
    perror("fopen /dev/urandom");
    return 1;
  }
  ret = fseek(f, 0, SEEK_CUR);
  if (ret < 0) {
    perror("fseek /dev/urandom");
    return 1;
  }
  memset(buf, 0, sizeof(buf));
  ret = fread(buf, 1, sizeof(buf), f);
  if (ferror(f)) {
    perror("fread /dev/urandom");
    return 1;
  }
  printf("Four bytes from /dev/urandom:");
  for (int i = 0; i < 4; i++)
    printf(" %02hhx", (unsigned char)buf[i]);
  printf("\n");
  ret = fclose(f);
  if (ret) {
    perror("fclose /dev/urandom");
    return 1;
  }
  printf("===== Write to /dev/null\n");
  f = fopen("/dev/null", "w");
  if (!f) {
    perror("fopen /dev/null");
    return 1;
  }
  ret = fseek(f, 0, SEEK_CUR);
  if (ret < 0) {
    perror("fseek /dev/null");
    return 1;
  }
  ret = fwrite(buf, 1, sizeof(buf), f);
  if (ret < sizeof(buf)) {
    perror("fwrite /dev/null");
    return 1;
  }
  ret = fclose(f);
  if (ret) {
    perror("fclose /dev/null");
    return 1;
  }
  puts("TEST OK!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe10(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1225 <main+0x55>
mov    0x2dbe(%rip),%rax
mov    (%rax),%rax
mov    0x2da4(%rip),%rcx
cmp    (%rcx),%rax
je     123d <main+0x6d>
lea    0xde7(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
lea    0xee7(%rip),%rdi
lea    0xe16(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1279 <main+0xa9>
mov    0x2d6a(%rip),%rax
mov    (%rax),%rax
mov    0x2d70(%rip),%rcx
cmp    (%rcx),%rax
je     1291 <main+0xc1>
lea    0xde4(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
lea    0xe02(%rip),%rdi
lea    0xd72(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12cd <main+0xfd>
mov    0x2d16(%rip),%rax
mov    (%rax),%rax
mov    0x2cfc(%rip),%rcx
cmp    (%rcx),%rax
je     12e5 <main+0x115>
lea    0xdd1(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe31(%rip),%rdi
call   1070 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1326 <main+0x156>
lea    0xdf8(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
mov    0x2ca3(%rip),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1365 <main+0x195>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1334 <main+0x164>
mov    0x2c64(%rip),%rax
cmpq   $0x0,(%rax)
je     138e <main+0x1be>
lea    0xda6(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
mov    -0x28(%rbp),%rdi
call   10a0 <closedir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    13bc <main+0x1ec>
lea    0xd85(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xdb7(%rip),%rdi
lea    0xc39(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1404 <main+0x234>
lea    0xd69(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
mov    -0x20(%rbp),%rdi
mov    0x2bd9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    143d <main+0x26d>
lea    0xd43(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1090 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x40,%edx
call   1050 <fread@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1492 <main+0x2c2>
lea    0xd01(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x74(%rbp)
cmpl   $0x4,-0x74(%rbp)
jge    14d6 <main+0x306>
movslq -0x74(%rbp),%rax
movzbl -0x70(%rbp,%rax,1),%esi
lea    0xcf2(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    14a7 <main+0x2d7>
lea    0xd0a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1512 <main+0x342>
lea    0xcba(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xcfc(%rip),%rdi
lea    0xcbb(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    155a <main+0x38a>
lea    0xca2(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
mov    -0x20(%rbp),%rdi
mov    0x2a83(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1593 <main+0x3c3>
lea    0xc79(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x40,%edx
call   10f0 <fwrite@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x40,%rax
jae    15d3 <main+0x403>
lea    0xc49(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1601 <main+0x431>
lea    0xc2c(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1614 <main+0x444>
lea    0xc25(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xe0f(%rip),%rdi
lea    0xe19(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
jne    146b <main+0x28b>
mov    0x2dc3(%rip),%r14
mov    (%r14),%rax
mov    0x2da9(%rip),%rbx
cmp    (%rbx),%rax
jne    146b <main+0x28b>
lea    0xfd1(%rip),%rdi
lea    0xe33(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
jne    1477 <main+0x297>
mov    (%r14),%rax
mov    0x2d9a(%rip),%rcx
cmp    (%rcx),%rax
jne    1477 <main+0x297>
lea    0xe44(%rip),%rdi
lea    0xdb4(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
jne    1483 <main+0x2a3>
mov    (%r14),%rax
cmp    (%rbx),%rax
jne    1483 <main+0x2a3>
lea    0xf68(%rip),%rdi
call   1040 <puts@plt>
lea    0xf6e(%rip),%rdi
call   1080 <opendir@plt>
test   %rax,%rax
je     148c <main+0x2ac>
mov    %rax,%rbx
movq   $0x0,(%r14)
mov    %rax,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
je     12da <main+0xfa>
lea    0xe4c(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    (%rax),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
jne    12c0 <main+0xe0>
cmpq   $0x0,(%r14)
jne    1495 <main+0x2b5>
mov    %rbx,%rdi
call   10b0 <closedir@plt>
test   %eax,%eax
js     149e <main+0x2be>
lea    0xf02(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4b(%rip),%rdi
lea    0xd03(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     14a7 <main+0x2c7>
mov    %rax,%rbx
mov    0x2cc2(%rip),%r15
mov    (%r15),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
test   %eax,%eax
js     14b0 <main+0x2d0>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   10a0 <memset@plt>
mov    $0x1,%r14d
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x40,%edx
mov    %rbx,%rcx
call   1060 <fread@plt>
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    14b9 <main+0x2d9>
lea    0xddf(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
movzbl (%rsp),%esi
lea    0xdeb(%rip),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
movzbl 0x1(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
movzbl 0x2(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
movzbl 0x3(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
test   %eax,%eax
jne    14c7 <main+0x2e7>
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
lea    0xddd(%rip),%rdi
lea    0xd9c(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     14d5 <main+0x2f5>
mov    %rax,%rbx
mov    (%r15),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
test   %eax,%eax
js     14e3 <main+0x303>
mov    %rsp,%rdi
mov    $0x1,%r14d
mov    $0x1,%esi
mov    $0x40,%edx
mov    %rbx,%rcx
call   1100 <fwrite@plt>
cmp    $0x3f,%eax
jbe    14f1 <main+0x311>
mov    %rbx,%rdi
call   1070 <fclose@plt>
test   %eax,%eax
jne    14ff <main+0x31f>
lea    0xd7f(%rip),%rdi
call   1040 <puts@plt>
xor    %r14d,%r14d
jmp    1511 <main+0x331>
lea    0xba1(%rip),%rdi
jmp    1506 <main+0x326>
lea    0xbe6(%rip),%rdi
jmp    1506 <main+0x326>
lea    0xc1b(%rip),%rdi
jmp    1506 <main+0x326>
lea    0xc62(%rip),%rdi
jmp    1506 <main+0x326>
lea    0xc6f(%rip),%rdi
jmp    1506 <main+0x326>
lea    0xc73(%rip),%rdi
jmp    1506 <main+0x326>
lea    0xc78(%rip),%rdi
jmp    1506 <main+0x326>
lea    0xc82(%rip),%rdi
jmp    1506 <main+0x326>
lea    0xc8c(%rip),%rdi
call   10f0 <perror@plt>
jmp    1511 <main+0x331>
lea    0xcb7(%rip),%rdi
call   10f0 <perror@plt>
jmp    1511 <main+0x331>
lea    0xcbf(%rip),%rdi
call   10f0 <perror@plt>
jmp    1511 <main+0x331>
lea    0xcc1(%rip),%rdi
call   10f0 <perror@plt>
jmp    1511 <main+0x331>
lea    0xcc3(%rip),%rdi
call   10f0 <perror@plt>
jmp    1511 <main+0x331>
lea    0xcc6(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [17 x i8] c"/dummy-pseudo-fs\00"
@.str.1 = [2 x i8] c"r\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [78 x i8] c"(sanity check) fopen of dummy non-existing pseudo-FS did not fail with ENOENT\00"
@.str.3 = [5 x i8] c"/dev\00"
@.str.4 = [3 x i8] c"r+\00"
@EISDIR = global i64 0
@.str.5 = [54 x i8] c"(sanity check) fopen of /dev did not fail with EISDIR\00"
@.str.6 = [11 x i8] c"/dev/dummy\00"
@.str.7 = [80 x i8] c"(sanity check) fopen of /dev/dummy (non-existing file) did not fail with ENOENT\00"
@.str.8 = [24 x i8] c"===== Contents of /dev\0A\00"
@.str.9 = [13 x i8] c"opendir /dev\00"
@.str.10 = [9 x i8] c"/dev/%s\0A\00"
@.str.11 = [13 x i8] c"readdir /dev\00"
@.str.12 = [14 x i8] c"closedir /dev\00"
@.str.13 = [30 x i8] c"===== Read from /dev/urandom\0A\00"
@.str.14 = [13 x i8] c"/dev/urandom\00"
@.str.15 = [19 x i8] c"fopen /dev/urandom\00"
@SEEK_CUR = global i32 0
@.str.16 = [19 x i8] c"fseek /dev/urandom\00"
@.str.17 = [19 x i8] c"fread /dev/urandom\00"
@.str.18 = [30 x i8] c"Four bytes from /dev/urandom:\00"
@.str.19 = [8 x i8] c" %02hhx\00"
@.str.20 = [2 x i8] c"\0A\00"
@.str.21 = [20 x i8] c"fclose /dev/urandom\00"
@.str.22 = [26 x i8] c"===== Write to /dev/null\0A\00"
@.str.23 = [10 x i8] c"/dev/null\00"
@.str.24 = [2 x i8] c"w\00"
@.str.25 = [16 x i8] c"fopen /dev/null\00"
@.str.26 = [16 x i8] c"fseek /dev/null\00"
@.str.27 = [17 x i8] c"fwrite /dev/null\00"
@.str.28 = [17 x i8] c"fclose /dev/null\00"
@.str.29 = [9 x i8] c"TEST OK!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca %struct.dirent*
%10 = alloca [64 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp ne i32* %13, null
br i1 %14, label %19, label %15
15: ; preds = %2
%16 = load i64, i64* @errno
%17 = load i64, i64* @ENOENT
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15, %2
%20 = call i32 @perror(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %152
21: ; preds = %15
%22 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %22, i32** %7
%23 = load i32*, i32** %7
%24 = icmp ne i32* %23, null
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i64, i64* @errno
%27 = load i64, i64* @EISDIR
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25, %21
%30 = call i32 @perror(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %152
31: ; preds = %25
%32 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = icmp ne i32* %33, null
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = load i64, i64* @errno
%37 = load i64, i64* @ENOENT
%38 = icmp ne i64 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %35, %31
%40 = call i32 @perror(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %152
41: ; preds = %35
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%43 = call i32* @opendir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32* %43, i32** %8
%44 = load i32*, i32** %8
%45 = icmp ne i32* %44, null
br i1 %45, label %48, label %46
46: ; preds = %41
%47 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %3
br label %152
48: ; preds = %41
store i64 0, i64* @errno
br label %49
49: ; preds = %53, %48
%50 = load i32*, i32** %8
%51 = call %struct.dirent* @readdir(i32* %50)
store %struct.dirent* %51, %struct.dirent** %9
%52 = icmp ne %struct.dirent* %51, null
br i1 %52, label %53, label %58
53: ; preds = %49
%54 = load %struct.dirent*, %struct.dirent** %9
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %54, i32 0, i32 0
%56 = load i8*, i8** %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* %56)
br label %49
58: ; preds = %49
%59 = load i64, i64* @errno
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %3
br label %152
63: ; preds = %58
%64 = load i32*, i32** %8
%65 = call i32 @closedir(i32* %64)
store i32 %65, i32* %6
%66 = load i32, i32* %6
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %63
%69 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %3
br label %152
70: ; preds = %63
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.13, i64 0, i64 0))
%72 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %72, i32** %7
%73 = load i32*, i32** %7
%74 = icmp ne i32* %73, null
br i1 %74, label %77, label %75
75: ; preds = %70
%76 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.15, i64 0, i64 0))
store i32 1, i32* %3
br label %152
77: ; preds = %70
%78 = load i32*, i32** %7
%79 = load i32, i32* @SEEK_CUR
%80 = call i32 @fseek(i32* %78, i32 0, i32 %79)
store i32 %80, i32* %6
%81 = load i32, i32* %6
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %77
%84 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.16, i64 0, i64 0))
store i32 1, i32* %3
br label %152
85: ; preds = %77
%86 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%87 = call i32 @memset(i8* %86, i32 0, i32 64)
%88 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%89 = load i32*, i32** %7
%90 = call i32 @fread(i8* %88, i32 1, i32 64, i32* %89)
store i32 %90, i32* %6
%91 = load i32*, i32** %7
%92 = call i64 @ferror(i32* %91)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %96
94: ; preds = %85
%95 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.17, i64 0, i64 0))
store i32 1, i32* %3
br label %152
96: ; preds = %85
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.18, i64 0, i64 0))
store i32 0, i32* %11
br label %98
98: ; preds = %108, %96
%99 = load i32, i32* %11
%100 = icmp slt i32 %99, 4
br i1 %100, label %101, label %111
101: ; preds = %98
%102 = load i32, i32* %11
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 %103
%105 = load i8, i8* %104
%106 = zext i8 %105 to i32
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.19, i64 0, i64 0), i32 %106)
br label %108
108: ; preds = %101
%109 = load i32, i32* %11
%110 = add nsw i32 %109, 1
store i32 %110, i32* %11
br label %98
111: ; preds = %98
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.20, i64 0, i64 0))
%113 = load i32*, i32** %7
%114 = call i32 @fclose(i32* %113)
store i32 %114, i32* %6
%115 = load i32, i32* %6
%116 = icmp ne i32 %115, 0
br i1 %116, label %117, label %119
117: ; preds = %111
%118 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.21, i64 0, i64 0))
store i32 1, i32* %3
br label %152
119: ; preds = %111
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.22, i64 0, i64 0))
%121 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.23, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.24, i64 0, i64 0))
store i32* %121, i32** %7
%122 = load i32*, i32** %7
%123 = icmp ne i32* %122, null
br i1 %123, label %126, label %124
124: ; preds = %119
%125 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.25, i64 0, i64 0))
store i32 1, i32* %3
br label %152
126: ; preds = %119
%127 = load i32*, i32** %7
%128 = load i32, i32* @SEEK_CUR
%129 = call i32 @fseek(i32* %127, i32 0, i32 %128)
store i32 %129, i32* %6
%130 = load i32, i32* %6
%131 = icmp slt i32 %130, 0
br i1 %131, label %132, label %134
132: ; preds = %126
%133 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.26, i64 0, i64 0))
store i32 1, i32* %3
br label %152
134: ; preds = %126
%135 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%136 = load i32*, i32** %7
%137 = call i32 @fwrite(i8* %135, i32 1, i32 64, i32* %136)
store i32 %137, i32* %6
%138 = load i32, i32* %6
%139 = sext i32 %138 to i64
%140 = icmp ult i64 %139, 64
br i1 %140, label %141, label %143
141: ; preds = %134
%142 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.27, i64 0, i64 0))
store i32 1, i32* %3
br label %152
143: ; preds = %134
%144 = load i32*, i32** %7
%145 = call i32 @fclose(i32* %144)
store i32 %145, i32* %6
%146 = load i32, i32* %6
%147 = icmp ne i32 %146, 0
br i1 %147, label %148, label %150
148: ; preds = %143
%149 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.28, i64 0, i64 0))
store i32 1, i32* %3
br label %152
150: ; preds = %143
%151 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.29, i64 0, i64 0))
store i32 0, i32* %3
br label %152
152: ; preds = %150, %148, %141, %132, %124, %117, %94, %83, %75, %68, %61, %46, %39, %29, %19
%153 = load i32, i32* %3
ret i32 %153
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [17 x i8] c"/dummy-pseudo-fs\00"
@.str.1 = [2 x i8] c"r\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [78 x i8] c"(sanity check) fopen of dummy non-existing pseudo-FS did not fail with ENOENT\00"
@.str.3 = [5 x i8] c"/dev\00"
@.str.4 = [3 x i8] c"r+\00"
@EISDIR = global i64 0
@.str.5 = [54 x i8] c"(sanity check) fopen of /dev did not fail with EISDIR\00"
@.str.6 = [11 x i8] c"/dev/dummy\00"
@.str.7 = [80 x i8] c"(sanity check) fopen of /dev/dummy (non-existing file) did not fail with ENOENT\00"
@.str.9 = [13 x i8] c"opendir /dev\00"
@.str.10 = [9 x i8] c"/dev/%s\0A\00"
@.str.11 = [13 x i8] c"readdir /dev\00"
@.str.12 = [14 x i8] c"closedir /dev\00"
@.str.14 = [13 x i8] c"/dev/urandom\00"
@.str.15 = [19 x i8] c"fopen /dev/urandom\00"
@SEEK_CUR = global i32 0
@.str.16 = [19 x i8] c"fseek /dev/urandom\00"
@.str.17 = [19 x i8] c"fread /dev/urandom\00"
@.str.18 = [30 x i8] c"Four bytes from /dev/urandom:\00"
@.str.19 = [8 x i8] c" %02hhx\00"
@.str.21 = [20 x i8] c"fclose /dev/urandom\00"
@.str.23 = [10 x i8] c"/dev/null\00"
@.str.24 = [2 x i8] c"w\00"
@.str.25 = [16 x i8] c"fopen /dev/null\00"
@.str.26 = [16 x i8] c"fseek /dev/null\00"
@.str.27 = [17 x i8] c"fwrite /dev/null\00"
@.str.28 = [17 x i8] c"fclose /dev/null\00"
@.str.29 = [9 x i8] c"TEST OK!\00"
@str = [23 x i8] c"===== Contents of /dev\00"
@str.30 = [29 x i8] c"===== Read from /dev/urandom\00"
@str.31 = [25 x i8] c"===== Write to /dev/null\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENOENT
%10 = icmp eq i64 %8, %9
br i1 %10, label %13, label %11
11: ; preds = %7, %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
br label %122
13: ; preds = %7
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i64, i64* @errno
%18 = load i64, i64* @EISDIR
%19 = icmp eq i64 %17, %18
br i1 %19, label %22, label %20
20: ; preds = %16, %13
%21 = tail call i32 @perror(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0))
br label %122
22: ; preds = %16
%23 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i64, i64* @errno
%27 = load i64, i64* @ENOENT
%28 = icmp eq i64 %26, %27
br i1 %28, label %31, label %29
29: ; preds = %25, %22
%30 = tail call i32 @perror(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.7, i64 0, i64 0))
br label %122
31: ; preds = %25
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%33 = tail call i32* @opendir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
br label %122
37: ; preds = %31
store i64 0, i64* @errno
%38 = tail call %struct.dirent* @readdir(i32* %33)
%39 = icmp eq %struct.dirent* %38, null
br i1 %39, label %47, label %40
40: ; preds = %37, %40
%41 = phi %struct.dirent* [ %45, %40 ], [ %38, %37 ]
%42 = getelementptr inbounds %struct.dirent, %struct.dirent* %41, i64 0, i32 0
%43 = load i8*, i8** %42
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* %43)
%45 = tail call %struct.dirent* @readdir(i32* %33)
%46 = icmp eq %struct.dirent* %45, null
br i1 %46, label %47, label %40
47: ; preds = %40, %37
%48 = load i64, i64* @errno
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %47
%51 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
br label %122
52: ; preds = %47
%53 = tail call i32 @closedir(i32* %33)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %122
57: ; preds = %52
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.30, i64 0, i64 0))
%59 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.15, i64 0, i64 0))
br label %122
63: ; preds = %57
%64 = load i32, i32* @SEEK_CUR
%65 = tail call i32 @fseek(i32* %59, i32 0, i32 %64)
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.16, i64 0, i64 0))
br label %122
69: ; preds = %63
%70 = call i32 @memset(i8* %4, i32 0, i32 64)
%71 = call i32 @fread(i8* %4, i32 1, i32 64, i32* %59)
%72 = call i64 @ferror(i32* %59)
%73 = icmp eq i64 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %69
%75 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.17, i64 0, i64 0))
br label %122
76: ; preds = %69
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.18, i64 0, i64 0))
%78 = load i8, i8* %4
%79 = zext i8 %78 to i32
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.19, i64 0, i64 0), i32 %79)
%81 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 1
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.19, i64 0, i64 0), i32 %83)
%85 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 2
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.19, i64 0, i64 0), i32 %87)
%89 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 3
%90 = load i8, i8* %89
%91 = zext i8 %90 to i32
%92 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.19, i64 0, i64 0), i32 %91)
%93 = call i32 @putchar(i32 10)
%94 = call i32 @fclose(i32* %59)
%95 = icmp eq i32 %94, 0
br i1 %95, label %98, label %96
96: ; preds = %76
%97 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.21, i64 0, i64 0))
br label %122
98: ; preds = %76
%99 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.31, i64 0, i64 0))
%100 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.23, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.24, i64 0, i64 0))
%101 = icmp eq i32* %100, null
br i1 %101, label %102, label %104
102: ; preds = %98
%103 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.25, i64 0, i64 0))
br label %122
104: ; preds = %98
%105 = load i32, i32* @SEEK_CUR
%106 = call i32 @fseek(i32* %100, i32 0, i32 %105)
%107 = icmp slt i32 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %104
%109 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.26, i64 0, i64 0))
br label %122
110: ; preds = %104
%111 = call i32 @fwrite(i8* %4, i32 1, i32 64, i32* %100)
%112 = icmp ult i32 %111, 64
br i1 %112, label %113, label %115
113: ; preds = %110
%114 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.27, i64 0, i64 0))
br label %122
115: ; preds = %110
%116 = call i32 @fclose(i32* %100)
%117 = icmp eq i32 %116, 0
br i1 %117, label %120, label %118
118: ; preds = %115
%119 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.28, i64 0, i64 0))
br label %122
120: ; preds = %115
%121 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.29, i64 0, i64 0))
br label %122
122: ; preds = %120, %118, %113, %108, %102, %96, %74, %67, %61, %55, %50, %35, %29, %20, %11
%123 = phi i32 [ 1, %11 ], [ 1, %20 ], [ 1, %29 ], [ 1, %50 ], [ 1, %55 ], [ 1, %67 ], [ 1, %74 ], [ 1, %96 ], [ 1, %108 ], [ 1, %113 ], [ 1, %118 ], [ 0, %120 ], [ 1, %102 ], [ 1, %61 ], [ 1, %35 ]
ret i32 %123
}