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

/* Variables and functions */
int const *MAP_FAILED;
int MAP_FILE;
int MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int,
                           char *);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
scalar_t__ mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int, int,
                int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char *, int const *, int);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int);
size_t strlen(char const *);
int FindAndMapFifo(uint32_t const **ppau32Fifo, uint32_t *pcbFifo, int rcExit) {
  const char g_szDir[] = "/sys/bus/pci/devices";
  DIR *pDir = opendir(g_szDir);
  if (pDir) {
    struct dirent *pEntry;
    char szPath[4096];
    size_t offPath = sizeof(g_szDir);
    memcpy(szPath, g_szDir, sizeof(g_szDir));
    szPath[offPath - 1] = '/';
    while ((pEntry = readdir(pDir)) != NULL) {
      struct stat st;
      size_t cchName = strlen(pEntry->d_name);
      memcpy(&szPath[offPath], pEntry->d_name, cchName);
      strcpy(&szPath[offPath + cchName], "/boot_vga");
      if (stat(szPath, &st) >= 0) {
        strcpy(&szPath[offPath + cchName], "/resource2");
        if (stat(szPath, &st) >= 0) {
          int fdFifo = open(szPath, O_RDONLY);
          if (fdFifo >= 0) {
            *pcbFifo = (uint32_t)st.st_size;
            *ppau32Fifo = (uint32_t *)mmap(NULL, *pcbFifo, PROT_READ,
                                           MAP_SHARED | MAP_FILE, fdFifo, 0);
            if (*ppau32Fifo != MAP_FAILED) {
              printf("info: Mapped %s at %p LB %#x\n", szPath, *ppau32Fifo,
                     *pcbFifo);
              close(fdFifo);
              closedir(pDir);
              return rcExit;
            }
            fprintf(stderr, "error: failed to mmap '%s': %d (%s)\n", szPath,
                    errno, strerror(errno));
            close(fdFifo);
          } else
            fprintf(stderr, "error: failed to open '%s': %d (%s)\n", g_szDir,
                    errno, strerror(errno));
        } else
          fprintf(stderr,
                  "error: boot_vga devices doesn't have '%s'. (%d [%s])\n",
                  szPath, errno, strerror(errno));
      }
    }
    closedir(pDir);
  } else
    fprintf(stderr, "error: failed to open '%s': %d (%s)\n", g_szDir, errno,
            strerror(errno));
  return 1;
}


x86 assembly (clang, -O0):
<FindAndMapFifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10b0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0xe13(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe10(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe0e(%rip),%eax
mov    %eax,-0x30(%rbp)
mov    0xe09(%rip),%al
mov    %al,-0x2c(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     152f <FindAndMapFifo+0x35f>
movq   $0x15,-0x1058(%rbp)
lea    -0x1050(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x15,%edx
call   10c0 <memcpy@plt>
mov    -0x1058(%rbp),%rax
sub    $0x1,%rax
movb   $0x2f,-0x1050(%rbp,%rax,1)
2f
mov    -0x48(%rbp),%rdi
call   10d0 <readdir@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
je     1521 <FindAndMapFifo+0x351>
mov    -0x50(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x1068(%rbp)
lea    -0x1050(%rbp),%rdi
add    -0x1058(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    (%rax),%rsi
mov    -0x1068(%rbp),%rdx
call   10c0 <memcpy@plt>
mov    -0x1058(%rbp),%rax
add    -0x1068(%rbp),%rax
lea    -0x1050(%rbp),%rdi
add    %rax,%rdi
lea    0xd52(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x1050(%rbp),%rdi
lea    -0x1060(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
jl     151c <FindAndMapFifo+0x34c>
mov    -0x1058(%rbp),%rax
add    -0x1068(%rbp),%rax
lea    -0x1050(%rbp),%rdi
add    %rax,%rdi
lea    0xd1b(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x1050(%rbp),%rdi
lea    -0x1060(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
jl     14bb <FindAndMapFifo+0x2eb>
lea    -0x1050(%rbp),%rdi
mov    0x2ca4(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x106c(%rbp)
cmpl   $0x0,-0x106c(%rbp)
jl     145d <FindAndMapFifo+0x28d>
mov    -0x1060(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    0x2c8e(%rip),%rax
mov    (%rax),%edx
mov    0x2c75(%rip),%rax
mov    (%rax),%ecx
mov    0x2c54(%rip),%rax
or     (%rax),%ecx
mov    -0x106c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2c07(%rip),%rcx
cmp    (%rcx),%rax
je     13f1 <FindAndMapFifo+0x221>
lea    -0x1050(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
lea    0xc5d(%rip),%rdi
call   1070 <printf@plt>
mov    -0x106c(%rbp),%edi
call   1080 <close@plt>
mov    -0x48(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    158f <FindAndMapFifo+0x3bf>
mov    0x2bc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x107c(%rbp)
lea    -0x1050(%rbp),%rax
mov    %rax,-0x1078(%rbp)
mov    0x2ba3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1070(%rbp)
mov    0x2b94(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x107c(%rbp),%edi
mov    -0x1078(%rbp),%rdx
mov    -0x1070(%rbp),%ecx
mov    %rax,%r8
lea    0xc00(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x106c(%rbp),%edi
call   1080 <close@plt>
jmp    14b6 <FindAndMapFifo+0x2e6>
mov    0x2b5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x108c(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x1088(%rbp)
mov    0x2b3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1080(%rbp)
mov    0x2b2b(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x108c(%rbp),%edi
mov    -0x1088(%rbp),%rdx
mov    -0x1080(%rbp),%ecx
mov    %rax,%r8
lea    0xbbc(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1517 <FindAndMapFifo+0x347>
mov    0x2afe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x109c(%rbp)
lea    -0x1050(%rbp),%rax
mov    %rax,-0x1098(%rbp)
mov    0x2ad9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1090(%rbp)
mov    0x2aca(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x109c(%rbp),%edi
mov    -0x1098(%rbp),%rdx
mov    -0x1090(%rbp),%ecx
mov    %rax,%r8
lea    0xb80(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    151c <FindAndMapFifo+0x34c>
jmp    1259 <FindAndMapFifo+0x89>
mov    -0x48(%rbp),%rdi
call   1090 <closedir@plt>
jmp    1588 <FindAndMapFifo+0x3b8>
mov    0x2a8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10ac(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x10a8(%rbp)
mov    0x2a68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10a0(%rbp)
mov    0x2a59(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x10ac(%rbp),%edi
mov    -0x10a8(%rbp),%rdx
mov    -0x10a0(%rbp),%ecx
mov    %rax,%r8
lea    0xaea(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindAndMapFifo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1048,%rsp
mov    %edx,%ebx
mov    %rsi,0x10(%rsp)
mov    %rdi,0x38(%rsp)
movaps 0xe0c(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movabs $0x73656369766564,%rax
mov    %rax,0x2d(%rsp)
lea    0x20(%rsp),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1406 <FindAndMapFifo+0x236>
mov    %rax,%r13
mov    %ebx,0xc(%rsp)
lea    0x40(%rsp),%r14
lea    0x20(%rsp),%rsi
mov    $0x15,%edx
mov    %r14,%rdi
call   10c0 <memcpy@plt>
movb   $0x2f,0x54(%rsp)
mov    %r13,%rdi
call   10d0 <readdir@plt>
test   %rax,%rax
je     13fc <FindAndMapFifo+0x22c>
lea    0x55(%rsp),%r12
lea    0xdba(%rip),%r15
mov    %r13,(%rsp)
jmp    12b0 <FindAndMapFifo+0xe0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2d49(%rip),%rax
mov    (%rax),%ebx
mov    0x2d38(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10f0 <strerror@plt>
mov    %ebx,%edi
lea    0xe00(%rip),%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %rax,%r8
call   10a0 <fprintf@plt>
mov    %r13,%rdi
call   10d0 <readdir@plt>
test   %rax,%rax
je     13fc <FindAndMapFifo+0x22c>
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   10c0 <memcpy@plt>
lea    (%r14,%rbp,1),%rbx
add    $0x15,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
lea    0x18(%rsp),%rsi
call   10b0 <stat@plt>
test   %rax,%rax
js     129f <FindAndMapFifo+0xcf>
mov    %rbx,%rdi
lea    0xd24(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
lea    0x18(%rsp),%rsi
call   10b0 <stat@plt>
test   %rax,%rax
js     1270 <FindAndMapFifo+0xa0>
mov    %r15,%r13
mov    %r12,%r15
mov    0x2cb5(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10e0 <open@plt>
test   %eax,%eax
js     13bc <FindAndMapFifo+0x1ec>
mov    %eax,%r12d
mov    0x18(%rsp),%esi
mov    0x10(%rsp),%rax
mov    %esi,(%rax)
mov    0x2cae(%rip),%rax
mov    (%rax),%edx
mov    0x2c7d(%rip),%rax
mov    (%rax),%ecx
mov    0x2c8c(%rip),%rax
or     (%rax),%ecx
xor    %edi,%edi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    0x38(%rsp),%rcx
mov    %rax,(%rcx)
mov    0x2c36(%rip),%rcx
cmp    %rax,(%rcx)
jne    144e <FindAndMapFifo+0x27e>
mov    0x2c36(%rip),%rax
mov    (%rax),%ebx
mov    0x2c25(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10f0 <strerror@plt>
mov    %ebx,%edi
lea    0xca3(%rip),%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %rax,%r8
call   10a0 <fprintf@plt>
mov    %r12d,%edi
call   1080 <close@plt>
jmp    13ed <FindAndMapFifo+0x21d>
mov    0x2bfd(%rip),%rax
mov    (%rax),%ebx
mov    0x2bec(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10f0 <strerror@plt>
mov    %ebx,%edi
lea    0xc8f(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %ebp,%ecx
mov    %rax,%r8
call   10a0 <fprintf@plt>
mov    %r15,%r12
mov    %r13,%r15
mov    (%rsp),%r13
jmp    129f <FindAndMapFifo+0xcf>
mov    %r13,%rdi
call   1090 <closedir@plt>
jmp    1437 <FindAndMapFifo+0x267>
mov    0x2bb3(%rip),%rax
mov    (%rax),%ebx
mov    0x2ba2(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10f0 <strerror@plt>
lea    0xc47(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %ebx,%edi
mov    %ebp,%ecx
mov    %rax,%r8
call   10a0 <fprintf@plt>
mov    $0x1,%eax
add    $0x1048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rcx
mov    (%rcx),%ecx
lea    0xbce(%rip),%rdi
lea    0x40(%rsp),%rsi
mov    %rax,%rdx
call   1070 <printf@plt>
mov    %r12d,%edi
call   1080 <close@plt>
mov    (%rsp),%rdi
call   1090 <closedir@plt>
mov    0xc(%rsp),%eax
jmp    143c <FindAndMapFifo+0x26c>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i64 }
@__const.FindAndMapFifo.g_szDir = [21 x i8] c"/sys/bus/pci/devices\00"
@.str = [10 x i8] c"/boot_vga\00"
@.str.1 = [11 x i8] c"/resource2\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FILE = global i32 0
@MAP_FAILED = global i32* null
@.str.2 = [30 x i8] c"info: Mapped %s at %p LB %#x\0A\00"
@stderr = global i32 0
@.str.3 = [37 x i8] c"error: failed to mmap '%s': %d (%s)\0A\00"
@errno = global i32 0
@.str.4 = [37 x i8] c"error: failed to open '%s': %d (%s)\0A\00"
@.str.5 = [54 x i8] c"error: boot_vga devices doesn't have '%s'. (%d [%s])\0A\00"
define i32 @FindAndMapFifo(i32** %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [21 x i8]
%9 = alloca i32*
%10 = alloca %struct.dirent*
%11 = alloca [4096 x i8]
%12 = alloca i64
%13 = alloca %struct.stat
%14 = alloca i64
%15 = alloca i32
store i32** %0, i32*** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%16 = bitcast [21 x i8]* %8 to i8*
%17 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%18 = call i32* @opendir(i8* %17)
store i32* %18, i32** %9
%19 = load i32*, i32** %9
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %127
21: ; preds = %3
store i64 21, i64* %12
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%23 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%24 = call i32 @memcpy(i8* %22, i8* %23, i64 21)
%25 = load i64, i64* %12
%26 = sub i64 %25, 1
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 %26
store i8 47, i8* %27
br label %28
28: ; preds = %123, %21
%29 = load i32*, i32** %9
%30 = call %struct.dirent* @readdir(i32* %29)
store %struct.dirent* %30, %struct.dirent** %10
%31 = icmp ne %struct.dirent* %30, null
br i1 %31, label %32, label %124
32: ; preds = %28
%33 = load %struct.dirent*, %struct.dirent** %10
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = call i64 @strlen(i8* %35)
store i64 %36, i64* %14
%37 = load i64, i64* %12
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 %37
%39 = load %struct.dirent*, %struct.dirent** %10
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %39, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = load i64, i64* %14
%43 = call i32 @memcpy(i8* %38, i8* %41, i64 %42)
%44 = load i64, i64* %12
%45 = load i64, i64* %14
%46 = add i64 %44, %45
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 %46
%48 = call i32 @strcpy(i8* %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%49 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%50 = call i64 @stat(i8* %49, %struct.stat* %13)
%51 = icmp sge i64 %50, 0
br i1 %51, label %52, label %123
52: ; preds = %32
%53 = load i64, i64* %12
%54 = load i64, i64* %14
%55 = add i64 %53, %54
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 %55
%57 = call i32 @strcpy(i8* %56, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%58 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%59 = call i64 @stat(i8* %58, %struct.stat* %13)
%60 = icmp sge i64 %59, 0
br i1 %60, label %61, label %115
61: ; preds = %52
%62 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%63 = load i32, i32* @O_RDONLY
%64 = call i32 @open(i8* %62, i32 %63)
store i32 %64, i32* %15
%65 = load i32, i32* %15
%66 = icmp sge i32 %65, 0
br i1 %66, label %67, label %107
67: ; preds = %61
%68 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%69 = load i64, i64* %68
%70 = trunc i64 %69 to i32
%71 = load i32*, i32** %6
store i32 %70, i32* %71
%72 = load i32*, i32** %6
%73 = load i32, i32* %72
%74 = load i32, i32* @PROT_READ
%75 = load i32, i32* @MAP_SHARED
%76 = load i32, i32* @MAP_FILE
%77 = or i32 %75, %76
%78 = load i32, i32* %15
%79 = call i64 @mmap(i32* null, i32 %73, i32 %74, i32 %77, i32 %78, i32 0)
%80 = inttoptr i64 %79 to i32*
%81 = load i32**, i32*** %5
store i32* %80, i32** %81
%82 = load i32**, i32*** %5
%83 = load i32*, i32** %82
%84 = load i32*, i32** @MAP_FAILED
%85 = icmp ne i32* %83, %84
br i1 %85, label %86, label %98
86: ; preds = %67
%87 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%88 = load i32**, i32*** %5
%89 = load i32*, i32** %88
%90 = load i32*, i32** %6
%91 = load i32, i32* %90
%92 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %87, i32* %89, i32 %91)
%93 = load i32, i32* %15
%94 = call i32 @close(i32 %93)
%95 = load i32*, i32** %9
%96 = call i32 @closedir(i32* %95)
%97 = load i32, i32* %7
store i32 %97, i32* %4
br label %135
98: ; preds = %67
%99 = load i32, i32* @stderr
%100 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%101 = load i32, i32* @errno
%102 = load i32, i32* @errno
%103 = call i8* @strerror(i32 %102)
%104 = call i32 @fprintf(i32 %99, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %100, i32 %101, i8* %103)
%105 = load i32, i32* %15
%106 = call i32 @close(i32 %105)
br label %114
107: ; preds = %61
%108 = load i32, i32* @stderr
%109 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%110 = load i32, i32* @errno
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 @fprintf(i32 %108, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %109, i32 %110, i8* %112)
br label %114
114: ; preds = %107, %98
br label %122
115: ; preds = %52
%116 = load i32, i32* @stderr
%117 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%118 = load i32, i32* @errno
%119 = load i32, i32* @errno
%120 = call i8* @strerror(i32 %119)
%121 = call i32 @fprintf(i32 %116, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* %117, i32 %118, i8* %120)
br label %122
122: ; preds = %115, %114
br label %123
123: ; preds = %122, %32
br label %28
124: ; preds = %28
%125 = load i32*, i32** %9
%126 = call i32 @closedir(i32* %125)
br label %134
127: ; preds = %3
%128 = load i32, i32* @stderr
%129 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%130 = load i32, i32* @errno
%131 = load i32, i32* @errno
%132 = call i8* @strerror(i32 %131)
%133 = call i32 @fprintf(i32 %128, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %129, i32 %130, i8* %132)
br label %134
134: ; preds = %127, %124
store i32 1, i32* %4
br label %135
135: ; preds = %134, %86
%136 = load i32, i32* %4
ret i32 %136
}

LLVM IR (-O2):
%struct.stat = type { i64 }
%struct.dirent = type { i8* }
@__const.FindAndMapFifo.g_szDir = [21 x i8] c"/sys/bus/pci/devices\00"
@.str = [10 x i8] c"/boot_vga\00"
@.str.1 = [11 x i8] c"/resource2\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FILE = global i32 0
@MAP_FAILED = global i32* null
@.str.2 = [30 x i8] c"info: Mapped %s at %p LB %#x\0A\00"
@stderr = global i32 0
@.str.3 = [37 x i8] c"error: failed to mmap '%s': %d (%s)\0A\00"
@errno = global i32 0
@.str.4 = [37 x i8] c"error: failed to open '%s': %d (%s)\0A\00"
@.str.5 = [54 x i8] c"error: boot_vga devices doesn't have '%s'. (%d [%s])\0A\00"
define i32 @FindAndMapFifo(i32** nocapture writeonly %0, i32* nocapture %1, i32 %2) {
%4 = alloca [21 x i8]
%5 = alloca [4096 x i8]
%6 = alloca %struct.stat
%7 = getelementptr inbounds [21 x i8], [21 x i8]* %4, i64 0, i64 0
%8 = call i32* @opendir(i8* %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %77, label %10
10: ; preds = %3
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%12 = call i32 @memcpy(i8* %11, i8* %7, i64 21)
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 20
store i8 47, i8* %13
%14 = call %struct.dirent* @readdir(i32* %8)
%15 = icmp eq %struct.dirent* %14, null
br i1 %15, label %69, label %16
16: ; preds = %10
%17 = bitcast %struct.stat* %6 to i8*
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 21
%19 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
br label %20
20: ; preds = %16, %66
%21 = phi %struct.dirent* [ %14, %16 ], [ %67, %66 ]
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = call i64 @strlen(i8* dereferenceable(1) %23)
%25 = call i32 @memcpy(i8* %18, i8* %23, i64 %24)
%26 = add i64 %24, 21
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %26
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%29 = call i64 @stat(i8* %11, %struct.stat* %6)
%30 = icmp sgt i64 %29, -1
br i1 %30, label %31, label %66
31: ; preds = %20
%32 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%33 = call i64 @stat(i8* %11, %struct.stat* %6)
%34 = icmp sgt i64 %33, -1
br i1 %34, label %35, label %61
35: ; preds = %31
%36 = load i32, i32* @O_RDONLY
%37 = call i32 @open(i8* %11, i32 %36)
%38 = icmp sgt i32 %37, -1
br i1 %38, label %39, label %56
39: ; preds = %35
%40 = load i64, i64* %19
%41 = trunc i64 %40 to i32
store i32 %41, i32* %1
%42 = load i32, i32* @PROT_READ
%43 = load i32, i32* @MAP_SHARED
%44 = load i32, i32* @MAP_FILE
%45 = or i32 %44, %43
%46 = call i64 @mmap(i32* null, i32 %41, i32 %42, i32 %45, i32 %37, i32 0)
%47 = inttoptr i64 %46 to i32*
store i32* %47, i32** %0
%48 = load i32*, i32** @MAP_FAILED
%49 = icmp eq i32* %48, %47
br i1 %49, label %50, label %71
50: ; preds = %39
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %11, i32 %52, i8* %53)
%55 = call i32 @close(i32 %37)
br label %66
56: ; preds = %35
%57 = load i32, i32* @stderr
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %7, i32 %58, i8* %59)
br label %66
61: ; preds = %31
%62 = load i32, i32* @stderr
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* %11, i32 %63, i8* %64)
br label %66
66: ; preds = %50, %56, %20, %61
%67 = call %struct.dirent* @readdir(i32* %8)
%68 = icmp eq %struct.dirent* %67, null
br i1 %68, label %69, label %20
69: ; preds = %66, %10
%70 = call i32 @closedir(i32* %8)
br label %82
71: ; preds = %39
%72 = inttoptr i64 %46 to i32*
%73 = load i32, i32* %1
%74 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %11, i32* %72, i32 %73)
%75 = call i32 @close(i32 %37)
%76 = call i32 @closedir(i32* %8)
br label %82
77: ; preds = %3
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = tail call i8* @strerror(i32 %79)
%81 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %7, i32 %79, i8* %80)
br label %82
82: ; preds = %77, %69, %71
%83 = phi i32 [ %2, %71 ], [ 1, %69 ], [ 1, %77 ]
ret i32 %83
}