#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int is_disk_mounted() {
  FILE *fp;
  char buffer[128];
  system("df > /tmp/df");
  fp = fopen("/tmp/df", "r");
  if (fp) {
    while (!feof(fp)) {
      fgets(buffer, 128, fp);
      if (strncmp("/dev/sd", buffer, strlen("/dev/sd")) == 0) {
        fclose(fp);
        return 1;
      }
    }
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_disk_mounted>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    0xe7e(%rip),%rdi
call   1060 <system@plt>
lea    0xe77(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     123d <is_disk_mounted+0xcd>
jmp    11ae <is_disk_mounted+0x3e>
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cc <is_disk_mounted+0x5c>
jmp    1234 <is_disk_mounted+0xc4>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    0xe19(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
lea    0xe04(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    122f <is_disk_mounted+0xbf>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1244 <is_disk_mounted+0xd4>
jmp    11ae <is_disk_mounted+0x3e>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_disk_mounted>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
lea    0xe7c(%rip),%rdi
call   1060 <system@plt>
lea    0xe75(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11ed <is_disk_mounted+0x7d>
mov    %rax,%rbx
mov    %rsp,%r14
lea    0xe61(%rip),%r15
xchg   %ax,%ax
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    11f1 <is_disk_mounted+0x81>
mov    %r14,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11b0 <is_disk_mounted+0x40>
mov    $0x1,%ebp
jmp    11f3 <is_disk_mounted+0x83>
xor    %ebp,%ebp
jmp    11fb <is_disk_mounted+0x8b>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"df > /tmp/df\00"
@.str.1 = [8 x i8] c"/tmp/df\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"/dev/sd\00"
define i32 @is_disk_mounted() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [128 x i8]
%4 = call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %29
8: ; preds = %0
br label %9
9: ; preds = %25, %8
%10 = load i32*, i32** %2
%11 = call i32 @feof(i32* %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %26
14: ; preds = %9
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%16 = load i32*, i32** %2
%17 = call i32 @fgets(i8* %15, i32 128, i32* %16)
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%19 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%20 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %18, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = load i32*, i32** %2
%24 = call i32 @fclose(i32* %23)
store i32 1, i32* %1
br label %30
25: ; preds = %14
br label %9
26: ; preds = %9
%27 = load i32*, i32** %2
%28 = call i32 @fclose(i32* %27)
br label %29
29: ; preds = %26, %0
store i32 0, i32* %1
br label %30
30: ; preds = %29, %22
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [13 x i8] c"df > /tmp/df\00"
@.str.1 = [8 x i8] c"/tmp/df\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"/dev/sd\00"
define i32 @is_disk_mounted() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %17, label %6
6: ; preds = %0, %9
%7 = call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = call i32 @fgets(i8* %2, i32 128, i32* %4)
%11 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%12 = call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %2, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6, %9
%15 = phi i32 [ 1, %9 ], [ 0, %6 ]
%16 = call i32 @fclose(i32* %4)
br label %17
17: ; preds = %14, %0
%18 = phi i32 [ 0, %0 ], [ %15, %14 ]
ret i32 %18
}