#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct stat {
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  char const *d_name;
};
typedef int /*<<< orphan*/ nbuf;
typedef scalar_t__ dev_t;
typedef scalar_t__ __u32;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ __ploop_err(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
scalar_t__ get_dev_num(char *, scalar_t__ *);
int get_dev_start(char *, scalar_t__ *);
scalar_t__ lstat(char *, struct stat *);
scalar_t__ memcmp(char const *, char const *, size_t);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
size_t strlen(char const *);
int dev_num2dev_start(const char *device, dev_t dev_num, __u32 *dev_start) {
  char nbuf[4096];
  dev_t dev;
  DIR *dp;
  struct dirent *de;
  if (memcmp(device, "/dev/", 5) == 0)
    device += 5;
  snprintf(nbuf, sizeof(nbuf) - 1, "/sys/block/%s/dev", device);
  if (get_dev_num(nbuf, &dev))
    return -1;
  if (dev == dev_num) {
    *dev_start = 0;
    return 0;
  }
  snprintf(nbuf, sizeof(nbuf) - 1, "/sys/block/%s", device);
  dp = opendir(nbuf);
  if (dp == NULL) {
    __ploop_err(errno, "Can't opendir %s", nbuf);
    return -1;
  }
  while ((de = readdir(dp)) != NULL) {
    struct stat st;
    if (strlen(de->d_name) <= strlen(device) + 1 ||
        memcmp(de->d_name, device, strlen(device)) ||
        de->d_name[strlen(device)] != 'p')
      continue;
    snprintf(nbuf, sizeof(nbuf) - 1, "/sys/block/%s/%s", device, de->d_name);
    if (lstat(nbuf, &st)) {
      __ploop_err(errno, "Can't lstat %s", nbuf);
      goto close_dir;
    }
    if (!S_ISDIR(st.st_mode))
      continue;
    snprintf(nbuf, sizeof(nbuf) - 1, "/sys/block/%s/%s/dev", device,
             de->d_name);
    if (get_dev_num(nbuf, &dev))
      goto close_dir;
    if (dev == dev_num) {
      snprintf(nbuf, sizeof(nbuf) - 1, "/sys/block/%s/%s/start", device,
               de->d_name);
      closedir(dp);
      return get_dev_start(nbuf, dev_start);
    }
  }
  __ploop_err(0, "Can't find entry under /sys/block/%s with dev=%llx", device,
              (unsigned long long)dev_num);
close_dir:
  closedir(dp);
  return -1;
}


x86 assembly (clang, -O0):
<dev_num2dev_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1060,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe2e(%rip),%rsi
mov    $0x5,%edx
call   10a0 <memcmp@plt>
cmp    $0x0,%rax
jne    11f2 <dev_num2dev_start+0x42>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xfff,%esi
lea    0xdfd(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x1028(%rbp),%rsi
call   10c0 <get_dev_num@plt>
cmp    $0x0,%rax
je     1239 <dev_num2dev_start+0x89>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f5 <dev_num2dev_start+0x345>
mov    -0x1028(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1261 <dev_num2dev_start+0xb1>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    14f5 <dev_num2dev_start+0x345>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xfff,%esi
lea    0xda0(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x1030(%rbp)
cmpq   $0x0,-0x1030(%rbp)
jne    12ca <dev_num2dev_start+0x11a>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rdx
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   10d0 <__ploop_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f5 <dev_num2dev_start+0x345>
jmp    12cf <dev_num2dev_start+0x11f>
mov    -0x1030(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x1038(%rbp)
cmp    $0x0,%rax
je     14ca <dev_num2dev_start+0x31a>
mov    -0x1038(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x1048(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x1048(%rbp),%rax
add    $0x1,%rcx
cmp    %rcx,%rax
jbe    1398 <dev_num2dev_start+0x1e8>
mov    -0x1038(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x1058(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1050(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1058(%rbp),%rdi
mov    -0x1050(%rbp),%rsi
mov    %rax,%rdx
call   10a0 <memcmp@plt>
cmp    $0x0,%rax
jne    1398 <dev_num2dev_start+0x1e8>
mov    -0x1038(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x1060(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x1060(%rbp),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x70,%eax
je     139d <dev_num2dev_start+0x1ed>
jmp    12cf <dev_num2dev_start+0x11f>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x1038(%rbp),%rax
mov    (%rax),%r8
mov    $0xfff,%esi
lea    0xc79(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
call   1090 <lstat@plt>
cmp    $0x0,%rax
je     1405 <dev_num2dev_start+0x255>
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rdx
lea    0xc4f(%rip),%rsi
mov    $0x0,%al
call   10d0 <__ploop_err@plt>
jmp    14e2 <dev_num2dev_start+0x332>
mov    -0x1040(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    141e <dev_num2dev_start+0x26e>
jmp    12cf <dev_num2dev_start+0x11f>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x1038(%rbp),%rax
mov    (%rax),%r8
mov    $0xfff,%esi
lea    0xc18(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x1028(%rbp),%rsi
call   10c0 <get_dev_num@plt>
cmp    $0x0,%rax
je     1468 <dev_num2dev_start+0x2b8>
jmp    14e2 <dev_num2dev_start+0x332>
mov    -0x1028(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    14c5 <dev_num2dev_start+0x315>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x1038(%rbp),%rax
mov    (%rax),%r8
mov    $0xfff,%esi
lea    0xbd2(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    -0x1030(%rbp),%rdi
call   1080 <closedir@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <get_dev_start@plt>
mov    %eax,-0x4(%rbp)
jmp    14f5 <dev_num2dev_start+0x345>
jmp    12cf <dev_num2dev_start+0x11f>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
xor    %edi,%edi
lea    0xba8(%rip),%rsi
mov    $0x0,%al
call   10d0 <__ploop_err@plt>
mov    -0x1030(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dev_num2dev_start>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xe2f(%rip),%rsi
mov    $0x5,%edx
call   10a0 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,4),%rbx
add    %rbp,%rbx
lea    0xe15(%rip),%rdx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xfff,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   10c0 <get_dev_num@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
jne    13ed <dev_num2dev_start+0x23d>
cmp    %r15,0x8(%rsp)
jne    123a <dev_num2dev_start+0x8a>
movq   $0x0,(%r14)
xor    %r12d,%r12d
jmp    13ed <dev_num2dev_start+0x23d>
mov    %r15,0x10(%rsp)
lea    0xdd2(%rip),%rdx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xfff,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %rbp,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     13d1 <dev_num2dev_start+0x221>
mov    %rax,%r13
mov    %r14,0x18(%rsp)
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     13af <dev_num2dev_start+0x1ff>
mov    %rax,%rbp
jmp    12a4 <dev_num2dev_start+0xf4>
nopl   0x0(%rax)
mov    %r13,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     13af <dev_num2dev_start+0x1ff>
mov    0x0(%rbp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rcx
cmp    %rcx,%r15
jbe    1290 <dev_num2dev_start+0xe0>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   10a0 <memcmp@plt>
test   %rax,%rax
jne    1290 <dev_num2dev_start+0xe0>
mov    0x0(%rbp),%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmpb   $0x70,(%r14,%rax,1)
jne    1290 <dev_num2dev_start+0xe0>
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0xfff,%esi
lea    0xd39(%rip),%rdx
mov    %rbx,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %r15,%rdi
mov    %rsp,%rsi
call   1090 <lstat@plt>
test   %rax,%rax
jne    1402 <dev_num2dev_start+0x252>
mov    (%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %eax,%eax
je     1290 <dev_num2dev_start+0xe0>
mov    0x0(%rbp),%r8
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0xfff,%esi
lea    0xd10(%rip),%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %r14,%rdi
lea    0x8(%rsp),%rsi
call   10c0 <get_dev_num@plt>
test   %rax,%rax
jne    13c7 <dev_num2dev_start+0x217>
mov    0x10(%rsp),%rax
cmp    %rax,0x8(%rsp)
jne    1290 <dev_num2dev_start+0xe0>
mov    0x0(%rbp),%r8
lea    0xcee(%rip),%rdx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xfff,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %r13,%rdi
call   1080 <closedir@plt>
mov    %rbp,%rdi
mov    0x18(%rsp),%rsi
call   1060 <get_dev_start@plt>
mov    %eax,%r12d
jmp    13ed <dev_num2dev_start+0x23d>
lea    0xccd(%rip),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
mov    0x10(%rsp),%rcx
xor    %eax,%eax
call   10d0 <__ploop_err@plt>
mov    %r13,%rdi
call   1080 <closedir@plt>
jmp    13ed <dev_num2dev_start+0x23d>
mov    0x2c08(%rip),%rax
mov    (%rax),%edi
lea    0xc45(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   10d0 <__ploop_err@plt>
mov    %r12d,%eax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bd7(%rip),%rax
mov    (%rax),%edi
lea    0xc36(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   10d0 <__ploop_err@plt>
jmp    13c7 <dev_num2dev_start+0x217>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@.str = [6 x i8] c"/dev/\00"
@.str.1 = [18 x i8] c"/sys/block/%s/dev\00"
@.str.2 = [14 x i8] c"/sys/block/%s\00"
@errno = global i32 0
@.str.3 = [17 x i8] c"Can't opendir %s\00"
@.str.4 = [17 x i8] c"/sys/block/%s/%s\00"
@.str.5 = [15 x i8] c"Can't lstat %s\00"
@.str.6 = [21 x i8] c"/sys/block/%s/%s/dev\00"
@.str.7 = [23 x i8] c"/sys/block/%s/%s/start\00"
@.str.8 = [51 x i8] c"Can't find entry under /sys/block/%s with dev=%llx\00"
define i32 @dev_num2dev_start(i8* %0, i64 %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64*
%8 = alloca [4096 x i8]
%9 = alloca i64
%10 = alloca i32*
%11 = alloca %struct.dirent*
%12 = alloca %struct.stat
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64* %2, i64** %7
%13 = load i8*, i8** %5
%14 = call i64 @memcmp(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 5
store i8* %18, i8** %5
br label %19
19: ; preds = %16, %3
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%21 = load i8*, i8** %5
%22 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %20, i32 4095, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%24 = call i64 @get_dev_num(i8* %23, i64* %9)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 -1, i32* %4
br label %134
27: ; preds = %19
%28 = load i64, i64* %9
%29 = load i64, i64* %6
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i64*, i64** %7
store i64 0, i64* %32
store i32 0, i32* %4
br label %134
33: ; preds = %27
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%35 = load i8*, i8** %5
%36 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %34, i32 4095, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%38 = call i32* @opendir(i8* %37)
store i32* %38, i32** %10
%39 = load i32*, i32** %10
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %45
41: ; preds = %33
%42 = load i32, i32* @errno
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%44 = call i32 (i32, i8*, i8*, ...) @__ploop_err(i32 %42, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %43)
store i32 -1, i32* %4
br label %134
45: ; preds = %33
br label %46
46: ; preds = %126, %98, %78, %45
%47 = load i32*, i32** %10
%48 = call %struct.dirent* @readdir(i32* %47)
store %struct.dirent* %48, %struct.dirent** %11
%49 = icmp ne %struct.dirent* %48, null
br i1 %49, label %50, label %127
50: ; preds = %46
%51 = load %struct.dirent*, %struct.dirent** %11
%52 = getelementptr inbounds %struct.dirent, %struct.dirent* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = call i64 @strlen(i8* %53)
%55 = load i8*, i8** %5
%56 = call i64 @strlen(i8* %55)
%57 = add i64 %56, 1
%58 = icmp ule i64 %54, %57
br i1 %58, label %78, label %59
59: ; preds = %50
%60 = load %struct.dirent*, %struct.dirent** %11
%61 = getelementptr inbounds %struct.dirent, %struct.dirent* %60, i32 0, i32 0
%62 = load i8*, i8** %61
%63 = load i8*, i8** %5
%64 = load i8*, i8** %5
%65 = call i64 @strlen(i8* %64)
%66 = call i64 @memcmp(i8* %62, i8* %63, i64 %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %78, label %68
68: ; preds = %59
%69 = load %struct.dirent*, %struct.dirent** %11
%70 = getelementptr inbounds %struct.dirent, %struct.dirent* %69, i32 0, i32 0
%71 = load i8*, i8** %70
%72 = load i8*, i8** %5
%73 = call i64 @strlen(i8* %72)
%74 = getelementptr inbounds i8, i8* %71, i64 %73
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp ne i32 %76, 112
br i1 %77, label %78, label %79
78: ; preds = %68, %59, %50
br label %46
79: ; preds = %68
%80 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%81 = load i8*, i8** %5
%82 = load %struct.dirent*, %struct.dirent** %11
%83 = getelementptr inbounds %struct.dirent, %struct.dirent* %82, i32 0, i32 0
%84 = load i8*, i8** %83
%85 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %80, i32 4095, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %81, i8* %84)
%86 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%87 = call i64 @lstat(i8* %86, %struct.stat* %12)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %79
%90 = load i32, i32* @errno
%91 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%92 = call i32 (i32, i8*, i8*, ...) @__ploop_err(i32 %90, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %91)
br label %131
93: ; preds = %79
%94 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%95 = load i32, i32* %94
%96 = call i32 @S_ISDIR(i32 %95)
%97 = icmp ne i32 %96, 0
br i1 %97, label %99, label %98
98: ; preds = %93
br label %46
99: ; preds = %93
%100 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%101 = load i8*, i8** %5
%102 = load %struct.dirent*, %struct.dirent** %11
%103 = getelementptr inbounds %struct.dirent, %struct.dirent* %102, i32 0, i32 0
%104 = load i8*, i8** %103
%105 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %100, i32 4095, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %101, i8* %104)
%106 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%107 = call i64 @get_dev_num(i8* %106, i64* %9)
%108 = icmp ne i64 %107, 0
br i1 %108, label %109, label %110
109: ; preds = %99
br label %131
110: ; preds = %99
%111 = load i64, i64* %9
%112 = load i64, i64* %6
%113 = icmp eq i64 %111, %112
br i1 %113, label %114, label %126
114: ; preds = %110
%115 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%116 = load i8*, i8** %5
%117 = load %struct.dirent*, %struct.dirent** %11
%118 = getelementptr inbounds %struct.dirent, %struct.dirent* %117, i32 0, i32 0
%119 = load i8*, i8** %118
%120 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %115, i32 4095, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %116, i8* %119)
%121 = load i32*, i32** %10
%122 = call i32 @closedir(i32* %121)
%123 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%124 = load i64*, i64** %7
%125 = call i32 @get_dev_start(i8* %123, i64* %124)
store i32 %125, i32* %4
br label %134
126: ; preds = %110
br label %46
127: ; preds = %46
%128 = load i8*, i8** %5
%129 = load i64, i64* %6
%130 = call i32 (i32, i8*, i8*, ...) @__ploop_err(i32 0, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i8* %128, i64 %129)
br label %131
131: ; preds = %127, %109, %89
%132 = load i32*, i32** %10
%133 = call i32 @closedir(i32* %132)
store i32 -1, i32* %4
br label %134
134: ; preds = %131, %114, %41, %31, %26
%135 = load i32, i32* %4
ret i32 %135
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [6 x i8] c"/dev/\00"
@.str.1 = [18 x i8] c"/sys/block/%s/dev\00"
@.str.2 = [14 x i8] c"/sys/block/%s\00"
@errno = global i32 0
@.str.3 = [17 x i8] c"Can't opendir %s\00"
@.str.4 = [17 x i8] c"/sys/block/%s/%s\00"
@.str.5 = [15 x i8] c"Can't lstat %s\00"
@.str.6 = [21 x i8] c"/sys/block/%s/%s/dev\00"
@.str.7 = [23 x i8] c"/sys/block/%s/%s/start\00"
@.str.8 = [51 x i8] c"Can't find entry under /sys/block/%s with dev=%llx\00"
define i32 @dev_num2dev_start(i8* %0, i64 %1, i64* %2) {
%4 = alloca [4096 x i8]
%5 = alloca i64
%6 = alloca %struct.stat
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = bitcast i64* %5 to i8*
%9 = tail call i64 @memcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 5)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i64 5, i64 0
%12 = getelementptr i8, i8* %0, i64 %11
%13 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 4095, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i64 @get_dev_num(i8* %7, i64* %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %82
16: ; preds = %3
%17 = load i64, i64* %5
%18 = icmp eq i64 %17, %1
br i1 %18, label %19, label %20
19: ; preds = %16
store i64 0, i64* %2
br label %82
20: ; preds = %16
%21 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 4095, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%22 = call i32* @opendir(i8* %7)
%23 = icmp eq i32* %22, null
br i1 %23, label %30, label %24
24: ; preds = %20
%25 = call %struct.dirent* @readdir(i32* %22)
%26 = icmp eq %struct.dirent* %25, null
br i1 %26, label %78, label %27
27: ; preds = %24
%28 = bitcast %struct.stat* %6 to i8*
%29 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
br label %33
30: ; preds = %20
%31 = load i32, i32* @errno
%32 = call i32 (i32, i8*, i8*, ...) @__ploop_err(i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %7)
br label %82
33: ; preds = %27, %75
%34 = phi %struct.dirent* [ %25, %27 ], [ %76, %75 ]
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i64 0, i32 0
%36 = load i8*, i8** %35
%37 = call i64 @strlen(i8* dereferenceable(1) %36)
%38 = call i64 @strlen(i8* dereferenceable(1) %12)
%39 = add i64 %38, 1
%40 = icmp ugt i64 %37, %39
br i1 %40, label %41, label %75
41: ; preds = %33
%42 = call i64 @memcmp(i8* %36, i8* %12, i64 %38)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %75
44: ; preds = %41
%45 = load i8*, i8** %35
%46 = call i64 @strlen(i8* dereferenceable(1) %12)
%47 = getelementptr inbounds i8, i8* %45, i64 %46
%48 = load i8, i8* %47
%49 = icmp eq i8 %48, 112
br i1 %49, label %50, label %75
50: ; preds = %44
%51 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 4095, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %12, i8* %45)
%52 = call i64 @lstat(i8* %7, %struct.stat* %6)
%53 = icmp eq i64 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %50
%55 = load i32, i32* @errno
%56 = call i32 (i32, i8*, i8*, ...) @__ploop_err(i32 %55, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %7)
br label %74
57: ; preds = %50
%58 = load i32, i32* %29
%59 = call i32 @S_ISDIR(i32 %58)
%60 = icmp eq i32 %59, 0
br i1 %60, label %75, label %61
61: ; preds = %57
%62 = load i8*, i8** %35
%63 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 4095, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %12, i8* %62)
%64 = call i64 @get_dev_num(i8* %7, i64* %5)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %74
66: ; preds = %61
%67 = load i64, i64* %5
%68 = icmp eq i64 %67, %1
br i1 %68, label %69, label %75
69: ; preds = %66
%70 = load i8*, i8** %35
%71 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 4095, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %12, i8* %70)
%72 = call i32 @closedir(i32* %22)
%73 = call i32 @get_dev_start(i8* %7, i64* %2)
br label %82
74: ; preds = %61, %54
br label %80
75: ; preds = %66, %57, %33, %41, %44
%76 = call %struct.dirent* @readdir(i32* %22)
%77 = icmp eq %struct.dirent* %76, null
br i1 %77, label %78, label %33
78: ; preds = %75, %24
%79 = call i32 (i32, i8*, i8*, ...) @__ploop_err(i32 0, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i8* %12, i64 %1)
br label %80
80: ; preds = %74, %78
%81 = call i32 @closedir(i32* %22)
br label %82
82: ; preds = %69, %3, %80, %30, %19
%83 = phi i32 [ 0, %19 ], [ -1, %30 ], [ -1, %80 ], [ -1, %3 ], [ %73, %69 ]
ret i32 %83
}