#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*/ chomp(char *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void getvmstat(char *buffer) {
  FILE *stat = NULL;
  strcpy(buffer, "");
  stat = popen("/usr/bin/vmstat", "r");
  if (stat) {
    int vmstat_counter = 0;
    while (!feof(stat)) {
      if (!fgets(buffer, 4096, stat)) {
        strcpy(buffer, "");
        break;
      }
      vmstat_counter++;
      if (vmstat_counter == 3)
        break;
    }
    pclose(stat);
  }
  chomp(buffer);
}


x86 assembly (clang, -O0):
<getvmstat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe75(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1221 <getvmstat+0xc1>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cb <getvmstat+0x6b>
jmp    1218 <getvmstat+0xb8>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    11fb <getvmstat+0x9b>
mov    -0x8(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1218 <getvmstat+0xb8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jne    1213 <getvmstat+0xb3>
jmp    1218 <getvmstat+0xb8>
jmp    11ad <getvmstat+0x4d>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0x8(%rbp),%rdi
call   1070 <chomp@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getvmstat>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xea3(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe86(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1080 <popen@plt>
test   %rax,%rax
je     1205 <getvmstat+0xa5>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11fd <getvmstat+0x9d>
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
je     11ee <getvmstat+0x8e>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11fd <getvmstat+0x9d>
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
je     11ee <getvmstat+0x8e>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11fd <getvmstat+0x9d>
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
jne    11fd <getvmstat+0x9d>
lea    0xe1c(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <chomp@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [16 x i8] c"/usr/bin/vmstat\00"
@.str.2 = [2 x i8] c"r\00"
define void @getvmstat(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
store i32* null, i32** %3
%5 = load i8*, i8** %2
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = call i32* @popen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %34
10: ; preds = %1
store i32 0, i32* %4
br label %11
11: ; preds = %30, %10
%12 = load i32*, i32** %3
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %31
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = load i32*, i32** %3
%19 = call i32 @fgets(i8* %17, i32 4096, i32* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i8*, i8** %2
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %31
24: ; preds = %16
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 3
br i1 %28, label %29, label %30
29: ; preds = %24
br label %31
30: ; preds = %24
br label %11
31: ; preds = %29, %21, %11
%32 = load i32*, i32** %3
%33 = call i32 @pclose(i32* %32)
br label %34
34: ; preds = %31, %1
%35 = load i8*, i8** %2
%36 = call i32 @chomp(i8* %35)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [16 x i8] c"/usr/bin/vmstat\00"
@.str.2 = [2 x i8] c"r\00"
define void @getvmstat(i8* %0) {
%2 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32* @popen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %27, label %5
5: ; preds = %1
%6 = tail call i32 @feof(i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %5
%9 = tail call i32 @fgets(i8* %0, i32 4096, i32* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %22, %16, %8
%12 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %25
13: ; preds = %8
%14 = tail call i32 @feof(i32* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = tail call i32 @fgets(i8* %0, i32 4096, i32* %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %11, label %19
19: ; preds = %16
%20 = tail call i32 @feof(i32* %3)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = tail call i32 @fgets(i8* %0, i32 4096, i32* %3)
%24 = icmp eq i32 %23, 0
br i1 %24, label %11, label %25
25: ; preds = %5, %13, %19, %22, %11
%26 = tail call i32 @pclose(i32* %3)
br label %27
27: ; preds = %25, %1
%28 = tail call i32 @chomp(i8* %0)
ret void
}