#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*/ assert_fp(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fcloseall();
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ stdin;
void test_fp(void) {
  FILE *fp1, *fp2;
  fp1 = fopen("file_out", "r");
  assert_fp("fopen", fp1);
  fp2 = freopen("file_out", "r+", stdin);
  assert_fp("freopen", fp2);
  fclose(fp1);
  fp1 = popen("/bin/echo", "r");
  assert_fp("popen", fp1);
  pclose(fp1);
  fcloseall();
}


x86 assembly (clang, -O0):
<test_fp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe81(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1030 <assert_fp@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
lea    0xe51(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1060 <freopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe4a(%rip),%rdi
call   1030 <assert_fp@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe3d(%rip),%rdi
lea    0xe23(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1030 <assert_fp@plt>
mov    -0x8(%rbp),%rdi
call   1050 <pclose@plt>
mov    $0x0,%al
call   1090 <fcloseall@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_fp>:
push   %r15
push   %r14
push   %rbx
lea    0xe84(%rip),%r15
lea    0xe86(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe73(%rip),%rdi
mov    %rax,%rsi
call   1030 <assert_fp@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
lea    0xe61(%rip),%rsi
mov    %r15,%rdi
call   1060 <freopen@plt>
lea    0xe55(%rip),%rdi
mov    %rax,%rsi
call   1030 <assert_fp@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe46(%rip),%rdi
mov    %r14,%rsi
call   1070 <popen@plt>
mov    %rax,%rbx
lea    0xe3e(%rip),%rdi
mov    %rax,%rsi
call   1030 <assert_fp@plt>
mov    %rbx,%rdi
call   1050 <pclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <fcloseall@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"file_out\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [3 x i8] c"r+\00"
@stdin = global i32 0
@.str.4 = [8 x i8] c"freopen\00"
@.str.5 = [10 x i8] c"/bin/echo\00"
@.str.6 = [6 x i8] c"popen\00"
define void @test_fp() {
%1 = alloca i32*
%2 = alloca i32*
%3 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = call i32 @assert_fp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%6 = load i32, i32* @stdin
%7 = call i32* @freopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %6)
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = call i32 @assert_fp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32* %8)
%10 = load i32*, i32** %1
%11 = call i32 @fclose(i32* %10)
%12 = call i32* @popen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %1
%13 = load i32*, i32** %1
%14 = call i32 @assert_fp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32* %13)
%15 = load i32*, i32** %1
%16 = call i32 @pclose(i32* %15)
%17 = call i32 (...) @fcloseall()
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"file_out\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [3 x i8] c"r+\00"
@stdin = global i32 0
@.str.4 = [8 x i8] c"freopen\00"
@.str.5 = [10 x i8] c"/bin/echo\00"
@.str.6 = [6 x i8] c"popen\00"
define void @test_fp() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @assert_fp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%3 = load i32, i32* @stdin
%4 = tail call i32* @freopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %3)
%5 = tail call i32 @assert_fp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%6 = tail call i32 @fclose(i32* %1)
%7 = tail call i32* @popen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @assert_fp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32* %7)
%9 = tail call i32 @pclose(i32* %7)
%10 = tail call i32 (...) @fcloseall()
ret void
}