#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*/ tmp;
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
scalar_t__ snprintf(char *, int, char *, int, int);
int sscanf(char *, char *, int *);
int crypt_sysfs_get_rotational(int major, int minor, int *rotational) {
  char path[PATH_MAX], tmp[64] = {0};
  int fd, r;
  if (snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/queue/rotational",
               major, minor) < 0)
    return 0;
  if ((fd = open(path, O_RDONLY)) < 0)
    return 0;
  r = read(fd, tmp, sizeof(tmp));
  close(fd);
  if (r <= 0)
    return 0;
  if (sscanf(tmp, "%d", rotational) != 1)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<crypt_sysfs_get_rotational>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x90(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
mov    -0x90(%rbp),%rax
mov    -0x88(%rbp),%rdi
mov    %eax,%esi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0xe27(%rip),%rdx
call   1030 <snprintf@plt>
cmp    $0x0,%rax
jge    11fb <crypt_sysfs_get_rotational+0x9b>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    12a6 <crypt_sysfs_get_rotational+0x146>
mov    -0x88(%rbp),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x74(%rbp)
cmp    $0x0,%eax
jge    122f <crypt_sysfs_get_rotational+0xcf>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    12a6 <crypt_sysfs_get_rotational+0x146>
mov    -0x74(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x40,%edx
call   1060 <read@plt>
mov    %eax,-0x78(%rbp)
mov    -0x74(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x0,-0x78(%rbp)
jg     1268 <crypt_sysfs_get_rotational+0x108>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    12a6 <crypt_sysfs_get_rotational+0x146>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdaf(%rip),%rsi
call   1070 <sscanf@plt>
cmp    $0x1,%eax
je     1298 <crypt_sysfs_get_rotational+0x138>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    12a6 <crypt_sysfs_get_rotational+0x146>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypt_sysfs_get_rotational>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rdx,%r14
mov    %esi,%r8d
mov    %edi,%ecx
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,-0x30(%rbp)
movaps %xmm0,-0x40(%rbp)
movaps %xmm0,-0x50(%rbp)
movaps %xmm0,-0x60(%rbp)
lea    0xe62(%rip),%rdx
mov    %rbx,%rdi
call   1030 <snprintf@plt>
xor    %r15d,%r15d
test   %rax,%rax
js     1201 <crypt_sysfs_get_rotational+0xb1>
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1201 <crypt_sysfs_get_rotational+0xb1>
mov    %eax,%ebx
lea    -0x60(%rbp),%rsi
mov    %eax,%edi
mov    $0x40,%edx
call   1050 <read@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1040 <close@plt>
test   %r12d,%r12d
jle    1201 <crypt_sysfs_get_rotational+0xb1>
lea    0xe3b(%rip),%rsi
lea    -0x60(%rbp),%rdi
mov    %r14,%rdx
call   1060 <sscanf@plt>
xor    %r15d,%r15d
cmp    $0x1,%eax
sete   %r15b
mov    %r15d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [38 x i8] c"/sys/dev/block/%d:%d/queue/rotational\00"
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @crypt_sysfs_get_rotational(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca [64 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%14 = load i32, i32* @PATH_MAX
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %8
%17 = alloca i8, i64 %15
store i64 %15, i64* %9
%18 = bitcast [64 x i8]* %10 to i8*
%19 = trunc i64 %15 to i32
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call i64 @snprintf(i8* %17, i32 %19, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %3
store i32 0, i32* %4
store i32 1, i32* %13
br label %46
25: ; preds = %3
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %17, i32 %26)
store i32 %27, i32* %11
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 0, i32* %4
store i32 1, i32* %13
br label %46
30: ; preds = %25
%31 = load i32, i32* %11
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%33 = call i32 @read(i32 %31, i8* %32, i32 64)
store i32 %33, i32* %12
%34 = load i32, i32* %11
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %12
%37 = icmp sle i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %30
store i32 0, i32* %4
store i32 1, i32* %13
br label %46
39: ; preds = %30
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%41 = load i32*, i32** %7
%42 = call i32 @sscanf(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %41)
%43 = icmp ne i32 %42, 1
br i1 %43, label %44, label %45
44: ; preds = %39
store i32 0, i32* %4
store i32 1, i32* %13
br label %46
45: ; preds = %39
store i32 1, i32* %4
store i32 1, i32* %13
br label %46
46: ; preds = %45, %44, %38, %29, %24
%47 = load i8*, i8** %8
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [38 x i8] c"/sys/dev/block/%d:%d/queue/rotational\00"
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @crypt_sysfs_get_rotational(i32 %0, i32 %1, i32* %2) {
%4 = alloca [64 x i8]
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%9 = call i64 @snprintf(i8* %7, i32 %5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%10 = icmp slt i64 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %3
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %7, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %11
%16 = call i32 @read(i32 %13, i8* %8, i32 64)
%17 = call i32 @close(i32 %13)
%18 = icmp slt i32 %16, 1
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%21 = icmp eq i32 %20, 1
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %19, %15, %11, %3
%24 = phi i32 [ 0, %3 ], [ 0, %11 ], [ 0, %15 ], [ %22, %19 ]
ret i32 %24
}