#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*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void num_vms_allocated(char *buf) {
  FILE *f;
  int n;
  f = popen("sudo xl vm-list | wc -l", "r");
  fscanf(f, "%d", &n);
  pclose(f);
  sprintf(buf, "%d", n - 1);
}


x86 assembly (clang, -O0):
<num_vms_allocated>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
lea    0xebe(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeac(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <pclose@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
lea    0xe89(%rip),%rsi
call   1060 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_vms_allocated>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xead(%rip),%rdi
lea    0xebe(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,%rbx
lea    0xeb1(%rip),%r15
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <pclose@plt>
mov    0xc(%rsp),%edx
add    $0xffffffff,%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <sprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"sudo xl vm-list | wc -l\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define void @num_vms_allocated(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32* @popen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%8 = load i32*, i32** %3
%9 = call i32 @pclose(i32* %8)
%10 = load i8*, i8** %2
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
%13 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %12)
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"sudo xl vm-list | wc -l\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define void @num_vms_allocated(i8* nocapture writeonly %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32* @popen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%6 = call i32 @pclose(i32* %4)
%7 = load i32, i32* %2
%8 = add nsw i32 %7, -1
%9 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %8)
ret void
}