#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*/ wchar_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *wcsdupstr(int /*<<< orphan*/ const *);
FILE *_wfopen(const wchar_t *wpath, const wchar_t *wmode) {
  FILE *fd;
  char *path = wcsdupstr(wpath);
  char *mode = wcsdupstr(wmode);
  if ((path == NULL) || (mode == NULL))
    return NULL;
  fd = fopen(path, mode);
  free(path);
  free(mode);
  return fd;
}


x86 assembly (clang, -O0):
<_wfopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <wcsdupstr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <wcsdupstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1170 <_wfopen+0x40>
cmpq   $0x0,-0x30(%rbp)
jne    117d <_wfopen+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <_wfopen+0x78>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_wfopen>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
call   1050 <wcsdupstr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <wcsdupstr@plt>
test   %rbx,%rbx
je     1178 <_wfopen+0x48>
mov    %rax,%r14
test   %rax,%rax
je     1178 <_wfopen+0x48>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fopen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
jmp    117a <_wfopen+0x4a>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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