#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void reopen_logfiles(void) {
  if (!freopen("/var/log/mtp3d.log", "a", stdout)) {
    fprintf(stderr, "Cannot open /var/log/mtp3d.log for writing\n");
    exit(1);
  }
  if (!freopen("/var/log/mtp3d.log", "a", stderr))
    fprintf(stderr, "Cannot open /var/log/mtp3d.log for writing\n");
}


x86 assembly (clang, -O0):
<reopen_logfiles>:
push   %rbp
mov    %rsp,%rbp
mov    0x2e9d(%rip),%rax
mov    (%rax),%edx
lea    0xebc(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1030 <freopen@plt>
cmp    $0x0,%eax
jne    1178 <reopen_logfiles+0x48>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
lea    0xe78(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1030 <freopen@plt>
cmp    $0x0,%eax
jne    11b2 <reopen_logfiles+0x82>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1040 <fprintf@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<reopen_logfiles>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%edx
lea    0xebf(%rip),%rdi
lea    0xecb(%rip),%rsi
call   1030 <freopen@plt>
mov    0x2e8c(%rip),%rbx
mov    (%rbx),%edx
test   %eax,%eax
je     1182 <reopen_logfiles+0x52>
lea    0xe9f(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1030 <freopen@plt>
test   %eax,%eax
je     1173 <reopen_logfiles+0x43>
pop    %rbx
ret
mov    (%rbx),%edi
lea    0xe99(%rip),%rsi
pop    %rbx
jmp    1040 <fprintf@plt>
lea    0xe8c(%rip),%rsi
mov    %edx,%edi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"/var/log/mtp3d.log\00"
@.str.1 = [2 x i8] c"a\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [44 x i8] c"Cannot open /var/log/mtp3d.log for writing\0A\00"
define void @reopen_logfiles() {
%1 = load i32, i32* @stdout
%2 = call i32 @freopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%3 = icmp ne i32 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @freopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %12, %8
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"/var/log/mtp3d.log\00"
@.str.1 = [2 x i8] c"a\00"
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [44 x i8] c"Cannot open /var/log/mtp3d.log for writing\0A\00"
define void @reopen_logfiles() {
%1 = load i32, i32* @stdout
%2 = tail call i32 @freopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, 0
%4 = load i32, i32* @stderr
br i1 %3, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i32 @freopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %11, %8
ret void
}