#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 atoi(char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int getCountFiles(char *com) {
  FILE *fp1;
  fp1 = popen(com, "r");
  if (fp1 == 0)
    perror(com);
  char *line = (char *)malloc(25 * sizeof(char));
  int n = 0;
  if (fgets(line, 25, fp1))
    n = atoi(line);
  free(line);
  pclose(fp1);
  return n;
}


x86 assembly (clang, -O0):
<getCountFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a4 <getCountFiles+0x34>
mov    -0x8(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x19,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x19,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11e1 <getCountFiles+0x71>
mov    -0x18(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCountFiles>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xe82(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,%r14
test   %rax,%rax
je     11d2 <getCountFiles+0x62>
mov    $0x19,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x19,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11b9 <getCountFiles+0x49>
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
jmp    11bb <getCountFiles+0x4b>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <pclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
call   1080 <perror@plt>
jmp    118b <getCountFiles+0x1b>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @getCountFiles(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @perror(i8* %11)
br label %13
13: ; preds = %10, %1
%14 = call i64 @malloc(i32 25)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %4
store i32 0, i32* %5
%16 = load i8*, i8** %4
%17 = load i32*, i32** %3
%18 = call i64 @fgets(i8* %16, i32 25, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %5
br label %23
23: ; preds = %20, %13
%24 = load i8*, i8** %4
%25 = call i32 @free(i8* %24)
%26 = load i32*, i32** %3
%27 = call i32 @pclose(i32* %26)
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @getCountFiles(i8* nocapture %0) {
%2 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @perror(i8* %0)
br label %6
6: ; preds = %4, %1
%7 = tail call i64 @malloc(i32 25)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i64 @fgets(i8* %8, i32 25, i32* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call i32 @atoi(i8* %8)
br label %13
13: ; preds = %11, %6
%14 = phi i32 [ %12, %11 ], [ 0, %6 ]
%15 = tail call i32 @free(i8* %8)
%16 = tail call i32 @pclose(i32* %2)
ret i32 %14
}