#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 */
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char const *, char *);
int do_command(const char *cmd) {
  FILE *f;
  int status;
  f = popen(cmd, "r");
  if (!f)
    return 0;
  status = fclose(f);
  return WIFEXITED(status) && WEXITSTATUS(status) == 0;
}


x86 assembly (clang, -O0):
<do_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1177 <do_command+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11ba <do_command+0x7a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <WIFEXITED@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1d(%rbp)
je     11af <do_command+0x6f>
mov    -0x1c(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_command>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rsi
call   1050 <popen@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     117b <do_command+0x3b>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
je     117b <do_command+0x3b>
mov    %ebp,%edi
call   1040 <WEXITSTATUS@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @do_command(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 0, i32* %2
br label %24
11: ; preds = %1
%12 = load i32*, i32** %4
%13 = call i32 @fclose(i32* %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = call i64 @WIFEXITED(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i32, i32* %5
%19 = call i64 @WEXITSTATUS(i32 %18)
%20 = icmp eq i64 %19, 0
br label %21
21: ; preds = %17, %11
%22 = phi i1 [ false, %11 ], [ %20, %17 ]
%23 = zext i1 %22 to i32
store i32 %23, i32* %2
br label %24
24: ; preds = %21, %10
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @do_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 = icmp eq i32* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i32 @fclose(i32* %2)
%6 = tail call i64 @WIFEXITED(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = tail call i64 @WEXITSTATUS(i32 %5)
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %4, %8, %1
%13 = phi i32 [ 0, %1 ], [ 0, %4 ], [ %11, %8 ]
ret i32 %13
}