#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 */
char EOF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char getc(int /*<<< orphan*/ *);
char *gettext(char *);
scalar_t__ malloc(int);
scalar_t__ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char const *, char *);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
char *command_output(const char *command) {
  int idxc = 0, bufsize_step = 4096, bufsize = bufsize_step;
  char *buffer = (char *)malloc(bufsize);
  if (!buffer) {
    fprintf(
        stderr,
        gettext("command_output(): malloc() failed: insufficient memory.\n"));
    return NULL;
  }
  FILE *found = popen(command, "r");
  if (!found) {
    fprintf(stderr, gettext("command_output(): Cannot into popen.\n"));
    return NULL;
  }
  while ((buffer[idxc] = getc(found)) != EOF) {
    if (strlen(buffer) > bufsize - 8) {
      buffer = (char *)realloc(buffer, bufsize += bufsize_step);
      if (!buffer) {
        fprintf(stderr, gettext("command_output(): realloc() failed: "
                                "insufficient memory.\n"));
        return NULL;
      }
    }
    idxc++;
  }
  if (pclose(found) != 0) {
    fprintf(stderr, gettext("command_output(): Cannot into pclose.\n"));
    return NULL;
  }
  buffer[idxc] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<command_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1000,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e7 <command_output+0x67>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
lea    0xe36(%rip),%rdi
call   1040 <gettext@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1336 <command_output+0x1b6>
mov    -0x10(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1236 <command_output+0xb6>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
lea    0xe22(%rip),%rdi
call   1040 <gettext@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1336 <command_output+0x1b6>
jmp    123b <command_output+0xbb>
mov    -0x30(%rbp),%rdi
call   10a0 <getc@plt>
mov    -0x28(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    %al,(%rcx,%rdx,1)
movsbl %al,%eax
mov    0x2d8f(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12df <command_output+0x15f>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1c(%rbp),%ecx
sub    $0x8,%ecx
cmp    %ecx,%eax
jle    12d1 <command_output+0x151>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    -0x1c(%rbp),%esi
mov    %esi,-0x1c(%rbp)
call   1080 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12cc <command_output+0x14c>
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
lea    0xdb2(%rip),%rdi
call   1040 <gettext@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1336 <command_output+0x1b6>
jmp    12d1 <command_output+0x151>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123b <command_output+0xbb>
mov    -0x30(%rbp),%rdi
call   1050 <pclose@plt>
cmp    $0x0,%rax
je     1322 <command_output+0x1a2>
mov    0x2cdf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
lea    0xd96(%rip),%rdi
call   1040 <gettext@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1336 <command_output+0x1b6>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<command_output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x1000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11d6 <command_output+0x56>
mov    %rax,%r15
lea    0xe92(%rip),%rsi
mov    %rbx,%rdi
call   1090 <popen@plt>
test   %rax,%rax
je     11eb <command_output+0x6b>
mov    %rax,%r14
mov    %rax,%rdi
call   10a0 <getc@plt>
mov    %al,(%r15)
mov    0x2e1f(%rip),%r12
cmp    (%r12),%al
jne    1200 <command_output+0x80>
xor    %ebx,%ebx
jmp    1268 <command_output+0xe8>
mov    0x2dfb(%rip),%rax
mov    (%rax),%ebx
lea    0xe1a(%rip),%rdi
jmp    1285 <command_output+0x105>
mov    0x2de6(%rip),%rax
mov    (%rax),%ebx
lea    0xe40(%rip),%rdi
jmp    1285 <command_output+0x105>
mov    $0x1000,%r13d
xor    %ebx,%ebx
jmp    122a <command_output+0xaa>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%rbp
mov    %r14,%rdi
call   10a0 <getc@plt>
mov    %al,0x1(%r15,%rbx,1)
mov    %rbp,%rbx
cmp    (%r12),%al
je     1266 <command_output+0xe6>
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    -0x8(%r13),%ecx
cmp    %ecx,%eax
jle    1210 <command_output+0x90>
add    $0x1000,%r13d
mov    %r15,%rdi
mov    %r13d,%esi
call   1080 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1210 <command_output+0x90>
mov    0x2d7d(%rip),%rax
mov    (%rax),%ebx
lea    0xdfd(%rip),%rdi
jmp    1285 <command_output+0x105>
mov    %ebp,%ebx
mov    %r14,%rdi
call   1050 <pclose@plt>
test   %rax,%rax
je     12a9 <command_output+0x129>
mov    0x2d5c(%rip),%rax
mov    (%rax),%ebx
lea    0xe16(%rip),%rdi
call   1040 <gettext@plt>
mov    %ebx,%edi
mov    %rax,%rsi
call   1060 <fprintf@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,(%r15,%rbx,1)
jmp    1297 <command_output+0x117>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [57 x i8] c"command_output(): malloc() failed: insufficient memory.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [38 x i8] c"command_output(): Cannot into popen.\0A\00"
@EOF = global i8 0
@.str.3 = [58 x i8] c"command_output(): realloc() failed: insufficient memory.\0A\00"
@.str.4 = [39 x i8] c"command_output(): Cannot into pclose.\0A\00"
define i8* @command_output(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 4096, i32* %5
%9 = load i32, i32* %5
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = call i8* @gettext(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @fprintf(i32 %16, i8* %17)
store i8* null, i8** %2
br label %77
19: ; preds = %1
%20 = load i8*, i8** %3
%21 = call i32* @popen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %8
%22 = load i32*, i32** %8
%23 = icmp ne i32* %22, null
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i8* @gettext(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @fprintf(i32 %25, i8* %26)
store i8* null, i8** %2
br label %77
28: ; preds = %19
br label %29
29: ; preds = %60, %28
%30 = load i32*, i32** %8
%31 = call signext i8 @getc(i32* %30)
%32 = load i8*, i8** %7
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
%36 = sext i8 %31 to i32
%37 = load i8, i8* @EOF
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %36, %38
br i1 %39, label %40, label %63
40: ; preds = %29
%41 = load i8*, i8** %7
%42 = call i32 @strlen(i8* %41)
%43 = load i32, i32* %6
%44 = sub nsw i32 %43, 8
%45 = icmp sgt i32 %42, %44
br i1 %45, label %46, label %60
46: ; preds = %40
%47 = load i8*, i8** %7
%48 = load i32, i32* %5
%49 = load i32, i32* %6
%50 = add nsw i32 %49, %48
store i32 %50, i32* %6
%51 = call i64 @realloc(i8* %47, i32 %50)
%52 = inttoptr i64 %51 to i8*
store i8* %52, i8** %7
%53 = load i8*, i8** %7
%54 = icmp ne i8* %53, null
br i1 %54, label %59, label %55
55: ; preds = %46
%56 = load i32, i32* @stderr
%57 = call i8* @gettext(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @fprintf(i32 %56, i8* %57)
store i8* null, i8** %2
br label %77
59: ; preds = %46
br label %60
60: ; preds = %59, %40
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %4
br label %29
63: ; preds = %29
%64 = load i32*, i32** %8
%65 = call i64 @pclose(i32* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = call i8* @gettext(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%70 = call i32 @fprintf(i32 %68, i8* %69)
store i8* null, i8** %2
br label %77
71: ; preds = %63
%72 = load i8*, i8** %7
%73 = load i32, i32* %4
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
store i8 0, i8* %75
%76 = load i8*, i8** %7
store i8* %76, i8** %2
br label %77
77: ; preds = %71, %67, %55, %24, %15
%78 = load i8*, i8** %2
ret i8* %78
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [57 x i8] c"command_output(): malloc() failed: insufficient memory.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [38 x i8] c"command_output(): Cannot into popen.\0A\00"
@EOF = global i8 0
@.str.3 = [58 x i8] c"command_output(): realloc() failed: insufficient memory.\0A\00"
@.str.4 = [39 x i8] c"command_output(): Cannot into pclose.\0A\00"
define i8* @command_output(i8* nocapture %0) {
%2 = tail call i64 @malloc(i32 4096)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i8* @gettext(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @fprintf(i32 %5, i8* %6)
br label %57
8: ; preds = %1
%9 = inttoptr i64 %2 to i8*
%10 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = tail call signext i8 @getc(i32* %10)
store i8 %13, i8* %9
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %13, %14
br i1 %15, label %46, label %20
16: ; preds = %8
%17 = load i32, i32* @stderr
%18 = tail call i8* @gettext(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @fprintf(i32 %17, i8* %18)
br label %57
20: ; preds = %12, %36
%21 = phi i64 [ %39, %36 ], [ 0, %12 ]
%22 = phi i8* [ %38, %36 ], [ %9, %12 ]
%23 = phi i32 [ %37, %36 ], [ 4096, %12 ]
%24 = tail call i32 @strlen(i8* %22)
%25 = add nsw i32 %23, -8
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %36
27: ; preds = %20
%28 = add nsw i32 %23, 4096
%29 = tail call i64 @realloc(i8* %22, i32 %28)
%30 = inttoptr i64 %29 to i8*
%31 = icmp eq i64 %29, 0
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = tail call i8* @gettext(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0))
%35 = tail call i32 @fprintf(i32 %33, i8* %34)
br label %57
36: ; preds = %27, %20
%37 = phi i32 [ %28, %27 ], [ %23, %20 ]
%38 = phi i8* [ %30, %27 ], [ %22, %20 ]
%39 = add nuw i64 %21, 1
%40 = tail call signext i8 @getc(i32* %10)
%41 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 %40, i8* %41
%42 = load i8, i8* @EOF
%43 = icmp eq i8 %40, %42
br i1 %43, label %44, label %20
44: ; preds = %36
%45 = and i64 %39, 4294967295
br label %46
46: ; preds = %44, %12
%47 = phi i64 [ 0, %12 ], [ %45, %44 ]
%48 = phi i8* [ %9, %12 ], [ %38, %44 ]
%49 = tail call i64 @pclose(i32* %10)
%50 = icmp eq i64 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %46
%52 = load i32, i32* @stderr
%53 = tail call i8* @gettext(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%54 = tail call i32 @fprintf(i32 %52, i8* %53)
br label %57
55: ; preds = %46
%56 = getelementptr inbounds i8, i8* %48, i64 %47
store i8 0, i8* %56
br label %57
57: ; preds = %16, %32, %51, %55, %4
%58 = phi i8* [ null, %4 ], [ null, %32 ], [ null, %51 ], [ %48, %55 ], [ null, %16 ]
ret i8* %58
}