#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;
struct stfl_widget {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int mbsrtowcs(int /*<<< orphan*/ *, char const **, scalar_t__,
              int /*<<< orphan*/ *);
size_t mbstowcs(char *, char *, size_t);
char *realloc(char *, int);
int /*<<< orphan*/ stderr;
struct stfl_widget *stfl_parser(char *);
scalar_t__ strlen(char const *);
struct stfl_widget *stfl_parser_file(const char *filename) {
  FILE *f = fopen(filename, "r");
  if (!f) {
    fprintf(stderr, "STFL Parser Error: Can't read file '%s'!\n", filename);
    abort();
    return 0;
  }
  int len = 0;
  char *text = 0;
  while (1) {
    int pos = len;
    text = realloc(text, len += 4096);
    pos += fread(text + pos, 1, 4096, f);
    if (pos < len) {
      text[pos] = 0;
      fclose(f);
      break;
    }
  }
  const char *text1 = text;
  size_t wtextsize = mbsrtowcs(NULL, &text1, strlen(text1) + 1, NULL) + 1;
  wchar_t *wtext = malloc(sizeof(wchar_t) * wtextsize);
  size_t rc = mbstowcs(wtext, text, wtextsize);
  assert(rc != (size_t)-1);
  struct stfl_widget *w = stfl_parser(wtext);
  free(text);
  free(wtext);
  return w;
}


x86 assembly (clang, -O0):
<stfl_parser_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    121b <stfl_parser_file+0x4b>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdf3(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1000,%esi
mov    %esi,-0x14(%rbp)
call   10e0 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1050 <fread@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    129a <stfl_parser_file+0xca>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1070 <fclose@plt>
jmp    129f <stfl_parser_file+0xcf>
jmp    122a <stfl_parser_file+0x5a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1080 <strlen@plt>
mov    %rax,%rdx
add    $0x1,%rdx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x30(%rbp),%rsi
mov    %rcx,%rdi
call   10c0 <mbsrtowcs@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1060 <mbstowcs@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0xffffffffffffffff,-0x48(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x40(%rbp),%rdi
call   1090 <stfl_parser@plt>
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stfl_parser_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe1e(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     12b8 <stfl_parser_file+0xe8>
mov    %rax,%r14
xor    %ebx,%ebx
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
lea    0x1000(%rbx),%r12
mov    %r15,%rdi
mov    %r12d,%esi
call   10e0 <realloc@plt>
mov    %rax,%r15
lea    (%rax,%rbx,1),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
add    %eax,%ebx
movslq %ebx,%rax
mov    %r12,%rbx
cmp    %r12,%rax
jge    1200 <stfl_parser_file+0x30>
movb   $0x0,(%r15,%rax,1)
mov    %r14,%rdi
call   1070 <fclose@plt>
mov    %r15,(%rsp)
mov    %r15,%rdi
call   1080 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rsp,%rsi
xor    %edi,%edi
xor    %ecx,%ecx
call   10c0 <mbsrtowcs@plt>
add    $0x1,%eax
movslq %eax,%rbx
mov    %ebx,%edi
call   10d0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <mbstowcs@plt>
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rax
setne  %dil
call   10a0 <assert@plt>
mov    %r14,%rdi
call   1090 <stfl_parser@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    0xd3a(%rip),%rsi
mov    %rbx,%rdx
call   10b0 <fprintf@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
%struct.stfl_widget = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"STFL Parser Error: Can't read file '%s'!\0A\00"
define %struct.stfl_widget* @stfl_parser_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca %struct.stfl_widget*
store i8* %0, i8** %2
%12 = load i8*, i8** %2
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = icmp ne i32* %14, null
br i1 %15, label %21, label %16
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %2
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %1
store i32 0, i32* %4
store i8* null, i8** %5
br label %22
22: ; preds = %21, %48
%23 = load i32, i32* %4
store i32 %23, i32* %6
%24 = load i8*, i8** %5
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 4096
store i32 %26, i32* %4
%27 = call i8* @realloc(i8* %24, i32 %26)
store i8* %27, i8** %5
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i32*, i32** %3
%33 = call i64 @fread(i8* %31, i32 1, i32 4096, i32* %32)
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = add nsw i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = load i32, i32* %4
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %48
41: ; preds = %22
%42 = load i8*, i8** %5
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = load i32*, i32** %3
%47 = call i32 @fclose(i32* %46)
br label %49
48: ; preds = %22
br label %22
49: ; preds = %41
%50 = load i8*, i8** %5
store i8* %50, i8** %7
%51 = load i8*, i8** %7
%52 = call i64 @strlen(i8* %51)
%53 = add nsw i64 %52, 1
%54 = call i32 @mbsrtowcs(i32* null, i8** %7, i64 %53, i32* null)
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
store i64 %56, i64* %8
%57 = load i64, i64* %8
%58 = mul i64 1, %57
%59 = trunc i64 %58 to i32
%60 = call i8* @malloc(i32 %59)
store i8* %60, i8** %9
%61 = load i8*, i8** %9
%62 = load i8*, i8** %5
%63 = load i64, i64* %8
%64 = call i64 @mbstowcs(i8* %61, i8* %62, i64 %63)
store i64 %64, i64* %10
%65 = load i64, i64* %10
%66 = icmp ne i64 %65, -1
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = load i8*, i8** %9
%70 = call %struct.stfl_widget* @stfl_parser(i8* %69)
store %struct.stfl_widget* %70, %struct.stfl_widget** %11
%71 = load i8*, i8** %5
%72 = call i32 @free(i8* %71)
%73 = load i8*, i8** %9
%74 = call i32 @free(i8* %73)
%75 = load %struct.stfl_widget*, %struct.stfl_widget** %11
ret %struct.stfl_widget* %75
}

LLVM IR (-O2):
%struct.stfl_widget = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"STFL Parser Error: Can't read file '%s'!\0A\00"
define %struct.stfl_widget* @stfl_parser_file(i8* %0) {
%2 = alloca i8*
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %1, %9
%10 = phi i64 [ %12, %9 ], [ 0, %1 ]
%11 = phi i8* [ %14, %9 ], [ null, %1 ]
%12 = add nuw nsw i64 %10, 4096
%13 = trunc i64 %12 to i32
%14 = tail call i8* @realloc(i8* %11, i32 %13)
%15 = getelementptr inbounds i8, i8* %14, i64 %10
%16 = tail call i64 @fread(i8* %15, i32 1, i32 4096, i32* %3)
%17 = add i64 %10, %16
%18 = shl i64 %17, 32
%19 = ashr exact i64 %18, 32
%20 = icmp slt i64 %19, %12
br i1 %20, label %21, label %9
21: ; preds = %9
%22 = getelementptr inbounds i8, i8* %14, i64 %19
store i8 0, i8* %22
%23 = tail call i32 @fclose(i32* %3)
%24 = bitcast i8** %2 to i8*
store i8* %14, i8** %2
%25 = tail call i64 @strlen(i8* dereferenceable(1) %14)
%26 = add nsw i64 %25, 1
%27 = call i32 @mbsrtowcs(i32* null, i8** %2, i64 %26, i32* null)
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = call i8* @malloc(i32 %28)
%31 = call i64 @mbstowcs(i8* %30, i8* %14, i64 %29)
%32 = icmp ne i64 %31, -1
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = call %struct.stfl_widget* @stfl_parser(i8* %30)
%36 = call i32 @free(i8* %14)
%37 = call i32 @free(i8* %30)
ret %struct.stfl_widget* %35
}