#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*/ buf;
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*/ sscanf(char *, char *, int *);
int check_capacity(void) {
  FILE *ps;
  char buf[8] = {0};
  int percent;
  if ((ps = popen("df -h | grep rootfs | awk '{print $5}'", "r")) == NULL)
    return -1;
  fgets(buf, sizeof(buf), ps);
  pclose(ps);
  sscanf(buf, "%d", &percent);
  return percent;
}


x86 assembly (clang, -O0):
<check_capacity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    0xe91(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1195 <check_capacity+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ca <check_capacity+0x7a>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x8,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1030 <pclose@plt>
lea    -0x18(%rbp),%rdi
lea    0xe6e(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_capacity>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
lea    0xea9(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     11a2 <check_capacity+0x62>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x8,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1030 <pclose@plt>
lea    0xe9a(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1050 <sscanf@plt>
mov    0xc(%rsp),%eax
jmp    11a7 <check_capacity+0x67>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [39 x i8] c"df -h | grep rootfs | awk '{print $5}'\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @check_capacity() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [8 x i8]
%4 = alloca i32
%5 = bitcast [8 x i8]* %3 to i8*
%6 = call i32* @popen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %18
9: ; preds = %0
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i32 @fgets(i8* %10, i32 8, i32* %11)
%13 = load i32*, i32** %2
%14 = call i32 @pclose(i32* %13)
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%17 = load i32, i32* %4
store i32 %17, i32* %1
br label %18
18: ; preds = %9, %8
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [39 x i8] c"df -h | grep rootfs | awk '{print $5}'\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @check_capacity() {
%1 = alloca i64
%2 = alloca i32
%3 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%4 = bitcast i32* %2 to i8*
%5 = tail call i32* @popen(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %12, label %7
7: ; preds = %0
%8 = call i32 @fgets(i8* %3, i32 8, i32* %5)
%9 = call i32 @pclose(i32* %5)
%10 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
br label %12
12: ; preds = %0, %7
%13 = phi i32 [ %11, %7 ], [ -1, %0 ]
ret i32 %13
}