#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char const *);
FILE *wceex_freopen(const char *filename, const char *opentype, FILE *stream) {
  if (stream == NULL || filename == NULL || opentype == NULL)
    return NULL;
  fflush(stream);
  fclose(stream);
  return fopen(filename, opentype);
}


x86 assembly (clang, -O0):
<wceex_freopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1165 <wceex_freopen+0x35>
cmpq   $0x0,-0x10(%rbp)
je     1165 <wceex_freopen+0x35>
cmpq   $0x0,-0x18(%rbp)
jne    1172 <wceex_freopen+0x42>
movq   $0x0,-0x8(%rbp)
jmp    1195 <wceex_freopen+0x65>
mov    -0x20(%rbp),%rdi
call   1040 <fflush@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wceex_freopen>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     116d <wceex_freopen+0x3d>
mov    %rdi,%r14
test   %rdi,%rdi
je     116d <wceex_freopen+0x3d>
mov    %rdx,%rbx
test   %rdx,%rdx
je     116d <wceex_freopen+0x3d>
mov    %rsi,%r15
mov    %rbx,%rdi
call   1040 <fflush@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <fopen@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @wceex_freopen(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%8 = load i32*, i32** %7
%9 = icmp eq i32* %8, null
br i1 %9, label %16, label %10
10: ; preds = %3
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13, %10, %3
store i32* null, i32** %4
br label %25
17: ; preds = %13
%18 = load i32*, i32** %7
%19 = call i32 @fflush(i32* %18)
%20 = load i32*, i32** %7
%21 = call i32 @fclose(i32* %20)
%22 = load i8*, i8** %5
%23 = load i8*, i8** %6
%24 = call i32* @fopen(i8* %22, i8* %23)
store i32* %24, i32** %4
br label %25
25: ; preds = %17, %16
%26 = load i32*, i32** %4
ret i32* %26
}

LLVM IR (-O2):
define noalias i32* @wceex_freopen(i8* %0, i8* %1, i32* %2) {
%4 = icmp eq i32* %2, null
%5 = icmp eq i8* %0, null
%6 = or i1 %5, %4
%7 = icmp eq i8* %1, null
%8 = or i1 %7, %6
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = tail call i32 @fflush(i32* %2)
%11 = tail call i32 @fclose(i32* %2)
%12 = tail call i32* @fopen(i8* %0, i8* %1)
br label %13
13: ; preds = %3, %9
%14 = phi i32* [ %12, %9 ], [ null, %3 ]
ret i32* %14
}