#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ get_line(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
char *get_system(char *sys_str) {
  char buffer[1024];
  FILE *p;
  p = popen(sys_str, "r");
  if (!p) {
    fprintf(stderr, "ERROR: get_system(%s) cannot open pipe\n", sys_str);
    exit(1);
  }
  *buffer = '\0';
  get_line(buffer, p);
  pclose(p);
  return strdup(buffer);
}


x86 assembly (clang, -O0):
<get_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    11b7 <get_system+0x57>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movb   $0x0,-0x410(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rsi
call   1030 <get_line@plt>
mov    -0x418(%rbp),%rdi
call   1040 <pclose@plt>
lea    -0x410(%rbp),%rdi
call   1080 <strdup@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_system>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
lea    0xe8c(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     11ae <get_system+0x4e>
mov    %rax,%rbx
movb   $0x0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <get_line@plt>
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %r14,%rdi
call   1080 <strdup@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"ERROR: get_system(%s) cannot open pipe\0A\00"
define i8* @get_system(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %2
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
store i8 0, i8* %15
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = load i32*, i32** %4
%18 = call i32 @get_line(i8* %16, i32* %17)
%19 = load i32*, i32** %4
%20 = call i32 @pclose(i32* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%22 = call i8* @strdup(i8* %21)
ret i8* %22
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"ERROR: get_system(%s) cannot open pipe\0A\00"
define noalias i8* @get_system(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 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 %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
store i8 0, i8* %3
%11 = call i32 @get_line(i8* %3, i32* %4)
%12 = call i32 @pclose(i32* %4)
%13 = call i8* @strdup(i8* %3)
ret i8* %13
}