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

/* Variables and functions */
int /*<<< orphan*/ BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fread(char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  FILE *read_fp;
  char buffer[BUFSIZ + 1];
  int chars_read;
  memset(buffer, '\0', sizeof(buffer));
  read_fp = popen("uname -a", "r");
  if (read_fp != NULL) {
    chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
    if (chars_read > 0) {
      printf("Output was:-\n%s\n", buffer);
    }
    pclose(read_fp);
    exit(EXIT_SUCCESS);
  }
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe52(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1218 <main+0xb8>
mov    -0x30(%rbp),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    1201 <main+0xa1>
mov    -0x30(%rbp),%rsi
lea    0xe0f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <pclose@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e6f(%rip),%r15
mov    (%r15),%edx
add    $0x1,%edx
mov    %rsp,%rbx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe67(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1070 <popen@plt>
test   %rax,%rax
jne    11b8 <main+0x58>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %rax,%r14
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11e1 <main+0x81>
lea    0xe32(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1050 <pclose@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [9 x i8] c"uname -a\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"Output was:-\0A%s\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @BUFSIZ
%7 = add nsw i32 %6, 1
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
%11 = trunc i64 %8 to i32
%12 = call i32 @memset(i8* %10, i8 signext 0, i32 %11)
%13 = 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* %13, i32** %2
%14 = load i32*, i32** %2
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %29
16: ; preds = %0
%17 = load i32, i32* @BUFSIZ
%18 = load i32*, i32** %2
%19 = call i32 @fread(i8* %10, i32 1, i32 %17, i32* %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %24
24: ; preds = %22, %16
%25 = load i32*, i32** %2
%26 = call i32 @pclose(i32* %25)
%27 = load i32, i32* @EXIT_SUCCESS
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %0
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [9 x i8] c"uname -a\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"Output was:-\0A%s\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = load i32, i32* @BUFSIZ
%2 = add nsw i32 %1, 1
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @memset(i8* %4, i8 signext 0, i32 %2)
%6 = 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))
%7 = icmp eq i32* %6, null
br i1 %7, label %18, label %8
8: ; preds = %0
%9 = load i32, i32* @BUFSIZ
%10 = call i32 @fread(i8* %4, i32 1, i32 %9, i32* %6)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %14
14: ; preds = %12, %8
%15 = call i32 @pclose(i32* %6)
%16 = load i32, i32* @EXIT_SUCCESS
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
}