#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*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int fcntl(int, int /*<<< orphan*/, int);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char const *, char *);
FILE *call_command(const char *cmd) {
  int fd, flags;
  FILE *f = popen(cmd, "r");
  fd = fileno(f);
  flags = fcntl(fd, F_GETFL, 0);
  flags |= O_NONBLOCK;
  fcntl(fd, F_SETFL, flags);
  return f;
}


x86 assembly (clang, -O0):
<call_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
call   1030 <fcntl@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_command>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fileno@plt>
mov    %eax,%ebp
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    0x2e83(%rip),%rcx
or     (%rcx),%eax
mov    0x2e6a(%rip),%rcx
mov    (%rcx),%esi
mov    %ebp,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32* @call_command(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = call i32 @fileno(i32* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = load i32, i32* @F_GETFL
%12 = call i32 @fcntl(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %4
%13 = load i32, i32* @O_NONBLOCK
%14 = load i32, i32* %4
%15 = or i32 %14, %13
store i32 %15, i32* %4
%16 = load i32, i32* %3
%17 = load i32, i32* @F_SETFL
%18 = load i32, i32* %4
%19 = call i32 @fcntl(i32 %16, i32 %17, i32 %18)
%20 = load i32*, i32** %5
ret i32* %20
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define noalias i32* @call_command(i8* nocapture %0) {
%2 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @fileno(i32* %2)
%4 = load i32, i32* @F_GETFL
%5 = tail call i32 @fcntl(i32 %3, i32 %4, i32 0)
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %6, %5
%8 = load i32, i32* @F_SETFL
%9 = tail call i32 @fcntl(i32 %3, i32 %8, i32 %7)
ret i32* %2
}