#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*/ int32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ fgets(char *, int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ iscntrl(char);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char const *, char *);
int strlen(char *);
bool runCommand(const char *command, char *buff, size_t len) {
  if (len <= 0) {
    return false;
  }
  FILE *fp;
  bool result = false;
  fp = popen(command, "r");
  if (fp) {
    if (fgets(buff, (int32_t)len, fp)) {
      result = true;
      char *idx = buff + strlen(buff) - 1;
      while (idx > buff && iscntrl(*idx)) {
        *idx-- = '\0';
      }
    }
    pclose(fp);
  } else {
    buff[0] = '\0';
  }
  return result;
}


x86 assembly (clang, -O0):
<runCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
ja     117b <runCommand+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    125a <runCommand+0x10a>
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     124d <runCommand+0xfd>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     123f <runCommand+0xef>
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x41(%rbp)
jbe    1213 <runCommand+0xc3>
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1030 <iscntrl@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1223 <runCommand+0xd3>
jmp    123a <runCommand+0xea>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
jmp    11ea <runCommand+0x9a>
jmp    123f <runCommand+0xef>
mov    -0x28(%rbp),%rdi
call   1050 <pclose@plt>
jmp    1254 <runCommand+0x104>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runCommand>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
test   %rdx,%rdx
je     11dd <runCommand+0x8d>
mov    %rdx,%rbp
mov    %rsi,%rbx
lea    0xe94(%rip),%rsi
call   1070 <popen@plt>
test   %rax,%rax
je     11cd <runCommand+0x7d>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d2 <runCommand+0x82>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rbp
add    $0xffffffffffffffff,%rbp
mov    $0x1,%r15d
cmp    %rbx,%rbp
jbe    11d5 <runCommand+0x85>
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%rbp),%edi
call   1030 <iscntrl@plt>
test   %rax,%rax
je     11d5 <runCommand+0x85>
movb   $0x0,0x0(%rbp)
add    $0xffffffffffffffff,%rbp
cmp    %rbx,%rbp
ja     11b0 <runCommand+0x60>
jmp    11d5 <runCommand+0x85>
movb   $0x0,(%rbx)
jmp    11dd <runCommand+0x8d>
xor    %r15d,%r15d
mov    %r14,%rdi
call   1050 <pclose@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @runCommand(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%11 = load i64, i64* %7
%12 = icmp ule i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 0, i32* %4
br label %56
14: ; preds = %3
store i32 0, i32* %9
%15 = load i8*, i8** %5
%16 = call i32* @popen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %8
%17 = load i32*, i32** %8
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %51
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = load i64, i64* %7
%22 = trunc i64 %21 to i32
%23 = load i32*, i32** %8
%24 = call i64 @fgets(i8* %20, i32 %22, i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %48
26: ; preds = %19
store i32 1, i32* %9
%27 = load i8*, i8** %6
%28 = load i8*, i8** %6
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = getelementptr inbounds i8, i8* %31, i64 -1
store i8* %32, i8** %10
br label %33
33: ; preds = %44, %26
%34 = load i8*, i8** %10
%35 = load i8*, i8** %6
%36 = icmp ugt i8* %34, %35
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i8*, i8** %10
%39 = load i8, i8* %38
%40 = call i64 @iscntrl(i8 signext %39)
%41 = icmp ne i64 %40, 0
br label %42
42: ; preds = %37, %33
%43 = phi i1 [ false, %33 ], [ %41, %37 ]
br i1 %43, label %44, label %47
44: ; preds = %42
%45 = load i8*, i8** %10
%46 = getelementptr inbounds i8, i8* %45, i32 -1
store i8* %46, i8** %10
store i8 0, i8* %45
br label %33
47: ; preds = %42
br label %48
48: ; preds = %47, %19
%49 = load i32*, i32** %8
%50 = call i32 @pclose(i32* %49)
br label %54
51: ; preds = %14
%52 = load i8*, i8** %6
%53 = getelementptr inbounds i8, i8* %52, i64 0
store i8 0, i8* %53
br label %54
54: ; preds = %51, %48
%55 = load i32, i32* %9
store i32 %55, i32* %4
br label %56
56: ; preds = %54, %13
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @runCommand(i8* nocapture %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %30, label %5
5: ; preds = %3
%6 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %29, label %8
8: ; preds = %5
%9 = trunc i64 %2 to i32
%10 = tail call i64 @fgets(i8* %1, i32 %9, i32* %6)
%11 = icmp eq i64 %10, 0
br i1 %11, label %26, label %12
12: ; preds = %8
%13 = tail call i32 @strlen(i8* %1)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = icmp ugt i8* %16, %1
br i1 %17, label %18, label %26
18: ; preds = %12, %23
%19 = phi i8* [ %24, %23 ], [ %16, %12 ]
%20 = load i8, i8* %19
%21 = tail call i64 @iscntrl(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
store i8 0, i8* %19
%24 = getelementptr inbounds i8, i8* %19, i64 -1
%25 = icmp ugt i8* %24, %1
br i1 %25, label %18, label %26
26: ; preds = %23, %18, %12, %8
%27 = phi i32 [ 0, %8 ], [ 1, %12 ], [ 1, %18 ], [ 1, %23 ]
%28 = tail call i32 @pclose(i32* %6)
br label %30
29: ; preds = %5
store i8 0, i8* %1
br label %30
30: ; preds = %26, %29, %3
%31 = phi i32 [ 0, %3 ], [ %27, %26 ], [ 0, %29 ]
ret i32 %31
}