#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*/ temp;
typedef int /*<<< orphan*/ data;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ __rtinfo_internal_disk_isblock(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
unsigned int field_length(char *, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *index_string(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, unsigned int);
int __rtinfo_internal_disk_nbdisk(char *prefix) {
  FILE *fp;
  char temp[32], data[256];
  char *match;
  unsigned int length, nbdisk = 0;
  if (!(fp = fopen("/proc/diskstats", "r"))) {
    fprintf(stderr, "[-] librtinfo: cannot open %s, ignoring disks\n",
            "/proc/diskstats");
    return 0;
  }
  while (fgets(data, sizeof(data), fp) != NULL) {
    match = index_string(data, 2);
    length = field_length(data, 2);
    if (length > sizeof(temp))
      continue;
    strncpy(temp, match, length);
    temp[length] = '\0';
    if (prefix && strncmp(temp, prefix, strlen(prefix)))
      continue;
    if (!__rtinfo_internal_disk_isblock(temp))
      continue;
    nbdisk++;
  }
  fclose(fp);
  return nbdisk;
}


x86 assembly (clang, -O0):
<__rtinfo_internal_disk_nbdisk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x150(%rbp)
lea    0xe40(%rip),%rdi
lea    0xe49(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1202 <__rtinfo_internal_disk_nbdisk+0x62>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
lea    0xe0f(%rip),%rdx
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1316 <__rtinfo_internal_disk_nbdisk+0x176>
jmp    1207 <__rtinfo_internal_disk_nbdisk+0x67>
lea    -0x140(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1304 <__rtinfo_internal_disk_nbdisk+0x164>
lea    -0x140(%rbp),%rdi
mov    $0x2,%esi
call   10b0 <index_string@plt>
mov    %rax,-0x148(%rbp)
lea    -0x140(%rbp),%rdi
mov    $0x2,%esi
call   1050 <field_length@plt>
mov    %eax,-0x14c(%rbp)
mov    -0x14c(%rbp),%eax
cmp    $0x20,%rax
jbe    126a <__rtinfo_internal_disk_nbdisk+0xca>
jmp    1207 <__rtinfo_internal_disk_nbdisk+0x67>
lea    -0x40(%rbp),%rdi
mov    -0x148(%rbp),%rsi
mov    -0x14c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x14c(%rbp),%eax
movb   $0x0,-0x40(%rbp,%rax,1)
cmpq   $0x0,-0x10(%rbp)
je     12d9 <__rtinfo_internal_disk_nbdisk+0x139>
lea    -0x40(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x160(%rbp),%rdi
mov    -0x158(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     12d9 <__rtinfo_internal_disk_nbdisk+0x139>
jmp    1207 <__rtinfo_internal_disk_nbdisk+0x67>
lea    -0x40(%rbp),%rdi
call   10a0 <__rtinfo_internal_disk_isblock@plt>
cmp    $0x0,%eax
jne    12f0 <__rtinfo_internal_disk_nbdisk+0x150>
jmp    1207 <__rtinfo_internal_disk_nbdisk+0x67>
mov    -0x150(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x150(%rbp)
jmp    1207 <__rtinfo_internal_disk_nbdisk+0x67>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x150(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__rtinfo_internal_disk_nbdisk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rdi,%r13
lea    0xe45(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12a2 <__rtinfo_internal_disk_nbdisk+0x102>
mov    %rax,%r14
lea    0x30(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     12c6 <__rtinfo_internal_disk_nbdisk+0x126>
lea    0x30(%rsp),%rbp
lea    0x10(%rsp),%r12
mov    %ebx,0xc(%rsp)
jmp    1219 <__rtinfo_internal_disk_nbdisk+0x79>
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12c2 <__rtinfo_internal_disk_nbdisk+0x122>
mov    %rbp,%rdi
mov    $0x2,%esi
call   10b0 <index_string@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    $0x2,%esi
call   1050 <field_length@plt>
cmp    $0x21,%eax
jae    1200 <__rtinfo_internal_disk_nbdisk+0x60>
mov    %eax,%r15d
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %r15d,%eax
movb   $0x0,0x10(%rsp,%rax,1)
test   %r13,%r13
je     1272 <__rtinfo_internal_disk_nbdisk+0xd2>
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1200 <__rtinfo_internal_disk_nbdisk+0x60>
mov    %r12,%rdi
call   10a0 <__rtinfo_internal_disk_isblock@plt>
cmp    $0x1,%eax
mov    0xc(%rsp),%ebx
sbb    $0xffffffff,%ebx
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12c6 <__rtinfo_internal_disk_nbdisk+0x126>
mov    %ebx,0xc(%rsp)
jmp    1219 <__rtinfo_internal_disk_nbdisk+0x79>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xd60(%rip),%rsi
lea    0xd47(%rip),%rdx
call   1090 <fprintf@plt>
xor    %ebx,%ebx
jmp    12ce <__rtinfo_internal_disk_nbdisk+0x12e>
mov    0xc(%rsp),%ebx
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %ebx,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/diskstats\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [47 x i8] c"[-] librtinfo: cannot open %s, ignoring disks\0A\00"
define i32 @__rtinfo_internal_disk_nbdisk(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [32 x i8]
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %9
%10 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %60
15: ; preds = %1
br label %16
16: ; preds = %53, %52, %47, %29, %15
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %4
%19 = call i32* @fgets(i8* %17, i32 256, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %56
21: ; preds = %16
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%23 = call i8* @index_string(i8* %22, i32 2)
store i8* %23, i8** %7
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%25 = call i32 @field_length(i8* %24, i32 2)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = zext i32 %26 to i64
%28 = icmp ugt i64 %27, 32
br i1 %28, label %29, label %30
29: ; preds = %21
br label %16
30: ; preds = %21
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%32 = load i8*, i8** %7
%33 = load i32, i32* %8
%34 = call i32 @strncpy(i8* %31, i8* %32, i32 %33)
%35 = load i32, i32* %8
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %3
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %48
40: ; preds = %30
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%42 = load i8*, i8** %3
%43 = load i8*, i8** %3
%44 = call i32 @strlen(i8* %43)
%45 = call i64 @strncmp(i8* %41, i8* %42, i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %40
br label %16
48: ; preds = %40, %30
%49 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%50 = call i32 @__rtinfo_internal_disk_isblock(i8* %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %48
br label %16
53: ; preds = %48
%54 = load i32, i32* %9
%55 = add i32 %54, 1
store i32 %55, i32* %9
br label %16
56: ; preds = %16
%57 = load i32*, i32** %4
%58 = call i32 @fclose(i32* %57)
%59 = load i32, i32* %9
store i32 %59, i32* %2
br label %60
60: ; preds = %56, %12
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/diskstats\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [47 x i8] c"[-] librtinfo: cannot open %s, ignoring disks\0A\00"
define i32 @__rtinfo_internal_disk_nbdisk(i8* %0) {
%2 = alloca [32 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = call i32* @fgets(i8* %5, i32 256, i32* %6)
%10 = icmp eq i32* %9, null
br i1 %10, label %40, label %11
11: ; preds = %8
%12 = icmp eq i8* %0, null
br label %38
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %43
16: ; preds = %38, %20
%17 = call i8* @index_string(i8* %5, i32 2)
%18 = call i32 @field_length(i8* %5, i32 2)
%19 = icmp ugt i32 %18, 32
br i1 %19, label %20, label %23
20: ; preds = %16, %27
%21 = call i32* @fgets(i8* %5, i32 256, i32* %6)
%22 = icmp eq i32* %21, null
br i1 %22, label %40, label %16
23: ; preds = %16
%24 = zext i32 %18 to i64
%25 = call i32 @strncpy(i8* %4, i8* %17, i32 %18)
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %24
store i8 0, i8* %26
br i1 %12, label %31, label %27
27: ; preds = %23
%28 = call i32 @strlen(i8* %0)
%29 = call i64 @strncmp(i8* %4, i8* %0, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %20
31: ; preds = %27, %23
%32 = call i32 @__rtinfo_internal_disk_isblock(i8* %4)
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i32
%35 = add i32 %39, %34
%36 = call i32* @fgets(i8* %5, i32 256, i32* %6)
%37 = icmp eq i32* %36, null
br i1 %37, label %40, label %38
38: ; preds = %11, %31
%39 = phi i32 [ 0, %11 ], [ %35, %31 ]
br label %16
40: ; preds = %31, %20, %8
%41 = phi i32 [ 0, %8 ], [ %39, %20 ], [ %35, %31 ]
%42 = call i32 @fclose(i32* %6)
br label %43
43: ; preds = %40, %13
%44 = phi i32 [ %41, %40 ], [ 0, %13 ]
ret i32 %44
}