#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*/ atoi(int /*<<< orphan*/);
int /*<<< orphan*/ enter_sysfs();
int /*<<< orphan*/ exit_sysfs();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int is_sda_ssd(void) {
  FILE *file;
  int is_ssd = 0;
  enter_sysfs();
  file = fopen("sda/queue/rotational", "r");
  if (file) {
    char buffer[64];
    is_ssd = !atoi(fgets(buffer, 64, file));
    fclose(file);
  }
  exit_sysfs();
  return is_ssd;
}


x86 assembly (clang, -O0):
<is_sda_ssd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1050 <enter_sysfs@plt>
lea    0xe83(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ca <is_sda_ssd+0x6a>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x40,%esi
call   1040 <fgets@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x0,%al
call   1070 <exit_sysfs@plt>
mov    -0xc(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_sda_ssd>:
push   %r14
push   %rbx
sub    $0x48,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <enter_sysfs@plt>
lea    0xe89(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b1 <is_sda_ssd+0x51>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %eax,%edi
call   1080 <atoi@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
call   1070 <exit_sysfs@plt>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c"sda/queue/rotational\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @is_sda_ssd() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca [64 x i8]
store i32 0, i32* %2
%4 = call i32 (...) @enter_sysfs()
%5 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 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** %1
%6 = load i32*, i32** %1
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %18
8: ; preds = %0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %1
%11 = call i32 @fgets(i8* %9, i32 64, i32* %10)
%12 = call i32 @atoi(i32 %11)
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
%15 = zext i1 %14 to i32
store i32 %15, i32* %2
%16 = load i32*, i32** %1
%17 = call i32 @fclose(i32* %16)
br label %18
18: ; preds = %8, %0
%19 = call i32 (...) @exit_sysfs()
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str = [21 x i8] c"sda/queue/rotational\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @is_sda_ssd() {
%1 = alloca [64 x i8]
%2 = tail call i32 (...) @enter_sysfs()
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%7 = call i32 @fgets(i8* %6, i32 64, i32* %3)
%8 = call i32 @atoi(i32 %7)
%9 = icmp eq i32 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @fclose(i32* %3)
br label %12
12: ; preds = %5, %0
%13 = phi i32 [ %10, %5 ], [ 0, %0 ]
%14 = call i32 (...) @exit_sysfs()
ret i32 %13
}