#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*/ out;
typedef int /*<<< orphan*/ expect;
typedef int /*<<< orphan*/ bigdata;

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(char *, char, int);
int run_cmd_get_output(char *, int, char const **);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int test_run_cmd_get_output(void) {
  int ret;
  char out[64];
  char expect[64];
  char bigdata[8096];
  const char *echo1[] = {"echo", "foo", "bar", "and", "baz", NULL};
  const char *echo2[] = {"echo", bigdata, NULL};
  memset(bigdata, 'Z', sizeof(bigdata));
  bigdata[sizeof(bigdata) - 1] = '\0';
  ret = run_cmd_get_output(out, sizeof(out), echo1);
  if (ret) {
    fprintf(stderr, "run_cmd_get_output failed with error %d\n", ret);
    return ret;
  }
  if (strcmp(out, "foo bar and baz\n")) {
    fprintf(stderr,
            "test_run_cmd_get_output: echo1 failed. "
            "output was '%s'\n",
            out);
    return -EINVAL;
  }
  ret = run_cmd_get_output(out, sizeof(out), echo2);
  if (ret) {
    fprintf(stderr, "run_cmd_get_output failed with error %d\n", ret);
    return ret;
  }
  memset(expect, 'Z', sizeof(expect));
  expect[sizeof(expect) - 1] = '\0';
  if (strcmp(out, expect)) {
    fprintf(stderr,
            "test_run_cmd_get_output: echo2 failed. "
            "output was '%s'; expected '%s'\n",
            out, expect);
    return -EINVAL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_run_cmd_get_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2080,%rsp
lea    -0x2060(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
lea    0xe9b(%rip),%rax
mov    %rax,-0x2060(%rbp)
lea    0xe92(%rip),%rax
mov    %rax,-0x2058(%rbp)
lea    0xe88(%rip),%rax
mov    %rax,-0x2050(%rbp)
lea    0xe7e(%rip),%rax
mov    %rax,-0x2048(%rbp)
lea    0xe74(%rip),%rax
mov    %rax,-0x2040(%rbp)
lea    0xe55(%rip),%rax
mov    %rax,-0x2080(%rbp)
lea    -0x2030(%rbp),%rax
mov    %rax,-0x2078(%rbp)
movq   $0x0,-0x2070(%rbp)
lea    -0x2030(%rbp),%rdi
mov    $0x5a,%esi
mov    $0x1fa0,%edx
call   1040 <memset@plt>
movb   $0x0,-0x91(%rbp)
lea    -0x50(%rbp),%rdi
lea    -0x2060(%rbp),%rdx
mov    $0x40,%esi
call   1030 <run_cmd_get_output@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     122f <test_run_cmd_get_output+0xef>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    132e <test_run_cmd_get_output+0x1ee>
lea    -0x50(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1277 <test_run_cmd_get_output+0x137>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rdx
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    0x2d6b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    132e <test_run_cmd_get_output+0x1ee>
lea    -0x50(%rbp),%rdi
lea    -0x2080(%rbp),%rdx
mov    $0x40,%esi
call   1030 <run_cmd_get_output@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     12be <test_run_cmd_get_output+0x17e>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xd69(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    132e <test_run_cmd_get_output+0x1ee>
lea    -0x90(%rbp),%rdi
mov    $0x5a,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
movb   $0x0,-0x51(%rbp)
lea    -0x50(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1327 <test_run_cmd_get_output+0x1e7>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    0xd7a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    0x2cbb(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    132e <test_run_cmd_get_output+0x1ee>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2080,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_run_cmd_get_output>:
push   %rbx
sub    $0x2070,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
lea    0xea9(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xea2(%rip),%rcx
mov    %rcx,0x28(%rsp)
lea    0xe9a(%rip),%rcx
mov    %rcx,0x30(%rsp)
lea    0xe92(%rip),%rcx
mov    %rcx,0x38(%rsp)
lea    0xe8a(%rip),%rcx
mov    %rcx,0x40(%rsp)
mov    %rax,(%rsp)
lea    0xd0(%rsp),%rdi
mov    %rdi,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    $0x5a,%esi
mov    $0x1fa0,%edx
call   1040 <memset@plt>
movb   $0x0,0x206f(%rsp)
lea    0x50(%rsp),%rdi
lea    0x20(%rsp),%rdx
mov    $0x40,%esi
call   1030 <run_cmd_get_output@plt>
test   %eax,%eax
je     11f2 <test_run_cmd_get_output+0xb2>
mov    %eax,%ebx
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    122f <test_run_cmd_get_output+0xef>
lea    0xe45(%rip),%rsi
lea    0x50(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     123a <test_run_cmd_get_output+0xfa>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
xor    %ebx,%ebx
lea    0x50(%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2dab(%rip),%rax
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x2070,%rsp
pop    %rbx
ret
lea    0x50(%rsp),%rdi
mov    %rsp,%rdx
mov    $0x40,%esi
call   1030 <run_cmd_get_output@plt>
test   %eax,%eax
jne    11d5 <test_run_cmd_get_output+0x95>
lea    0x90(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x5a,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
movb   $0x0,0xcf(%rsp)
lea    0x50(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     12af <test_run_cmd_get_output+0x16f>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
xor    %ebx,%ebx
lea    0x50(%rsp),%rdx
lea    0x90(%rsp),%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1226 <test_run_cmd_get_output+0xe6>
xor    %ebx,%ebx
jmp    122f <test_run_cmd_get_output+0xef>

LLVM IR (-O0):
@.str = [5 x i8] c"echo\00"
@.str.1 = [4 x i8] c"foo\00"
@.str.2 = [4 x i8] c"bar\00"
@.str.3 = [4 x i8] c"and\00"
@.str.4 = [4 x i8] c"baz\00"
@stderr = global i32 0
@.str.5 = [41 x i8] c"run_cmd_get_output failed with error %d\0A\00"
@.str.6 = [17 x i8] c"foo bar and baz\0A\00"
@.str.7 = [56 x i8] c"test_run_cmd_get_output: echo1 failed. output was '%s'\0A\00"
@EINVAL = global i32 0
@.str.8 = [71 x i8] c"test_run_cmd_get_output: echo2 failed. output was '%s'; expected '%s'\0A\00"
define i32 @test_run_cmd_get_output() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [64 x i8]
%4 = alloca [64 x i8]
%5 = alloca [8096 x i8]
%6 = alloca [6 x i8*]
%7 = alloca [3 x i8*]
%8 = bitcast [6 x i8*]* %6 to i8*
%9 = bitcast i8* %8 to [6 x i8*]*
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
store i8* %17, i8** %16
%18 = getelementptr inbounds i8*, i8** %16, i64 1
store i8* null, i8** %18
%19 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i8 signext 90, i32 8096)
%21 = getelementptr inbounds [8096 x i8], [8096 x i8]* %5, i64 0, i64 8095
store i8 0, i8* %21
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%23 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 0
%24 = call i32 @run_cmd_get_output(i8* %22, i32 64, i8** %23)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %0
%28 = load i32, i32* @stderr
%29 = load i32, i32* %2
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %2
store i32 %31, i32* %1
br label %69
32: ; preds = %0
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EINVAL
%41 = sub nsw i32 0, %40
store i32 %41, i32* %1
br label %69
42: ; preds = %32
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%44 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
%45 = call i32 @run_cmd_get_output(i8* %43, i32 64, i8** %44)
store i32 %45, i32* %2
%46 = load i32, i32* %2
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %42
%49 = load i32, i32* @stderr
%50 = load i32, i32* %2
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %2
store i32 %52, i32* %1
br label %69
53: ; preds = %42
%54 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%55 = call i32 @memset(i8* %54, i8 signext 90, i32 64)
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 63
store i8 0, i8* %56
%57 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%58 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%59 = call i64 @strcmp(i8* %57, i8* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %68
61: ; preds = %53
%62 = load i32, i32* @stderr
%63 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%64 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.8, i64 0, i64 0), i8* %63, i8* %64)
%66 = load i32, i32* @EINVAL
%67 = sub nsw i32 0, %66
store i32 %67, i32* %1
br label %69
68: ; preds = %53
store i32 0, i32* %1
br label %69
69: ; preds = %68, %61, %48, %36, %27
%70 = load i32, i32* %1
ret i32 %70
}

LLVM IR (-O2):
@.str = [5 x i8] c"echo\00"
@.str.1 = [4 x i8] c"foo\00"
@.str.2 = [4 x i8] c"bar\00"
@.str.3 = [4 x i8] c"and\00"
@.str.4 = [4 x i8] c"baz\00"
@stderr = global i32 0
@.str.5 = [41 x i8] c"run_cmd_get_output failed with error %d\0A\00"
@.str.6 = [17 x i8] c"foo bar and baz\0A\00"
@.str.7 = [56 x i8] c"test_run_cmd_get_output: echo1 failed. output was '%s'\0A\00"
@EINVAL = global i32 0
@.str.8 = [71 x i8] c"test_run_cmd_get_output: echo2 failed. output was '%s'; expected '%s'\0A\00"
define i32 @test_run_cmd_get_output() {
%1 = alloca [64 x i8]
%2 = alloca [64 x i8]
%3 = alloca [8096 x i8]
%4 = alloca [6 x i8*]
%5 = alloca [3 x i8*]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [8096 x i8], [8096 x i8]* %3, i64 0, i64 0
%9 = bitcast [6 x i8*]* %4 to i8*
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 4
%11 = bitcast i8** %10 to i8*
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %16
%17 = bitcast [3 x i8*]* %5 to i8*
%18 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 1
store i8* %8, i8** %19
%20 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 2
store i8* null, i8** %20
%21 = call i32 @memset(i8* %8, i8 signext 90, i32 8096)
%22 = getelementptr inbounds [8096 x i8], [8096 x i8]* %3, i64 0, i64 8095
store i8 0, i8* %22
%23 = call i32 @run_cmd_get_output(i8* %6, i32 64, i8** %12)
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %0
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %23)
br label %52
28: ; preds = %0
%29 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0), i8* %6)
%34 = load i32, i32* @EINVAL
%35 = sub nsw i32 0, %34
br label %52
36: ; preds = %28
%37 = call i32 @run_cmd_get_output(i8* %6, i32 64, i8** %18)
%38 = icmp eq i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %37)
br label %52
42: ; preds = %36
%43 = call i32 @memset(i8* %7, i8 signext 90, i32 64)
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 63
store i8 0, i8* %44
%45 = call i64 @strcmp(i8* %6, i8* %7)
%46 = icmp eq i64 %45, 0
br i1 %46, label %52, label %47
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.8, i64 0, i64 0), i8* %6, i8* %7)
%50 = load i32, i32* @EINVAL
%51 = sub nsw i32 0, %50
br label %52
52: ; preds = %42, %47, %39, %31, %25
%53 = phi i32 [ %23, %25 ], [ %35, %31 ], [ %37, %39 ], [ %51, %47 ], [ 0, %42 ]
ret i32 %53
}