#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*/ dev_t;

/* Variables and functions */
scalar_t__ dinfo_extract_dev(int /*<<< orphan*/ *, char *);
char *dinfo_malloc(int);
scalar_t__ util_file_read_line(char *, int, char *, char *);
int /*<<< orphan*/ warnx(char *);
int dinfo_get_dev_from_blockdev(char *blockdev, dev_t *dev) {
  char *readbuf = NULL;
  readbuf = dinfo_malloc(80);
  if (!readbuf) {
    warnx("Error: Not enough memory to allocate readbuffer");
    return -1;
  }
  if (util_file_read_line(readbuf, 80, "/sys/block/%s/dev", blockdev) < 0)
    return -1;
  if (dinfo_extract_dev(dev, readbuf) != 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<dinfo_get_dev_from_blockdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x50,%edi
call   1030 <dinfo_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1189 <dinfo_get_dev_from_blockdev+0x49>
lea    0xe88(%rip),%rdi
call   1040 <warnx@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <dinfo_get_dev_from_blockdev+0xa2>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x50,%esi
lea    0xe93(%rip),%rdx
call   1050 <util_file_read_line@plt>
cmp    $0x0,%rax
jge    11b8 <dinfo_get_dev_from_blockdev+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <dinfo_get_dev_from_blockdev+0xa2>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <dinfo_extract_dev@plt>
cmp    $0x0,%rax
je     11db <dinfo_get_dev_from_blockdev+0x9b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <dinfo_get_dev_from_blockdev+0xa2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dinfo_get_dev_from_blockdev>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x50,%edi
call   1030 <dinfo_malloc@plt>
test   %rax,%rax
je     118b <dinfo_get_dev_from_blockdev+0x4b>
mov    %rax,%rbx
lea    0xecc(%rip),%rdx
mov    %rax,%rdi
mov    $0x50,%esi
mov    %r15,%rcx
call   1050 <util_file_read_line@plt>
test   %rax,%rax
js     1197 <dinfo_get_dev_from_blockdev+0x57>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <dinfo_extract_dev@plt>
neg    %rax
sbb    %eax,%eax
jmp    119c <dinfo_get_dev_from_blockdev+0x5c>
lea    0xe6e(%rip),%rdi
call   1040 <warnx@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Error: Not enough memory to allocate readbuffer\00"
@.str.1 = [18 x i8] c"/sys/block/%s/dev\00"
define i32 @dinfo_get_dev_from_blockdev(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* null, i8** %6
%7 = call i8* @dinfo_malloc(i32 80)
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 @warnx(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %25
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = load i8*, i8** %4
%15 = call i64 @util_file_read_line(i8* %13, i32 80, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 -1, i32* %3
br label %25
18: ; preds = %12
%19 = load i32*, i32** %5
%20 = load i8*, i8** %6
%21 = call i64 @dinfo_extract_dev(i32* %19, i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 -1, i32* %3
br label %25
24: ; preds = %18
store i32 0, i32* %3
br label %25
25: ; preds = %24, %23, %17, %10
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [48 x i8] c"Error: Not enough memory to allocate readbuffer\00"
@.str.1 = [18 x i8] c"/sys/block/%s/dev\00"
define i32 @dinfo_get_dev_from_blockdev(i8* %0, i32* %1) {
%3 = tail call i8* @dinfo_malloc(i32 80)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @warnx(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %14
7: ; preds = %2
%8 = tail call i64 @util_file_read_line(i8* %3, i32 80, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i64 @dinfo_extract_dev(i32* %1, i8* %3)
%12 = icmp ne i64 %11, 0
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %10, %7, %5
%15 = phi i32 [ -1, %5 ], [ -1, %7 ], [ %13, %10 ]
ret i32 %15
}