#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strstr(char *, char *);
int dir_get(char *arg, char *buf) {
  FILE *fp;
  int ret;
  sprintf(buf, "df -h | awk '/dev\\/%s/ {print $6}'", arg);
  fp = popen(buf, "r");
  if (fp) {
    fgets(buf, 30, fp);
    if (strstr(buf, "/media/pi/"))
      ret = 1;
    else
      ret = 0;
  } else {
    ret = -1;
  }
  pclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<dir_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe91(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d7 <dir_get+0x87>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1e,%esi
call   1040 <fgets@plt>
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     11cb <dir_get+0x7b>
movl   $0x1,-0x1c(%rbp)
jmp    11d2 <dir_get+0x82>
movl   $0x0,-0x1c(%rbp)
jmp    11de <dir_get+0x8e>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <pclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_get>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rdx
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <sprintf@plt>
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
call   1050 <popen@plt>
mov    %rax,%r14
test   %rax,%rax
je     11a9 <dir_get+0x59>
mov    %rbx,%rdi
mov    $0x1e,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
jmp    11ae <dir_get+0x5e>
mov    $0xffffffff,%ebx
mov    %r14,%rdi
call   1030 <pclose@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [35 x i8] c"df -h | awk '/dev\\/%s/ {print $6}'\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"/media/pi/\00"
define i32 @dir_get(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %4
%11 = call i32* @popen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = load i32*, i32** %5
%17 = call i32 @fgets(i8* %15, i32 30, i32* %16)
%18 = load i8*, i8** %4
%19 = call i64 @strstr(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 1, i32* %6
br label %23
22: ; preds = %14
store i32 0, i32* %6
br label %23
23: ; preds = %22, %21
br label %25
24: ; preds = %2
store i32 -1, i32* %6
br label %25
25: ; preds = %24, %23
%26 = load i32*, i32** %5
%27 = call i32 @pclose(i32* %26)
%28 = load i32, i32* %6
ret i32 %28
}

LLVM IR (-O2):
@.str = [35 x i8] c"df -h | awk '/dev\\/%s/ {print $6}'\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"/media/pi/\00"
define i32 @dir_get(i8* %0, i8* %1) {
%3 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i32* @popen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call i32 @fgets(i8* %1, i32 30, i32* %4)
%8 = tail call i64 @strstr(i8* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %2, %6
%12 = phi i32 [ %10, %6 ], [ -1, %2 ]
%13 = tail call i32 @pclose(i32* %4)
ret i32 %12
}