#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
char *realloc(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
char *getPythonProvider() {
  int buffer_length = 128;
  char buffer[buffer_length];
  char *result = malloc(1);
  *result = 0;
  FILE *pipe = popen("python2 --version 2>&1", "r");
  if (!pipe) {
    printf("Cant start command.");
  }
  while (fgets(buffer, 128, pipe) != NULL) {
    result = realloc(result, (result ? strlen(result) : 0) + buffer_length);
    strcat(result, buffer);
  }
  if (strstr(result, "not found") == NULL) {
    return "python2";
  }
  result = malloc(1);
  *result = 0;
  pipe = popen("python3 --version 2>&1", "r");
  if (!pipe) {
    printf("Cant start command.");
  }
  while (fgets(buffer, 128, pipe) != NULL) {
    result = realloc(result, (result ? strlen(result) : 0) + buffer_length);
    strcat(result, buffer);
  }
  if (strstr(result, "not found") == NULL) {
    return "python3";
  }
  return "python";
}


x86 assembly (clang, -O0):
<getPythonProvider>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x80,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
lea    0xe2f(%rip),%rdi
lea    0xe3f(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f8 <getPythonProvider+0x78>
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
jmp    11fd <getPythonProvider+0x7d>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     126c <getPythonProvider+0xec>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     123d <getPythonProvider+0xbd>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4c(%rbp)
jmp    1247 <getPythonProvider+0xc7>
xor    %eax,%eax
mov    %eax,-0x4c(%rbp)
jmp    1247 <getPythonProvider+0xc7>
mov    -0x48(%rbp),%rdi
mov    -0x4c(%rbp),%esi
add    -0xc(%rbp),%esi
call   1070 <realloc@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <strcat@plt>
jmp    11fd <getPythonProvider+0x7d>
mov    -0x28(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
jne    129d <getPythonProvider+0x11d>
lea    0xdaa(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1397 <getPythonProvider+0x217>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
lea    0xd86(%rip),%rdi
lea    0xd57(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12e0 <getPythonProvider+0x160>
lea    0xd3e(%rip),%rdi
call   1040 <printf@plt>
jmp    12e5 <getPythonProvider+0x165>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1354 <getPythonProvider+0x1d4>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1325 <getPythonProvider+0x1a5>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x5c(%rbp)
jmp    132f <getPythonProvider+0x1af>
xor    %eax,%eax
mov    %eax,-0x5c(%rbp)
jmp    132f <getPythonProvider+0x1af>
mov    -0x58(%rbp),%rdi
mov    -0x5c(%rbp),%esi
add    -0xc(%rbp),%esi
call   1070 <realloc@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <strcat@plt>
jmp    12e5 <getPythonProvider+0x165>
mov    -0x28(%rbp),%rdi
lea    0xcce(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
jne    1385 <getPythonProvider+0x205>
lea    0xce1(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1397 <getPythonProvider+0x217>
lea    0xcd2(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPythonProvider>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xe5d(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11c3 <getPythonProvider+0x43>
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1221 <getPythonProvider+0xa1>
mov    %rsp,%r15
jmp    1218 <getPythonProvider+0x98>
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
sub    $0xffffff80,%esi
mov    %rbx,%rdi
call   1070 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %r15,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1221 <getPythonProvider+0xa1>
test   %rbx,%rbx
jne    11e0 <getPythonProvider+0x60>
xor    %esi,%esi
jmp    11ea <getPythonProvider+0x6a>
lea    0xe05(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     12f7 <getPythonProvider+0x177>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xdef(%rip),%rdi
lea    0xdc0(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1270 <getPythonProvider+0xf0>
lea    0xdae(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12d1 <getPythonProvider+0x151>
mov    %rsp,%r15
jmp    12c8 <getPythonProvider+0x148>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
sub    $0xffffff80,%esi
mov    %rbx,%rdi
call   1070 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %r15,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12d1 <getPythonProvider+0x151>
test   %rbx,%rbx
jne    1290 <getPythonProvider+0x110>
xor    %esi,%esi
jmp    129a <getPythonProvider+0x11a>
lea    0xd55(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
lea    0xd6c(%rip),%rcx
lea    0xd6d(%rip),%rax
cmove  %rcx,%rax
jmp    12fe <getPythonProvider+0x17e>
lea    0xd39(%rip),%rax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"python2 --version 2>&1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"Cant start command.\00"
@.str.3 = [10 x i8] c"not found\00"
@.str.4 = [8 x i8] c"python2\00"
@.str.5 = [23 x i8] c"python3 --version 2>&1\00"
@.str.6 = [8 x i8] c"python3\00"
@.str.7 = [7 x i8] c"python\00"
define i8* @getPythonProvider() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i32 128, i32* %2
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i8, i64 %9
store i64 %9, i64* %4
%12 = call i8* @malloc(i32 1)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
store i8 0, i8* %13
%14 = call i32* @popen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %19, label %17
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %0
br label %20
20: ; preds = %32, %19
%21 = load i32*, i32** %6
%22 = call i32* @fgets(i8* %11, i32 128, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = load i8*, i8** %5
%26 = load i8*, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i8*, i8** %5
%30 = call i32 @strlen(i8* %29)
br label %32
31: ; preds = %24
br label %32
32: ; preds = %31, %28
%33 = phi i32 [ %30, %28 ], [ 0, %31 ]
%34 = load i32, i32* %2
%35 = add nsw i32 %33, %34
%36 = call i8* @realloc(i8* %25, i32 %35)
store i8* %36, i8** %5
%37 = load i8*, i8** %5
%38 = call i32 @strcat(i8* %37, i8* %11)
br label %20
39: ; preds = %20
%40 = load i8*, i8** %5
%41 = call i32* @strstr(i8* %40, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %44
43: ; preds = %39
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %1
store i32 1, i32* %7
br label %78
44: ; preds = %39
%45 = call i8* @malloc(i32 1)
store i8* %45, i8** %5
%46 = load i8*, i8** %5
store i8 0, i8* %46
%47 = call i32* @popen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %47, i32** %6
%48 = load i32*, i32** %6
%49 = icmp ne i32* %48, null
br i1 %49, label %52, label %50
50: ; preds = %44
%51 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %44
br label %53
53: ; preds = %65, %52
%54 = load i32*, i32** %6
%55 = call i32* @fgets(i8* %11, i32 128, i32* %54)
%56 = icmp ne i32* %55, null
br i1 %56, label %57, label %72
57: ; preds = %53
%58 = load i8*, i8** %5
%59 = load i8*, i8** %5
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = load i8*, i8** %5
%63 = call i32 @strlen(i8* %62)
br label %65
64: ; preds = %57
br label %65
65: ; preds = %64, %61
%66 = phi i32 [ %63, %61 ], [ 0, %64 ]
%67 = load i32, i32* %2
%68 = add nsw i32 %66, %67
%69 = call i8* @realloc(i8* %58, i32 %68)
store i8* %69, i8** %5
%70 = load i8*, i8** %5
%71 = call i32 @strcat(i8* %70, i8* %11)
br label %53
72: ; preds = %53
%73 = load i8*, i8** %5
%74 = call i32* @strstr(i8* %73, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%75 = icmp eq i32* %74, null
br i1 %75, label %76, label %77
76: ; preds = %72
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %1
store i32 1, i32* %7
br label %78
77: ; preds = %72
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %1
store i32 1, i32* %7
br label %78
78: ; preds = %77, %76, %43
%79 = load i8*, i8** %3
%80 = load i8*, i8** %1
ret i8* %80
}

LLVM IR (-O2):
@.str = [23 x i8] c"python2 --version 2>&1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"Cant start command.\00"
@.str.3 = [10 x i8] c"not found\00"
@.str.4 = [8 x i8] c"python2\00"
@.str.5 = [23 x i8] c"python3 --version 2>&1\00"
@.str.6 = [8 x i8] c"python3\00"
@.str.7 = [7 x i8] c"python\00"
define i8* @getPythonProvider() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
store i8 0, i8* %3
%4 = tail call i32* @popen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32* @fgets(i8* %2, i32 128, i32* %4)
%10 = icmp eq i32* %9, null
br i1 %10, label %23, label %11
11: ; preds = %8, %16
%12 = phi i8* [ %19, %16 ], [ %3, %8 ]
%13 = icmp eq i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @strlen(i8* %12)
br label %16
16: ; preds = %11, %14
%17 = phi i32 [ %15, %14 ], [ 0, %11 ]
%18 = add nsw i32 %17, 128
%19 = call i8* @realloc(i8* %12, i32 %18)
%20 = call i32 @strcat(i8* %19, i8* %2)
%21 = call i32* @fgets(i8* %2, i32 128, i32* %4)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %11
23: ; preds = %16, %8
%24 = phi i8* [ %3, %8 ], [ %19, %16 ]
%25 = call i32* @strstr(i8* dereferenceable(1) %24, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %53, label %27
27: ; preds = %23
%28 = call dereferenceable_or_null(1) i8* @malloc(i32 1)
store i8 0, i8* %28
%29 = call i32* @popen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = call i32* @fgets(i8* %2, i32 128, i32* %29)
%35 = icmp eq i32* %34, null
br i1 %35, label %48, label %36
36: ; preds = %33, %41
%37 = phi i8* [ %44, %41 ], [ %28, %33 ]
%38 = icmp eq i8* %37, null
br i1 %38, label %41, label %39
39: ; preds = %36
%40 = call i32 @strlen(i8* %37)
br label %41
41: ; preds = %36, %39
%42 = phi i32 [ %40, %39 ], [ 0, %36 ]
%43 = add nsw i32 %42, 128
%44 = call i8* @realloc(i8* %37, i32 %43)
%45 = call i32 @strcat(i8* %44, i8* %2)
%46 = call i32* @fgets(i8* %2, i32 128, i32* %29)
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %36
48: ; preds = %41, %33
%49 = phi i8* [ %28, %33 ], [ %44, %41 ]
%50 = call i32* @strstr(i8* dereferenceable(1) %49, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%51 = icmp eq i32* %50, null
%52 = select i1 %51, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0)
br label %53
53: ; preds = %48, %23
%54 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), %23 ], [ %52, %48 ]
ret i8* %54
}