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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
char *read_filew(int /*<<< orphan*/ *);
int /*<<< orphan*/ smb___free(char *);
int /*<<< orphan*/ stderr;
scalar_t__ wcscmp(char *, char *);
int test_read_filew(void) {
  FILE *f = fopen("res/file.txt", "r");
  wchar_t *expected = L"This is the first line of my file.\n"
                      L"This is the second line of my file.\n";
  wchar_t *str = read_filew(f);
  do {
    if (wcscmp((expected), (str)) != 0) {
      fprintf(stderr, "Assertion failed: \"%ls\" != \"%ls\"\n", expected, str);
      return 46;
    }
  } while (0);
  ;
  smb___free(str);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<test_read_filew>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <read_filew@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <wcscmp@plt>
cmp    $0x0,%rax
je     11d7 <test_read_filew+0x77>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe49(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x2e,-0x4(%rbp)
jmp    11f5 <test_read_filew+0x95>
jmp    11dc <test_read_filew+0x7c>
mov    -0x20(%rbp),%rdi
call   1040 <smb___free@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_read_filew>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <read_filew@plt>
mov    %rax,%rbx
lea    0xea8(%rip),%rdi
mov    %rax,%rsi
call   1030 <wcscmp@plt>
test   %rax,%rax
je     11bf <test_read_filew+0x5f>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
lea    0xe84(%rip),%rdx
mov    %rbx,%rcx
call   1060 <fprintf@plt>
mov    $0x2e,%eax
jmp    11d1 <test_read_filew+0x71>
mov    %rbx,%rdi
call   1040 <smb___free@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"res/file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [72 x i32] [i32 84, i32 104, i32 105, i32 115, i32 32, i32 105, i32 115, i32 32, i32 116, i32 104, i32 101, i32 32, i32 102, i32 105, i32 114, i32 115, i32 116, i32 32, i32 108, i32 105, i32 110, i32 101, i32 32, i32 111, i32 102, i32 32, i32 109, i32 121, i32 32, i32 102, i32 105, i32 108, i32 101, i32 46, i32 10, i32 84, i32 104, i32 105, i32 115, i32 32, i32 105, i32 115, i32 32, i32 116, i32 104, i32 101, i32 32, i32 115, i32 101, i32 99, i32 111, i32 110, i32 100, i32 32, i32 108, i32 105, i32 110, i32 101, i32 32, i32 111, i32 102, i32 32, i32 109, i32 121, i32 32, i32 102, i32 105, i32 108, i32 101, i32 46, i32 10, i32 0]
@stderr = global i32 0
@.str.3 = [34 x i8] c"Assertion failed: \22%ls\22 != \22%ls\22\0A\00"
define i32 @test_read_filew() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
store i8* bitcast ([72 x i32]* @.str.2 to i8*), i8** %3
%6 = load i32*, i32** %2
%7 = call i8* @read_filew(i32* %6)
store i8* %7, i8** %4
br label %8
8: ; preds = %0
%9 = load i8*, i8** %3
%10 = load i8*, i8** %4
%11 = call i64 @wcscmp(i8* %9, i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %16)
store i32 46, i32* %1
br label %24
18: ; preds = %8
br label %19
19: ; preds = %18
%20 = load i8*, i8** %4
%21 = call i32 @smb___free(i8* %20)
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
store i32 0, i32* %1
br label %24
24: ; preds = %19, %13
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [13 x i8] c"res/file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [72 x i32] [i32 84, i32 104, i32 105, i32 115, i32 32, i32 105, i32 115, i32 32, i32 116, i32 104, i32 101, i32 32, i32 102, i32 105, i32 114, i32 115, i32 116, i32 32, i32 108, i32 105, i32 110, i32 101, i32 32, i32 111, i32 102, i32 32, i32 109, i32 121, i32 32, i32 102, i32 105, i32 108, i32 101, i32 46, i32 10, i32 84, i32 104, i32 105, i32 115, i32 32, i32 105, i32 115, i32 32, i32 116, i32 104, i32 101, i32 32, i32 115, i32 101, i32 99, i32 111, i32 110, i32 100, i32 32, i32 108, i32 105, i32 110, i32 101, i32 32, i32 111, i32 102, i32 32, i32 109, i32 121, i32 32, i32 102, i32 105, i32 108, i32 101, i32 46, i32 10, i32 0]
@stderr = global i32 0
@.str.3 = [34 x i8] c"Assertion failed: \22%ls\22 != \22%ls\22\0A\00"
define i32 @test_read_filew() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i8* @read_filew(i32* %1)
%3 = tail call i64 @wcscmp(i8* bitcast ([72 x i32]* @.str.2 to i8*), i8* %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* bitcast ([72 x i32]* @.str.2 to i8*), i8* %2)
br label %11
8: ; preds = %0
%9 = tail call i32 @smb___free(i8* %2)
%10 = tail call i32 @fclose(i32* %1)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ 46, %5 ], [ 0, %8 ]
ret i32 %12
}