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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, char *);
scalar_t__ strcmp(char *, char *);
int get_misc_minor(void) {
  int minor;
  char name[64];
  FILE *f;
  if ((f = fopen("/proc/misc", "r")) == NULL)
    return -1;
  while (fscanf(f, " %d %64s", &minor, name) == 2) {
    if (strcmp(name, "pktcdvd") == 0) {
      fclose(f);
      return minor;
    }
  }
  fclose(f);
  return -1;
}


x86 assembly (clang, -O0):
<get_misc_minor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
jne    1175 <get_misc_minor+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11de <get_misc_minor+0x9e>
jmp    117a <get_misc_minor+0x3a>
mov    -0x58(%rbp),%rdi
lea    -0x50(%rbp),%rcx
lea    0xe84(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x2,%eax
jne    11ce <get_misc_minor+0x8e>
lea    -0x50(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11c9 <get_misc_minor+0x89>
mov    -0x58(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11de <get_misc_minor+0x9e>
jmp    117a <get_misc_minor+0x3a>
mov    -0x58(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_misc_minor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xeab(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11cd <get_misc_minor+0x8d>
mov    %rax,%rbx
lea    0xe97(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%rbp
lea    0xe8f(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbp,%rcx
call   1040 <fscanf@plt>
cmp    $0x2,%eax
jne    11c5 <get_misc_minor+0x85>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1190 <get_misc_minor+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%r14d
jmp    11cd <get_misc_minor+0x8d>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/proc/misc\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c" %d %64s\00"
@.str.3 = [8 x i8] c"pktcdvd\00"
define i32 @get_misc_minor() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [64 x i8]
%4 = alloca i32*
%5 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 -1, i32* %1
br label %26
8: ; preds = %0
br label %9
9: ; preds = %22, %8
%10 = load i32*, i32** %4
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%12 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %2, i8* %11)
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32*, i32** %4
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* %2
store i32 %21, i32* %1
br label %26
22: ; preds = %14
br label %9
23: ; preds = %9
%24 = load i32*, i32** %4
%25 = call i32 @fclose(i32* %24)
store i32 -1, i32* %1
br label %26
26: ; preds = %23, %18, %7
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [11 x i8] c"/proc/misc\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c" %d %64s\00"
@.str.3 = [8 x i8] c"pktcdvd\00"
define i32 @get_misc_minor() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %18, label %7
7: ; preds = %0, %10
%8 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %1, i8* %4)
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %7
13: ; preds = %10
%14 = call i32 @fclose(i32* %5)
%15 = load i32, i32* %1
br label %18
16: ; preds = %7
%17 = call i32 @fclose(i32* %5)
br label %18
18: ; preds = %0, %16, %13
%19 = phi i32 [ %15, %13 ], [ -1, %16 ], [ -1, %0 ]
ret i32 %19
}