#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 */

/* Variables and functions */
#define EINVAL 129
#define ENOMEM 128
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int);
void err_freopen(int err) {
  fprintf(stderr, "error: freopen() function caused an error\n");
  switch (err) {
  case EINVAL:
    fprintf(
        stderr,
        "       The mode provided to fopen, fdopen, or freopen was invalid.\n");
    break;
  case ENOMEM:
    fprintf(stderr, "       Not enough memory.\n");
    break;
  default:
    fprintf(stderr, "       freopen() unknown errno type encountered\n");
  }
  fprintf(stderr, "       errno is: %d\n", err);
  ;
  fprintf(stderr, "       %s\n", strerror(err));
  ;
  fflush(stderr);
}


x86 assembly (clang, -O0):
<err_freopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
lea    0xeb5(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x80,%eax
je     1197 <err_freopen+0x67>
jmp    1168 <err_freopen+0x38>
mov    -0x8(%rbp),%eax
sub    $0x81,%eax
jne    11b3 <err_freopen+0x83>
jmp    117b <err_freopen+0x4b>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11ca <err_freopen+0x9a>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xec8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11ca <err_freopen+0x9a>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xec7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xede(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rdx
lea    0xecb(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_freopen>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    0x2ea3(%rip),%r14
mov    (%r14),%edi
lea    0xeb9(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
cmp    $0x80,%ebx
lea    0xf14(%rip),%rax
lea    0xf28(%rip),%rcx
cmove  %rax,%rcx
cmp    $0x81,%ebx
lea    0xeb8(%rip),%rsi
cmovne %rcx,%rsi
mov    (%r14),%edi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
lea    0xf30(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%ebp
mov    %ebx,%edi
call   1050 <strerror@plt>
lea    0xf2b(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fflush@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"error: freopen() function caused an error\0A\00"
@.str.1 = [68 x i8] c" The mode provided to fopen, fdopen, or freopen was invalid.\0A\00"
@.str.2 = [27 x i8] c" Not enough memory.\0A\00"
@.str.3 = [49 x i8] c" freopen() unknown errno type encountered\0A\00"
@.str.4 = [21 x i8] c" errno is: %d\0A\00"
@.str.5 = [11 x i8] c" %s\0A\00"
define void @err_freopen(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @stderr
%4 = call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* %2
switch i32 %5, label %12 [
i32 129, label %6
i32 128, label %9
]
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
br label %15
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %15
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %12, %9, %6
%16 = load i32, i32* @stderr
%17 = load i32, i32* %2
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @stderr
%20 = load i32, i32* %2
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @stderr
%24 = call i32 @fflush(i32 %23)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"error: freopen() function caused an error\0A\00"
@.str.1 = [68 x i8] c" The mode provided to fopen, fdopen, or freopen was invalid.\0A\00"
@.str.2 = [27 x i8] c" Not enough memory.\0A\00"
@.str.3 = [49 x i8] c" freopen() unknown errno type encountered\0A\00"
@.str.4 = [21 x i8] c" errno is: %d\0A\00"
@.str.5 = [11 x i8] c" %s\0A\00"
define void @err_freopen(i32 %0) {
%2 = load i32, i32* @stderr
%3 = tail call i32 (i32, i8*, ...) @fprintf(i32 %2, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %0, 128
%5 = select i1 %4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0)
%6 = icmp eq i32 %0, 129
%7 = select i1 %6, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), i8* %5
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* %7)
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%12 = load i32, i32* @stderr
%13 = tail call i8* @strerror(i32 %0)
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @stderr
%16 = tail call i32 @fflush(i32 %15)
ret void
}