#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 ssize_t;
typedef int /*<<< orphan*/ path;
typedef scalar_t__ dev_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
scalar_t__ makedev(unsigned int, unsigned int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
unsigned long strtoul(char *, char **, int);
dev_t try_name(char *name, unsigned long int part) {
  char path[65536];
  char buf[65536];
  unsigned long int major_num, minor_num, range;
  dev_t res;
  char *s;
  ssize_t len;
  int fd;
  snprintf(path, sizeof(path), "/sys/block/%s/dev", name);
  fd = open(path, 0, 0);
  if (fd < 0)
    goto fail;
  len = read(fd, buf, 65536);
  close(fd);
  if (len <= 0 || len == 65536 || buf[len - 1] != '\n')
    goto fail;
  buf[len - 1] = '\0';
  major_num = strtoul(buf, &s, 10);
  if (*s != ':')
    goto fail;
  minor_num = strtoul(s + 1, &s, 10);
  if (*s)
    goto fail;
  res = makedev((unsigned int)major_num, (unsigned int)minor_num);
  if (!part)
    return res;
  snprintf(path, sizeof(path), "/sys/block/%s/range", name);
  fd = open(path, 0, 0);
  if (fd < 0)
    goto fail;
  len = read(fd, buf, 32);
  close(fd);
  if (len <= 0 || len == 32 || buf[len - 1] != '\n')
    goto fail;
  buf[len - 1] = '\0';
  range = strtoul(buf, &s, 10);
  if (*s)
    goto fail;
  if (part < range) {
    ((void)0);
    return res + part;
  }
fail:
  return (dev_t)0;
}


x86 assembly (clang, -O0):
<try_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20050,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x10020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x10000,%esi
lea    0xe76(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x10020(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <open@plt>
mov    %eax,-0x20050(%rbp)
cmpl   $0x0,-0x20050(%rbp)
jge    11b7 <try_name+0x57>
jmp    13f0 <try_name+0x290>
mov    -0x20050(%rbp),%edi
lea    -0x20020(%rbp),%rsi
mov    $0x10000,%edx
call   1050 <read@plt>
mov    %eax,-0x2004c(%rbp)
mov    -0x20050(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x2004c(%rbp)
jle    1218 <try_name+0xb8>
cmpl   $0x10000,-0x2004c(%rbp)
je     1218 <try_name+0xb8>
mov    -0x2004c(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x20020(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     121d <try_name+0xbd>
jmp    13f0 <try_name+0x290>
mov    -0x2004c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x20020(%rbp,%rax,1)
lea    -0x20020(%rbp),%rdi
lea    -0x20048(%rbp),%rsi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %rax,-0x20028(%rbp)
mov    -0x20048(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     1267 <try_name+0x107>
jmp    13f0 <try_name+0x290>
mov    -0x20048(%rbp),%rdi
add    $0x1,%rdi
lea    -0x20048(%rbp),%rsi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %rax,-0x20030(%rbp)
mov    -0x20048(%rbp),%rax
cmpb   $0x0,(%rax)
je     129f <try_name+0x13f>
jmp    13f0 <try_name+0x290>
mov    -0x20028(%rbp),%rax
mov    %eax,%edi
mov    -0x20030(%rbp),%rax
mov    %eax,%esi
call   1070 <makedev@plt>
mov    %rax,-0x20040(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12d8 <try_name+0x178>
mov    -0x20040(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13f8 <try_name+0x298>
lea    -0x10020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x10000,%esi
lea    0xd23(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x10020(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <open@plt>
mov    %eax,-0x20050(%rbp)
cmpl   $0x0,-0x20050(%rbp)
jge    131c <try_name+0x1bc>
jmp    13f0 <try_name+0x290>
mov    -0x20050(%rbp),%edi
lea    -0x20020(%rbp),%rsi
mov    $0x20,%edx
call   1050 <read@plt>
mov    %eax,-0x2004c(%rbp)
mov    -0x20050(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x2004c(%rbp)
jle    137a <try_name+0x21a>
cmpl   $0x20,-0x2004c(%rbp)
je     137a <try_name+0x21a>
mov    -0x2004c(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x20020(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     137f <try_name+0x21f>
jmp    13f0 <try_name+0x290>
mov    -0x2004c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x20020(%rbp,%rax,1)
lea    -0x20020(%rbp),%rdi
lea    -0x20048(%rbp),%rsi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %rax,-0x20038(%rbp)
mov    -0x20048(%rbp),%rax
cmpb   $0x0,(%rax)
je     13c6 <try_name+0x266>
jmp    13f0 <try_name+0x290>
mov    -0x18(%rbp),%rax
cmp    -0x20038(%rbp),%rax
jae    13eb <try_name+0x28b>
mov    -0x20040(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13f8 <try_name+0x298>
jmp    13f0 <try_name+0x290>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<try_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20018,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe82(%rip),%rdx
lea    0x10010(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x10000,%esi
mov    %r12,%rcx
call   1030 <snprintf@plt>
xor    %r13d,%r13d
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <open@plt>
test   %eax,%eax
js     1224 <try_name+0xc4>
mov    %eax,%ebp
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x10000,%edx
call   1050 <read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
xor    %r13d,%r13d
test   %ebx,%ebx
jle    1224 <try_name+0xc4>
cmp    $0x10000,%ebx
je     1224 <try_name+0xc4>
add    $0xffffffff,%ebx
cmpb   $0xa,0x10(%rsp,%rbx,1)
jne    1221 <try_name+0xc1>
movb   $0x0,0x10(%rsp,%rbx,1)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    0x8(%rsp),%rdi
cmpb   $0x3a,(%rdi)
jne    1221 <try_name+0xc1>
mov    %rax,%rbx
add    $0x1,%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
je     1239 <try_name+0xd9>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x20018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <makedev@plt>
mov    %rax,%r15
test   %r14,%r14
je     12eb <try_name+0x18b>
lea    0xdbd(%rip),%rdx
lea    0x10010(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x10000,%esi
mov    %r12,%rcx
call   1030 <snprintf@plt>
xor    %r13d,%r13d
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <open@plt>
test   %eax,%eax
js     1224 <try_name+0xc4>
mov    %eax,%ebp
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x20,%edx
call   1050 <read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
xor    %r13d,%r13d
test   %ebx,%ebx
jle    1224 <try_name+0xc4>
cmp    $0x20,%ebx
je     1224 <try_name+0xc4>
add    $0xffffffff,%ebx
cmpb   $0xa,0x10(%rsp,%rbx,1)
jne    1221 <try_name+0xc1>
movb   $0x0,0x10(%rsp,%rbx,1)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    0x8(%rsp),%rcx
add    %r14,%r15
xor    %edx,%edx
cmp    %r14,%rax
cmovbe %rdx,%r15
cmpb   $0x0,(%rcx)
cmovne %rdx,%r15
mov    %r15,%r13
jmp    1224 <try_name+0xc4>

LLVM IR (-O0):
@.str = [18 x i8] c"/sys/block/%s/dev\00"
@.str.1 = [20 x i8] c"/sys/block/%s/range\00"
define i64 @try_name(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [65536 x i8]
%7 = alloca [65536 x i8]
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%15 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%16 = load i8*, i8** %4
%17 = call i32 @snprintf(i8* %15, i32 65536, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%19 = call i32 @open(i8* %18, i32 0, i32 0)
store i32 %19, i32* %14
%20 = load i32, i32* %14
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %2
br label %122
23: ; preds = %2
%24 = load i32, i32* %14
%25 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%26 = call i32 @read(i32 %24, i8* %25, i32 65536)
store i32 %26, i32* %13
%27 = load i32, i32* %14
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %13
%30 = icmp sle i32 %29, 0
br i1 %30, label %42, label %31
31: ; preds = %23
%32 = load i32, i32* %13
%33 = icmp eq i32 %32, 65536
br i1 %33, label %42, label %34
34: ; preds = %31
%35 = load i32, i32* %13
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 10
br i1 %41, label %42, label %43
42: ; preds = %34, %31, %23
br label %122
43: ; preds = %34
%44 = load i32, i32* %13
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 %46
store i8 0, i8* %47
%48 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%49 = call i64 @strtoul(i8* %48, i8** %12, i32 10)
store i64 %49, i64* %8
%50 = load i8*, i8** %12
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 58
br i1 %53, label %54, label %55
54: ; preds = %43
br label %122
55: ; preds = %43
%56 = load i8*, i8** %12
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = call i64 @strtoul(i8* %57, i8** %12, i32 10)
store i64 %58, i64* %9
%59 = load i8*, i8** %12
%60 = load i8, i8* %59
%61 = icmp ne i8 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %55
br label %122
63: ; preds = %55
%64 = load i64, i64* %8
%65 = trunc i64 %64 to i32
%66 = load i64, i64* %9
%67 = trunc i64 %66 to i32
%68 = call i64 @makedev(i32 %65, i32 %67)
store i64 %68, i64* %11
%69 = load i64, i64* %5
%70 = icmp ne i64 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %63
%72 = load i64, i64* %11
store i64 %72, i64* %3
br label %123
73: ; preds = %63
%74 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%75 = load i8*, i8** %4
%76 = call i32 @snprintf(i8* %74, i32 65536, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %75)
%77 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%78 = call i32 @open(i8* %77, i32 0, i32 0)
store i32 %78, i32* %14
%79 = load i32, i32* %14
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %82
81: ; preds = %73
br label %122
82: ; preds = %73
%83 = load i32, i32* %14
%84 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%85 = call i32 @read(i32 %83, i8* %84, i32 32)
store i32 %85, i32* %13
%86 = load i32, i32* %14
%87 = call i32 @close(i32 %86)
%88 = load i32, i32* %13
%89 = icmp sle i32 %88, 0
br i1 %89, label %101, label %90
90: ; preds = %82
%91 = load i32, i32* %13
%92 = icmp eq i32 %91, 32
br i1 %92, label %101, label %93
93: ; preds = %90
%94 = load i32, i32* %13
%95 = sub nsw i32 %94, 1
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 %96
%98 = load i8, i8* %97
%99 = sext i8 %98 to i32
%100 = icmp ne i32 %99, 10
br i1 %100, label %101, label %102
101: ; preds = %93, %90, %82
br label %122
102: ; preds = %93
%103 = load i32, i32* %13
%104 = sub nsw i32 %103, 1
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 %105
store i8 0, i8* %106
%107 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%108 = call i64 @strtoul(i8* %107, i8** %12, i32 10)
store i64 %108, i64* %10
%109 = load i8*, i8** %12
%110 = load i8, i8* %109
%111 = icmp ne i8 %110, 0
br i1 %111, label %112, label %113
112: ; preds = %102
br label %122
113: ; preds = %102
%114 = load i64, i64* %5
%115 = load i64, i64* %10
%116 = icmp ult i64 %114, %115
br i1 %116, label %117, label %121
117: ; preds = %113
%118 = load i64, i64* %11
%119 = load i64, i64* %5
%120 = add i64 %118, %119
store i64 %120, i64* %3
br label %123
121: ; preds = %113
br label %122
122: ; preds = %121, %112, %101, %81, %62, %54, %42, %22
store i64 0, i64* %3
br label %123
123: ; preds = %122, %117, %71
%124 = load i64, i64* %3
ret i64 %124
}

LLVM IR (-O2):
@.str = [18 x i8] c"/sys/block/%s/dev\00"
@.str.1 = [20 x i8] c"/sys/block/%s/range\00"
define i64 @try_name(i8* %0, i64 %1) {
%3 = alloca [65536 x i8]
%4 = alloca [65536 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 0
%8 = bitcast i8** %5 to i8*
%9 = call i32 @snprintf(i8* %6, i32 65536, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = call i32 @open(i8* %6, i32 0, i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %65, label %12
12: ; preds = %2
%13 = call i32 @read(i32 %10, i8* %7, i32 65536)
%14 = call i32 @close(i32 %10)
%15 = icmp slt i32 %13, 1
%16 = icmp eq i32 %13, 65536
%17 = or i1 %15, %16
br i1 %17, label %65, label %18
18: ; preds = %12
%19 = add nsw i32 %13, -1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 10
br i1 %23, label %24, label %65
24: ; preds = %18
store i8 0, i8* %21
%25 = call i64 @strtoul(i8* %7, i8** %5, i32 10)
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 58
br i1 %28, label %29, label %65
29: ; preds = %24
%30 = getelementptr inbounds i8, i8* %26, i64 1
%31 = call i64 @strtoul(i8* %30, i8** %5, i32 10)
%32 = load i8*, i8** %5
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %65
35: ; preds = %29
%36 = trunc i64 %25 to i32
%37 = trunc i64 %31 to i32
%38 = call i64 @makedev(i32 %36, i32 %37)
%39 = icmp eq i64 %1, 0
br i1 %39, label %65, label %40
40: ; preds = %35
%41 = call i32 @snprintf(i8* %6, i32 65536, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%42 = call i32 @open(i8* %6, i32 0, i32 0)
%43 = icmp slt i32 %42, 0
br i1 %43, label %65, label %44
44: ; preds = %40
%45 = call i32 @read(i32 %42, i8* %7, i32 32)
%46 = call i32 @close(i32 %42)
%47 = icmp slt i32 %45, 1
%48 = icmp eq i32 %45, 32
%49 = or i1 %47, %48
br i1 %49, label %65, label %50
50: ; preds = %44
%51 = add nsw i32 %45, -1
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = icmp eq i8 %54, 10
br i1 %55, label %56, label %65
56: ; preds = %50
store i8 0, i8* %53
%57 = call i64 @strtoul(i8* %7, i8** %5, i32 10)
%58 = load i8*, i8** %5
%59 = load i8, i8* %58
%60 = icmp eq i8 %59, 0
%61 = icmp ugt i64 %57, %1
%62 = select i1 %60, i1 %61, i1 false
%63 = add i64 %38, %1
%64 = select i1 %62, i64 %63, i64 0
br label %65
65: ; preds = %56, %2, %18, %12, %24, %29, %40, %50, %44, %35
%66 = phi i64 [ %38, %35 ], [ 0, %44 ], [ 0, %50 ], [ 0, %40 ], [ 0, %29 ], [ 0, %24 ], [ 0, %12 ], [ 0, %18 ], [ 0, %2 ], [ %64, %56 ]
ret i64 %66
}