#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 BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, int, char *);
int main() {
  FILE *read_fp;
  char buffer[BUFSIZ + 1];
  int chars_read;
  memset(buffer, '\0', sizeof(buffer));
  read_fp = popen("ps ax", "r");
  if (read_fp != NULL) {
    chars_read = fread(buffer, sizeof(char), BUFSIZ / 10, read_fp);
    while (chars_read > 0) {
      buffer[chars_read - 1] = '\0';
      printf("Reading %d:-\n %s\n", BUFSIZ / 10, buffer);
      chars_read = fread(buffer, sizeof(char), BUFSIZ / 10, read_fp);
    }
    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    0xe51(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1273 <main+0x113>
mov    -0x30(%rbp),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    125c <main+0xfc>
mov    -0x30(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x30(%rbp),%rdx
mov    %eax,%esi
lea    0xdde(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
jmp    11f1 <main+0x91>
mov    -0x10(%rbp),%rdi
call   1050 <pclose@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e6e(%rip),%r12
mov    (%r12),%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    0xe65(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1070 <popen@plt>
test   %rax,%rax
jne    11ba <main+0x5a>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %rax,%r14
movslq (%r12),%rax
imul   $0x66666667,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x22,%rdx
add    %eax,%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    1246 <main+0xe6>
lea    0xe18(%rip),%r15
add    $0xffffffff,%eax
movb   $0x0,(%rbx,%rax,1)
movslq (%r12),%rax
imul   $0x66666667,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x22,%rsi
add    %eax,%esi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1040 <printf@plt>
movslq (%r12),%rax
imul   $0x66666667,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x22,%rdx
add    %eax,%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jg     11f0 <main+0x90>
mov    %r14,%rdi
call   1050 <pclose@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [6 x i8] c"ps ax\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"Reading %d:-\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 ([6 x i8], [6 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 %41
16: ; preds = %0
%17 = load i32, i32* @BUFSIZ
%18 = sdiv i32 %17, 10
%19 = load i32*, i32** %2
%20 = call i32 @fread(i8* %10, i32 1, i32 %18, i32* %19)
store i32 %20, i32* %5
br label %21
21: ; preds = %24, %16
%22 = load i32, i32* %5
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %21
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %10, i64 %27
store i8 0, i8* %28
%29 = load i32, i32* @BUFSIZ
%30 = sdiv i32 %29, 10
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %30, i8* %10)
%32 = load i32, i32* @BUFSIZ
%33 = sdiv i32 %32, 10
%34 = load i32*, i32** %2
%35 = call i32 @fread(i8* %10, i32 1, i32 %33, i32* %34)
store i32 %35, i32* %5
br label %21
36: ; preds = %21
%37 = load i32*, i32** %2
%38 = call i32 @pclose(i32* %37)
%39 = load i32, i32* @EXIT_SUCCESS
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %0
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [6 x i8] c"ps ax\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"Reading %d:-\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 ([6 x i8], [6 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 %29, label %8
8: ; preds = %0
%9 = load i32, i32* @BUFSIZ
%10 = sdiv i32 %9, 10
%11 = call i32 @fread(i8* %4, i32 1, i32 %10, i32* %6)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %8, %13
%14 = phi i32 [ %23, %13 ], [ %11, %8 ]
%15 = add nsw i32 %14, -1
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %4, i64 %16
store i8 0, i8* %17
%18 = load i32, i32* @BUFSIZ
%19 = sdiv i32 %18, 10
%20 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %19, i8* %4)
%21 = load i32, i32* @BUFSIZ
%22 = sdiv i32 %21, 10
%23 = call i32 @fread(i8* %4, i32 1, i32 %22, i32* %6)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %13, label %25
25: ; preds = %13, %8
%26 = call i32 @pclose(i32* %6)
%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
}