#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*/ output;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ isEqual(char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
char *getDistro() {
  char *distro;
  char output[64];
  FILE *process;
  process = popen(". /etc/os-release 2>/dev/null; echo $ID 2>/dev/null", "r");
  while (fgets(output, sizeof(output) - 1, process) != NULL) {
    distro = &output[0];
  }
  pclose(process);
  if (isEqual(distro, "")) {
    distro = "unknown";
  }
  return distro;
}


x86 assembly (clang, -O0):
<getDistro>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xeb1(%rip),%rdi
lea    0xede(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    $0x3f,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1188 <getDistro+0x48>
lea    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    115f <getDistro+0x1f>
mov    -0x58(%rbp),%rdi
call   1030 <pclose@plt>
mov    -0x8(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1060 <isEqual@plt>
cmp    $0x0,%rax
je     11b6 <getDistro+0x76>
lea    0xe84(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDistro>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xeb2(%rip),%rdi
lea    0xedf(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x3f,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1160 <getDistro+0x20>
mov    %rbx,%rdi
call   1030 <pclose@plt>
lea    0xeaf(%rip),%rsi
mov    %r14,%rdi
call   1060 <isEqual@plt>
test   %rax,%rax
lea    0xea0(%rip),%rax
cmove  %r14,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [52 x i8] c". /etc/os-release 2>/dev/null; echo $ID 2>/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [8 x i8] c"unknown\00"
define i8* @getDistro() {
%1 = alloca i8*
%2 = alloca [64 x i8]
%3 = alloca i32*
%4 = call i32* @popen(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
br label %5
5: ; preds = %10, %0
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%7 = load i32*, i32** %3
%8 = call i32* @fgets(i8* %6, i32 63, i32* %7)
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
store i8* %11, i8** %1
br label %5
12: ; preds = %5
%13 = load i32*, i32** %3
%14 = call i32 @pclose(i32* %13)
%15 = load i8*, i8** %1
%16 = call i64 @isEqual(i8* %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %19
19: ; preds = %18, %12
%20 = load i8*, i8** %1
ret i8* %20
}

LLVM IR (-O2):
@.str = [52 x i8] c". /etc/os-release 2>/dev/null; echo $ID 2>/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [8 x i8] c"unknown\00"
define i8* @getDistro() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %4, %0
%5 = call i32* @fgets(i8* %2, i32 63, i32* %3)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %4
7: ; preds = %4
%8 = call i32 @pclose(i32* %3)
%9 = call i64 @isEqual(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
ret i8* %11
}