#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*/ clean_retbuf(char *, char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ runtime_exception(char *, char *, int);
char *strdup(char *);
char *do_popen(char *command) {
  char *ret;
  char buffer[4096] = {0};
  FILE *outshell;
  if ((outshell = popen(command, "r")) == NULL) {
    printf("command [%s] no pipe open!\n", command);
    return NULL;
  }
  if (fgets(buffer, 4096, outshell) == NULL) {
    printf("command [%s] return no any answer!\n", command);
    return NULL;
  }
  pclose(outshell);
  clean_retbuf(buffer, "\r\n");
  if (((ret) = strdup(buffer)) == NULL) {
    {
      runtime_exception("damn, unable to allocate memory [FILE: %s LINE: %u]",
                        "/scratch/repos/new/home/jordi_armengol_estape/"
                        "c-scraper/outputs/2022-01-22/02-19-57/repos/evilaliv3/"
                        "janus/refs/heads/master/src/os_cmds.c",
                        174);
    }
  };
  return ret;
}


x86 assembly (clang, -O0):
<do_popen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
jne    11e0 <do_popen+0x60>
mov    -0x10(%rbp),%rsi
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1278 <do_popen+0xf8>
lea    -0x1020(%rbp),%rdi
mov    -0x1028(%rbp),%rdx
mov    $0x1000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    121f <do_popen+0x9f>
mov    -0x10(%rbp),%rsi
lea    0xe11(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1278 <do_popen+0xf8>
mov    -0x1028(%rbp),%rdi
call   1050 <pclose@plt>
lea    -0x1020(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1080 <clean_retbuf@plt>
lea    -0x1020(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1270 <do_popen+0xf0>
lea    0xde6(%rip),%rdi
lea    0xe13(%rip),%rsi
mov    $0xae,%edx
call   1030 <runtime_exception@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_popen>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe5d(%rip),%rsi
mov    %r14,%rdi
call   1090 <popen@plt>
test   %rax,%rax
je     1209 <do_popen+0x89>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1212 <do_popen+0x92>
mov    %rbx,%rdi
call   1050 <pclose@plt>
lea    0xe6b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <clean_retbuf@plt>
mov    %rbx,%rdi
call   10a0 <strdup@plt>
test   %rax,%rax
jne    1223 <do_popen+0xa3>
lea    0xe4f(%rip),%rdi
lea    0xe7c(%rip),%rsi
mov    $0xae,%edx
call   1030 <runtime_exception@plt>
jmp    1221 <do_popen+0xa1>
lea    0xdf2(%rip),%rdi
jmp    1219 <do_popen+0x99>
lea    0xe05(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"command [%s] no pipe open!\0A\00"
@.str.2 = [36 x i8] c"command [%s] return no any answer!\0A\00"
@.str.3 = [3 x i8] c"\0D\0A\00"
@.str.4 = [52 x i8] c"damn, unable to allocate memory [FILE: %s LINE: %u]\00"
@.str.5 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/evilaliv3/janus/refs/heads/master/src/os_cmds.c\00"
define i8* @do_popen(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [4096 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
%7 = bitcast [4096 x i8]* %5 to i8*
%8 = load i8*, i8** %3
%9 = call i32* @popen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store i8* null, i8** %2
br label %34
14: ; preds = %1
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i32* @fgets(i8* %15, i32 4096, i32* %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %20)
store i8* null, i8** %2
br label %34
22: ; preds = %14
%23 = load i32*, i32** %6
%24 = call i32 @pclose(i32* %23)
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%26 = call i32 @clean_retbuf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%28 = call i8* @strdup(i8* %27)
store i8* %28, i8** %4
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = call i32 @runtime_exception(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.5, i64 0, i64 0), i32 174)
br label %32
32: ; preds = %30, %22
%33 = load i8*, i8** %4
store i8* %33, i8** %2
br label %34
34: ; preds = %32, %19, %11
%35 = load i8*, i8** %2
ret i8* %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"command [%s] no pipe open!\0A\00"
@.str.2 = [36 x i8] c"command [%s] return no any answer!\0A\00"
@.str.3 = [3 x i8] c"\0D\0A\00"
@.str.4 = [52 x i8] c"damn, unable to allocate memory [FILE: %s LINE: %u]\00"
@.str.5 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/evilaliv3/janus/refs/heads/master/src/os_cmds.c\00"
define noalias i8* @do_popen(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %20
8: ; preds = %1
%9 = call i32* @fgets(i8* %3, i32 4096, i32* %4)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %20
13: ; preds = %8
%14 = call i32 @pclose(i32* %4)
%15 = call i32 @clean_retbuf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%16 = call i8* @strdup(i8* %3)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @runtime_exception(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.5, i64 0, i64 0), i32 174)
br label %20
20: ; preds = %13, %18, %11, %6
%21 = phi i8* [ null, %6 ], [ null, %11 ], [ null, %18 ], [ %16, %13 ]
ret i8* %21
}