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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
char *get_system_info(void) {
  FILE *fp;
  static char buf[1000];
  fp = popen("uname -a", "r");
  if (fp == NULL)
    return NULL;
  fgets(buf, sizeof(buf), fp);
  pclose(fp);
  return buf;
}


x86 assembly (clang, -O0):
<get_system_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    0xec3(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1167 <get_system_info+0x37>
movq   $0x0,-0x8(%rbp)
jmp    1190 <get_system_info+0x60>
mov    -0x10(%rbp),%rdx
lea    0x2ede(%rip),%rdi
mov    $0x3e8,%esi
call   1040 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1030 <pclose@plt>
lea    0x2ec4(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_system_info>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rdi
lea    0xec7(%rip),%rsi
call   1050 <popen@plt>
test   %rax,%rax
je     1170 <get_system_info+0x40>
mov    %rax,%rbx
lea    0x2efa(%rip),%r14
mov    %r14,%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1030 <pclose@plt>
jmp    1173 <get_system_info+0x43>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@get_system_info.buf = internal global [1000 x i8] zeroinitializer
@.str = [9 x i8] c"uname -a\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @get_system_info() {
%1 = alloca i8*
%2 = alloca i32*
%3 = call i32* @popen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %7
6: ; preds = %0
store i8* null, i8** %1
br label %12
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = call i32 @fgets(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @get_system_info.buf, i64 0, i64 0), i32 1000, i32* %8)
%10 = load i32*, i32** %2
%11 = call i32 @pclose(i32* %10)
store i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @get_system_info.buf, i64 0, i64 0), i8** %1
br label %12
12: ; preds = %7, %6
%13 = load i8*, i8** %1
ret i8* %13
}

LLVM IR (-O2):
@get_system_info.buf = internal global [1000 x i8] zeroinitializer
@.str = [9 x i8] c"uname -a\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @get_system_info() {
%1 = tail call i32* @popen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i32 @fgets(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @get_system_info.buf, i64 0, i64 0), i32 1000, i32* %1)
%5 = tail call i32 @pclose(i32* %1)
br label %6
6: ; preds = %0, %3
%7 = phi i8* [ getelementptr inbounds ([1000 x i8], [1000 x i8]* @get_system_info.buf, i64 0, i64 0), %3 ], [ null, %0 ]
ret i8* %7
}