#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*/ exit(int);
int forwardline(char *);
scalar_t__ fullline(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int read_profiles(char *cfgfile) {
  FILE *fp;
  char buffer[1024 * 5];
  char cmd[128];
  int rc = 0;
  sprintf(cmd, "cpp %s", cfgfile);
  if ((fp = popen(cmd, "r")) == NULL) {
    perror(cmd);
    exit(1);
  }
  while (fullline(fp, buffer, sizeof buffer))
    rc |= forwardline(buffer);
  pclose(fp);
  return rc;
}


x86 assembly (clang, -O0):
<read_profiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x14a0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1494(%rbp)
lea    -0x1490(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe65(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x1490(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11d7 <read_profiles+0x67>
lea    -0x1490(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11dc <read_profiles+0x6c>
mov    -0x10(%rbp),%rdi
lea    -0x1410(%rbp),%rsi
mov    $0x1400,%edx
call   1050 <fullline@plt>
cmp    $0x0,%rax
je     1218 <read_profiles+0xa8>
lea    -0x1410(%rbp),%rdi
call   1030 <forwardline@plt>
or     -0x1494(%rbp),%eax
mov    %eax,-0x1494(%rbp)
jmp    11dc <read_profiles+0x6c>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0x1494(%rbp),%eax
add    $0x14a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_profiles>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1480,%rsp
mov    %rdi,%rdx
lea    0xe7b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1060 <popen@plt>
test   %rax,%rax
je     1205 <read_profiles+0x95>
mov    %rax,%r14
lea    0x80(%rsp),%rsi
mov    %rax,%rdi
mov    $0x1400,%edx
call   1050 <fullline@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11ef <read_profiles+0x7f>
lea    0x80(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <forwardline@plt>
or     %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1400,%edx
call   1050 <fullline@plt>
test   %rax,%rax
jne    11d0 <read_profiles+0x60>
mov    %r14,%rdi
call   1040 <pclose@plt>
mov    %ebp,%eax
add    $0x1480,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rsp,%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"cpp %s\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @read_profiles(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [5120 x i8]
%5 = alloca [128 x i8]
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %6
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = load i8*, i8** %2
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%11 = call i32* @popen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%15 = call i32 @perror(i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
br label %18
18: ; preds = %23, %17
%19 = load i32*, i32** %3
%20 = getelementptr inbounds [5120 x i8], [5120 x i8]* %4, i64 0, i64 0
%21 = call i64 @fullline(i32* %19, i8* %20, i32 5120)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = getelementptr inbounds [5120 x i8], [5120 x i8]* %4, i64 0, i64 0
%25 = call i32 @forwardline(i8* %24)
%26 = load i32, i32* %6
%27 = or i32 %26, %25
store i32 %27, i32* %6
br label %18
28: ; preds = %18
%29 = load i32*, i32** %3
%30 = call i32 @pclose(i32* %29)
%31 = load i32, i32* %6
ret i32 %31
}

LLVM IR (-O2):
@.str = [7 x i8] c"cpp %s\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @read_profiles(i8* %0) {
%2 = alloca [5120 x i8]
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [5120 x i8], [5120 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = call i64 @fullline(i32* %7, i8* %4, i32 5120)
%11 = icmp eq i64 %10, 0
br i1 %11, label %21, label %15
12: ; preds = %1
%13 = call i32 @perror(i8* %5)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %15
%16 = phi i32 [ %18, %15 ], [ 0, %9 ]
%17 = call i32 @forwardline(i8* %4)
%18 = or i32 %17, %16
%19 = call i64 @fullline(i32* %7, i8* %4, i32 5120)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %15, %9
%22 = phi i32 [ 0, %9 ], [ %18, %15 ]
%23 = call i32 @pclose(i32* %7)
ret i32 %22
}