#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 /*<<< 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 *);
void *strtoul(char *, char **, int);
dev_t try_name(char *name, int part) {
  char path[65536];
  char buf[65536];
  int range;
  unsigned int major_num, minor_num;
  dev_t res;
  char *s;
  int 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(major_num, 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    %esi,-0x14(%rbp)
lea    -0x10020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x10000,%esi
lea    0xe77(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x10020(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <open@plt>
mov    %eax,-0x20048(%rbp)
cmpl   $0x0,-0x20048(%rbp)
jge    11b6 <try_name+0x56>
jmp    13e6 <try_name+0x286>
mov    -0x20048(%rbp),%edi
lea    -0x20020(%rbp),%rsi
mov    $0x10000,%edx
call   1050 <read@plt>
mov    %eax,-0x20044(%rbp)
mov    -0x20048(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x20044(%rbp)
jle    1217 <try_name+0xb7>
cmpl   $0x10000,-0x20044(%rbp)
je     1217 <try_name+0xb7>
mov    -0x20044(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x20020(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     121c <try_name+0xbc>
jmp    13e6 <try_name+0x286>
mov    -0x20044(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x20020(%rbp,%rax,1)
lea    -0x20020(%rbp),%rdi
lea    -0x20040(%rbp),%rsi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %eax,-0x20028(%rbp)
mov    -0x20040(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     1265 <try_name+0x105>
jmp    13e6 <try_name+0x286>
mov    -0x20040(%rbp),%rdi
add    $0x1,%rdi
lea    -0x20040(%rbp),%rsi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %eax,-0x2002c(%rbp)
mov    -0x20040(%rbp),%rax
cmpb   $0x0,(%rax)
je     129c <try_name+0x13c>
jmp    13e6 <try_name+0x286>
mov    -0x20028(%rbp),%edi
mov    -0x2002c(%rbp),%esi
call   1070 <makedev@plt>
mov    %rax,-0x20038(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    12ce <try_name+0x16e>
mov    -0x20038(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13ee <try_name+0x28e>
lea    -0x10020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x10000,%esi
lea    0xd2d(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x10020(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <open@plt>
mov    %eax,-0x20048(%rbp)
cmpl   $0x0,-0x20048(%rbp)
jge    1312 <try_name+0x1b2>
jmp    13e6 <try_name+0x286>
mov    -0x20048(%rbp),%edi
lea    -0x20020(%rbp),%rsi
mov    $0x20,%edx
call   1050 <read@plt>
mov    %eax,-0x20044(%rbp)
mov    -0x20048(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x20044(%rbp)
jle    1370 <try_name+0x210>
cmpl   $0x20,-0x20044(%rbp)
je     1370 <try_name+0x210>
mov    -0x20044(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x20020(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     1375 <try_name+0x215>
jmp    13e6 <try_name+0x286>
mov    -0x20044(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x20020(%rbp,%rax,1)
lea    -0x20020(%rbp),%rdi
lea    -0x20040(%rbp),%rsi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %eax,-0x20024(%rbp)
mov    -0x20040(%rbp),%rax
cmpb   $0x0,(%rax)
je     13bb <try_name+0x25b>
jmp    13e6 <try_name+0x286>
mov    -0x14(%rbp),%eax
cmp    -0x20024(%rbp),%eax
jge    13e1 <try_name+0x281>
mov    -0x20038(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    13ee <try_name+0x28e>
jmp    13e6 <try_name+0x286>
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    %esi,%r15d
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,%rbp
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    %ebp,%edi
mov    %eax,%esi
call   1070 <makedev@plt>
mov    %rax,%r14
test   %r15d,%r15d
je     12f3 <try_name+0x193>
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
xor    %r13d,%r13d
cmpb   $0x0,(%rcx)
jne    1224 <try_name+0xc4>
cmp    %r15d,%eax
jle    1224 <try_name+0xc4>
movslq %r15d,%rax
add    %rax,%r14
mov    %r14,%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, i32 %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [65536 x i8]
%7 = alloca [65536 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %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 %124
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 %124
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 i8* @strtoul(i8* %48, i8** %12, i32 10)
%50 = ptrtoint i8* %49 to i32
store i32 %50, i32* %9
%51 = load i8*, i8** %12
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 58
br i1 %54, label %55, label %56
55: ; preds = %43
br label %124
56: ; preds = %43
%57 = load i8*, i8** %12
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = call i8* @strtoul(i8* %58, i8** %12, i32 10)
%60 = ptrtoint i8* %59 to i32
store i32 %60, i32* %10
%61 = load i8*, i8** %12
%62 = load i8, i8* %61
%63 = icmp ne i8 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %56
br label %124
65: ; preds = %56
%66 = load i32, i32* %9
%67 = load i32, i32* %10
%68 = call i64 @makedev(i32 %66, i32 %67)
store i64 %68, i64* %11
%69 = load i32, i32* %5
%70 = icmp ne i32 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %65
%72 = load i64, i64* %11
store i64 %72, i64* %3
br label %125
73: ; preds = %65
%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 %124
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 %124
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 i8* @strtoul(i8* %107, i8** %12, i32 10)
%109 = ptrtoint i8* %108 to i32
store i32 %109, i32* %8
%110 = load i8*, i8** %12
%111 = load i8, i8* %110
%112 = icmp ne i8 %111, 0
br i1 %112, label %113, label %114
113: ; preds = %102
br label %124
114: ; preds = %102
%115 = load i32, i32* %5
%116 = load i32, i32* %8
%117 = icmp slt i32 %115, %116
br i1 %117, label %118, label %123
118: ; preds = %114
%119 = load i64, i64* %11
%120 = load i32, i32* %5
%121 = sext i32 %120 to i64
%122 = add nsw i64 %119, %121
store i64 %122, i64* %3
br label %125
123: ; preds = %114
br label %124
124: ; preds = %123, %113, %101, %81, %64, %55, %42, %22
store i64 0, i64* %3
br label %125
125: ; preds = %124, %118, %71
%126 = load i64, i64* %3
ret i64 %126
}

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, i32 %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 %70, 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 %70, 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 %70
24: ; preds = %18
store i8 0, i8* %21
%25 = call i8* @strtoul(i8* %7, i8** %5, i32 10)
%26 = ptrtoint i8* %25 to i64
%27 = trunc i64 %26 to i32
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 58
br i1 %30, label %31, label %70
31: ; preds = %24
%32 = getelementptr inbounds i8, i8* %28, i64 1
%33 = call i8* @strtoul(i8* %32, i8** %5, i32 10)
%34 = load i8*, i8** %5
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %37, label %70
37: ; preds = %31
%38 = ptrtoint i8* %33 to i64
%39 = trunc i64 %38 to i32
%40 = call i64 @makedev(i32 %27, i32 %39)
%41 = icmp eq i32 %1, 0
br i1 %41, label %70, label %42
42: ; preds = %37
%43 = call i32 @snprintf(i8* %6, i32 65536, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%44 = call i32 @open(i8* %6, i32 0, i32 0)
%45 = icmp slt i32 %44, 0
br i1 %45, label %70, label %46
46: ; preds = %42
%47 = call i32 @read(i32 %44, i8* %7, i32 32)
%48 = call i32 @close(i32 %44)
%49 = icmp slt i32 %47, 1
%50 = icmp eq i32 %47, 32
%51 = or i1 %49, %50
br i1 %51, label %70, label %52
52: ; preds = %46
%53 = add nsw i32 %47, -1
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = icmp eq i8 %56, 10
br i1 %57, label %58, label %70
58: ; preds = %52
store i8 0, i8* %55
%59 = call i8* @strtoul(i8* %7, i8** %5, i32 10)
%60 = load i8*, i8** %5
%61 = load i8, i8* %60
%62 = icmp eq i8 %61, 0
%63 = ptrtoint i8* %59 to i64
%64 = trunc i64 %63 to i32
%65 = icmp sgt i32 %64, %1
%66 = select i1 %62, i1 %65, i1 false
br i1 %66, label %67, label %70
67: ; preds = %58
%68 = sext i32 %1 to i64
%69 = add nsw i64 %40, %68
br label %70
70: ; preds = %2, %18, %12, %24, %31, %42, %52, %46, %58, %37, %67
%71 = phi i64 [ %69, %67 ], [ %40, %37 ], [ 0, %58 ], [ 0, %46 ], [ 0, %52 ], [ 0, %42 ], [ 0, %31 ], [ 0, %24 ], [ 0, %12 ], [ 0, %18 ], [ 0, %2 ]
ret i64 %71
}