#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 */
scalar_t__ dlsym(void *, char *);
int /*<<< orphan*/ *do_generic_freopen(
    char const *, char const *, int /*<<< orphan*/ *,
    int /*<<< orphan*/ *(*)(char const *, char const *, int /*<<< orphan*/ *));
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
FILE *flcow_freopen64(char const *name, char const *mode, FILE *file) {
  static FILE *(*func_open)(char const *, char const *, FILE *) = NULL;
  if (!func_open &&
      !(func_open = (FILE * (*)(char const *, char const *, FILE *))
            dlsym(((void *)-1L), "freopen64"))) {
    fprintf(stderr, "missing symbol: %s\n", "freopen64");
    exit(1);
  }
  do {
  } while (0);
  return do_generic_freopen(name, mode, file, func_open);
}


x86 assembly (clang, -O0):
<flcow_freopen64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,0x2eec(%rip)
jne    11ac <flcow_freopen64+0x6c>
mov    $0xffffffffffffffff,%rdi
lea    0xe90(%rip),%rsi
call   1050 <dlsym@plt>
mov    %rax,0x2ecc(%rip)
cmp    $0x0,%rax
jne    11ac <flcow_freopen64+0x6c>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
lea    0xe63(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11b1 <flcow_freopen64+0x71>
jmp    11b6 <flcow_freopen64+0x76>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    0x2e7f(%rip),%rcx
call   1030 <do_generic_freopen@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flcow_freopen64>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2ef3(%rip),%rcx
test   %rcx,%rcx
jne    117c <flcow_freopen64+0x3c>
lea    0xe9f(%rip),%rsi
mov    $0xffffffffffffffff,%rdi
call   1050 <dlsym@plt>
mov    %rax,%rcx
mov    %rax,0x2ed1(%rip)
test   %rax,%rax
je     118f <flcow_freopen64+0x4f>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <do_generic_freopen@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
lea    0xe5a(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@flcow_freopen64.func_open = internal global i32* (i8*, i8*, i32*)* null
@.str = [10 x i8] c"freopen64\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"missing symbol: %s\0A\00"
define i32* @flcow_freopen64(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%7 = load i32* (i8*, i8*, i32*)*, i32* (i8*, i8*, i32*)** @flcow_freopen64.func_open
%8 = icmp ne i32* (i8*, i8*, i32*)* %7, null
br i1 %8, label %17, label %9
9: ; preds = %3
%10 = call i64 @dlsym(i8* inttoptr (i64 -1 to i8*), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = inttoptr i64 %10 to i32* (i8*, i8*, i32*)*
store i32* (i8*, i8*, i32*)* %11, i32* (i8*, i8*, i32*)** @flcow_freopen64.func_open
%12 = icmp ne i32* (i8*, i8*, i32*)* %11, null
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %9, %3
br label %18
18: ; preds = %17
br label %19
19: ; preds = %18
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = load i32*, i32** %6
%23 = load i32* (i8*, i8*, i32*)*, i32* (i8*, i8*, i32*)** @flcow_freopen64.func_open
%24 = call i32* @do_generic_freopen(i8* %20, i8* %21, i32* %22, i32* (i8*, i8*, i32*)* %23)
ret i32* %24
}

LLVM IR (-O2):
@flcow_freopen64.func_open = internal unnamed_addr global i32* (i8*, i8*, i32*)* null
@.str = [10 x i8] c"freopen64\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"missing symbol: %s\0A\00"
define i32* @flcow_freopen64(i8* %0, i8* %1, i32* %2) {
%4 = load i32* (i8*, i8*, i32*)*, i32* (i8*, i8*, i32*)** @flcow_freopen64.func_open
%5 = icmp eq i32* (i8*, i8*, i32*)* %4, null
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = tail call i64 @dlsym(i8* inttoptr (i64 -1 to i8*), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = inttoptr i64 %7 to i32* (i8*, i8*, i32*)*
store i32* (i8*, i8*, i32*)* %8, i32* (i8*, i8*, i32*)** @flcow_freopen64.func_open
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %6, %3
%15 = phi i32* (i8*, i8*, i32*)* [ %8, %6 ], [ %4, %3 ]
%16 = tail call i32* @do_generic_freopen(i8* %0, i8* %1, i32* %2, i32* (i8*, i8*, i32*)* %15)
ret i32* %16
}