#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 *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
scalar_t__ strcasecmp(char *, char *);
int getWriteCache(const char *suf) {
  char s[200], s2[200];
  int ret = 0;
  FILE *fp = NULL;
  if (suf) {
    sprintf(s, "/sys/block/%s/queue/write_cache", suf);
    fp = fopen(s, "rt");
    if (!fp) {
      ret = -1;
      goto wvret;
    }
    if (fscanf(fp, "%s %s", s, s2) == 2) {
      if (strcasecmp(s2, "back") == 0) {
        ret = 1;
        goto wvret;
      }
    }
  } else {
    ret = -2;
  }
wvret:
  if (fp)
    fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<getWriteCache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1a4(%rbp)
movq   $0x0,-0x1b0(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     122d <getWriteCache+0xdd>
lea    -0xd0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0xd0(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x1b0(%rbp)
cmpq   $0x0,-0x1b0(%rbp)
jne    11cd <getWriteCache+0x7d>
movl   $0xffffffff,-0x1a4(%rbp)
ff ff ff
jmp    123c <getWriteCache+0xec>
mov    -0x1b0(%rbp),%rdi
lea    -0xd0(%rbp),%rdx
lea    -0x1a0(%rbp),%rcx
lea    0xe3a(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x2,%eax
jne    1228 <getWriteCache+0xd8>
lea    -0x1a0(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1223 <getWriteCache+0xd3>
movl   $0x1,-0x1a4(%rbp)
jmp    123c <getWriteCache+0xec>
jmp    1228 <getWriteCache+0xd8>
jmp    1237 <getWriteCache+0xe7>
movl   $0xfffffffe,-0x1a4(%rbp)
ff ff ff
jmp    123c <getWriteCache+0xec>
cmpq   $0x0,-0x1b0(%rbp)
je     1256 <getWriteCache+0x106>
mov    -0x1b0(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getWriteCache>:
push   %rbp
push   %rbx
sub    $0x198,%rsp
test   %rdi,%rdi
je     11d2 <getWriteCache+0x82>
mov    %rdi,%rdx
lea    0xe98(%rip),%rsi
lea    0xd0(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d9 <getWriteCache+0x89>
mov    %rax,%rbx
lea    0xe8d(%rip),%rsi
lea    0xd0(%rsp),%rdx
mov    %rsp,%rcx
mov    %rax,%rdi
call   1050 <fscanf@plt>
xor    %ebp,%ebp
cmp    $0x2,%eax
jne    11c8 <getWriteCache+0x78>
lea    0xe72(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcasecmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11de <getWriteCache+0x8e>
mov    $0xfffffffe,%ebp
jmp    11de <getWriteCache+0x8e>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x198,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"/sys/block/%s/queue/write_cache\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [6 x i8] c"%s %s\00"
@.str.3 = [5 x i8] c"back\00"
define i32 @getWriteCache(i8* %0) {
%2 = alloca i8*
%3 = alloca [200 x i8]
%4 = alloca [200 x i8]
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %5
store i32* null, i32** %6
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %31
9: ; preds = %1
%10 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%11 = load i8*, i8** %2
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %9
store i32 -1, i32* %5
br label %33
18: ; preds = %9
%19 = load i32*, i32** %6
%20 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%22 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %20, i8* %21)
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%26 = call i64 @strcasecmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 1, i32* %5
br label %33
29: ; preds = %24
br label %30
30: ; preds = %29, %18
br label %32
31: ; preds = %1
store i32 -2, i32* %5
br label %32
32: ; preds = %31, %30
br label %33
33: ; preds = %32, %28, %17
%34 = load i32*, i32** %6
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
br label %39
39: ; preds = %36, %33
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
@.str = [32 x i8] c"/sys/block/%s/queue/write_cache\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [6 x i8] c"%s %s\00"
@.str.3 = [5 x i8] c"back\00"
define i32 @getWriteCache(i8* %0) {
%2 = alloca [200 x i8]
%3 = alloca [200 x i8]
%4 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %21, label %7
7: ; preds = %1
%8 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %21, label %11
11: ; preds = %7
%12 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %5)
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %11, %14
%19 = phi i32 [ 0, %11 ], [ %17, %14 ]
%20 = call i32 @fclose(i32* %9)
br label %21
21: ; preds = %1, %7, %18
%22 = phi i32 [ %19, %18 ], [ -2, %1 ], [ -1, %7 ]
ret i32 %22
}