#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 */

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stdout;
int write_cmd(int, char *);
int send_cmd(int fd, char *cmd, char **ans) {
  char buf[255];
  int n;
  n = write_cmd(fd, cmd);
  if (n != 0)
    return n;
  do {
    n = read(fd, buf, 254);
    buf[n] = '\0';
    fputs(buf, stdout);
  } while (n > 0);
  return 0;
}


x86 assembly (clang, -O0):
<send_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <write_cmd@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
je     1173 <send_cmd+0x43>
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ca <send_cmd+0x9a>
jmp    1178 <send_cmd+0x48>
mov    -0x8(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xfe,%edx
call   1040 <read@plt>
mov    %eax,-0x124(%rbp)
movslq -0x124(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
cmpl   $0x0,-0x124(%rbp)
jg     1178 <send_cmd+0x48>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_cmd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %edi,%r15d
call   1050 <write_cmd@plt>
test   %eax,%eax
jne    1188 <send_cmd+0x58>
mov    %rsp,%rbx
mov    0x2e8d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xfe,%edx
call   1040 <read@plt>
movslq %eax,%rbp
movb   $0x0,(%rsp,%rbp,1)
mov    (%r14),%esi
mov    %rbx,%rdi
call   1030 <fputs@plt>
test   %ebp,%ebp
jg     1160 <send_cmd+0x30>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define i32 @send_cmd(i32 %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca [255 x i8]
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%10 = load i32, i32* %5
%11 = load i8*, i8** %6
%12 = call i32 @write_cmd(i32 %10, i8* %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %9
store i32 %16, i32* %4
br label %32
17: ; preds = %3
br label %18
18: ; preds = %28, %17
%19 = load i32, i32* %5
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 254)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 %23
store i8 0, i8* %24
%25 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%26 = load i32, i32* @stdout
%27 = call i32 @fputs(i8* %25, i32 %26)
br label %28
28: ; preds = %18
%29 = load i32, i32* %9
%30 = icmp sgt i32 %29, 0
br i1 %30, label %18, label %31
31: ; preds = %28
store i32 0, i32* %4
br label %32
32: ; preds = %31, %15
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@stdout = global i32 0
define i32 @send_cmd(i32 %0, i8* %1, i8** nocapture readnone %2) {
%4 = alloca [255 x i8]
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @write_cmd(i32 %0, i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %3, %8
%9 = call i32 @read(i32 %0, i8* %5, i32 254)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 %10
store i8 0, i8* %11
%12 = load i32, i32* @stdout
%13 = call i32 @fputs(i8* %5, i32 %12)
%14 = icmp sgt i32 %9, 0
br i1 %14, label %8, label %15
15: ; preds = %8, %3
%16 = phi i32 [ %6, %3 ], [ 0, %8 ]
ret i32 %16
}