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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int sscanf(char *, char *, int *, int *, unsigned long long *, char *);
scalar_t__ strncmp(char *, char *, int);
int is_sda(char *dev) {
  int count = 0;
  FILE *fp;
  char part_name[16], line[128];
  int major, minors;
  unsigned long long capacity;
  fp = fopen("/proc/partitions", "r");
  if (fp == NULL)
    goto ret;
  while (fgets(line, sizeof(line), fp)) {
    if (sscanf(line, " %d %d %llu %[^\n ]", &major, &minors, &capacity,
               part_name) != 4)
      continue;
    if (strncmp(part_name, dev, 3))
      continue;
    else
      count++;
  }
ret:
  if (fp != NULL)
    fclose(fp);
  return ((count == 1) ? 1 : 0);
}


x86 assembly (clang, -O0):
<is_sda>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118d <is_sda+0x3d>
jmp    121f <is_sda+0xcf>
jmp    1192 <is_sda+0x42>
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     121a <is_sda+0xca>
lea    -0xb0(%rbp),%rdi
lea    -0x30(%rbp),%r9
lea    0xe50(%rip),%rsi
lea    -0xb4(%rbp),%rdx
lea    -0xb8(%rbp),%rcx
lea    -0xc0(%rbp),%r8
call   1060 <sscanf@plt>
cmp    $0x4,%eax
je     11eb <is_sda+0x9b>
jmp    1192 <is_sda+0x42>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     120c <is_sda+0xbc>
jmp    1192 <is_sda+0x42>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1192 <is_sda+0x42>
jmp    121f <is_sda+0xcf>
cmpq   $0x0,-0x18(%rbp)
je     1233 <is_sda+0xe3>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0xc(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_sda>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rdi,0x8(%rsp)
lea    0xe93(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1210 <is_sda+0xc0>
mov    %rax,%rbx
movl   $0x0,0x4(%rsp)
lea    0x30(%rsp),%r15
lea    0x14(%rsp),%r13
lea    0x10(%rsp),%rbp
lea    0x18(%rsp),%r14
lea    0x20(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1202 <is_sda+0xb2>
mov    %r15,%rdi
lea    0xe44(%rip),%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
mov    %r14,%r8
mov    %r12,%r9
call   1060 <sscanf@plt>
cmp    $0x4,%eax
jne    11b0 <is_sda+0x60>
mov    %r12,%rdi
mov    0x8(%rsp),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x1,%rax
adcl   $0x0,0x4(%rsp)
jmp    11b0 <is_sda+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x4(%rsp),%ecx
jmp    1212 <is_sda+0xc2>
xor    %ecx,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
sete   %al
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/partitions\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c" %d %d %llu %[^\0A ]\00"
define i32 @is_sda(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [16 x i8]
%6 = alloca [128 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
store i8* %0, i8** %2
store i32 0, i32* %3
%10 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 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 = load i32*, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
br label %37
14: ; preds = %1
br label %15
15: ; preds = %35, %31, %25, %14
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%17 = load i32*, i32** %4
%18 = call i64 @fgets(i8* %16, i32 128, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %15
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%23 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32* %7, i32* %8, i64* %9, i8* %22)
%24 = icmp ne i32 %23, 4
br i1 %24, label %25, label %26
25: ; preds = %20
br label %15
26: ; preds = %20
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%28 = load i8*, i8** %2
%29 = call i64 @strncmp(i8* %27, i8* %28, i32 3)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
br label %15
32: ; preds = %26
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %35
35: ; preds = %32
br label %15
36: ; preds = %15
br label %37
37: ; preds = %36, %13
%38 = load i32*, i32** %4
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32*, i32** %4
%42 = call i32 @fclose(i32* %41)
br label %43
43: ; preds = %40, %37
%44 = load i32, i32* %3
%45 = icmp eq i32 %44, 1
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 1, i32 0
ret i32 %47
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/partitions\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c" %d %d %llu %[^\0A ]\00"
define i32 @is_sda(i8* %0) {
%2 = alloca [16 x i8]
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i64* %6 to i8*
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %29, label %14
14: ; preds = %1, %22
%15 = phi i32 [ %26, %22 ], [ 0, %1 ]
br label %16
16: ; preds = %14, %19
%17 = call i64 @fgets(i8* %8, i32 128, i32* %12)
%18 = icmp eq i64 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %16
%20 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5, i64* %6, i8* %7)
%21 = icmp eq i32 %20, 4
br i1 %21, label %22, label %16
22: ; preds = %19
%23 = call i64 @strncmp(i8* %7, i8* %0, i32 3)
%24 = icmp eq i64 %23, 0
%25 = zext i1 %24 to i32
%26 = add nuw nsw i32 %15, %25
br label %14
27: ; preds = %16
%28 = call i32 @fclose(i32* %12)
br label %29
29: ; preds = %1, %27
%30 = phi i32 [ %15, %27 ], [ 0, %1 ]
%31 = icmp eq i32 %30, 1
%32 = zext i1 %31 to i32
ret i32 %32
}