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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, unsigned int,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
unsigned int stb_decompress(unsigned char *, unsigned char *, unsigned int);
int stb_decompress_length(unsigned char *);
char *stb_decompress_fromfile(char *filename, unsigned int *len) {
  unsigned int n;
  char *q;
  unsigned char *p;
  FILE *f = fopen(filename, "rb");
  if (f == NULL)
    return NULL;
  fseek(f, 0, SEEK_END);
  n = ftell(f);
  fseek(f, 0, SEEK_SET);
  p = (unsigned char *)malloc(n);
  if (p == NULL)
    return NULL;
  fread(p, 1, n, f);
  fclose(f);
  if (p == NULL)
    return NULL;
  if (p[0] != 0x57 || p[1] != 0xBc || p[2] || p[3]) {
    free(p);
    return NULL;
  }
  q = (char *)malloc(stb_decompress_length(p) + 1);
  if (!q) {
    free(p);
    return NULL;
  }
  *len = stb_decompress((unsigned char *)q, p, n);
  if (*len)
    q[*len] = 0;
  free(p);
  return q;
}


x86 assembly (clang, -O0):
<stb_decompress_fromfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11cc <stb_decompress_fromfile+0x3c>
movq   $0x0,-0x8(%rbp)
jmp    1331 <stb_decompress_fromfile+0x1a1>
mov    -0x38(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x38(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x1c(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1224 <stb_decompress_fromfile+0x94>
movq   $0x0,-0x8(%rbp)
jmp    1331 <stb_decompress_fromfile+0x1a1>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
cmpq   $0x0,-0x30(%rbp)
jne    125a <stb_decompress_fromfile+0xca>
movq   $0x0,-0x8(%rbp)
jmp    1331 <stb_decompress_fromfile+0x1a1>
mov    -0x30(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x57,%eax
jne    129f <stb_decompress_fromfile+0x10f>
mov    -0x30(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0xbc,%eax
jne    129f <stb_decompress_fromfile+0x10f>
mov    -0x30(%rbp),%rax
movzbl 0x2(%rax),%eax
cmp    $0x0,%eax
jne    129f <stb_decompress_fromfile+0x10f>
mov    -0x30(%rbp),%rax
movzbl 0x3(%rax),%eax
cmp    $0x0,%eax
je     12b5 <stb_decompress_fromfile+0x125>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1331 <stb_decompress_fromfile+0x1a1>
mov    -0x30(%rbp),%rdi
call   1050 <stb_decompress_length@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12ed <stb_decompress_fromfile+0x15d>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1331 <stb_decompress_fromfile+0x1a1>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10b0 <stb_decompress@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
je     1320 <stb_decompress_fromfile+0x190>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stb_decompress_fromfile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
lea    0xe5e(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1236 <stb_decompress_fromfile+0xa6>
mov    %rax,%rbp
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbp,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbp,%rdi
call   1070 <ftell@plt>
mov    %eax,%r12d
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r12d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1239 <stb_decompress_fromfile+0xa9>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
cmpb   $0x57,(%rbx)
jne    1229 <stb_decompress_fromfile+0x99>
cmpb   $0xbc,0x1(%rbx)
jne    1229 <stb_decompress_fromfile+0x99>
cmpb   $0x0,0x2(%rbx)
jne    1229 <stb_decompress_fromfile+0x99>
cmpb   $0x0,0x3(%rbx)
je     1245 <stb_decompress_fromfile+0xb5>
xor    %r15d,%r15d
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1239 <stb_decompress_fromfile+0xa9>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1050 <stb_decompress_length@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1229 <stb_decompress_fromfile+0x99>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   10b0 <stb_decompress@plt>
mov    %eax,(%r14)
test   %eax,%eax
je     122c <stb_decompress_fromfile+0x9c>
mov    %eax,%eax
movb   $0x0,(%r15,%rax,1)
jmp    122c <stb_decompress_fromfile+0x9c>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @stb_decompress_fromfile(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i8* null, i8** %3
br label %97
15: ; preds = %2
%16 = load i32*, i32** %9
%17 = load i32, i32* @SEEK_END
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = load i32*, i32** %9
%20 = call i32 @ftell(i32* %19)
store i32 %20, i32* %6
%21 = load i32*, i32** %9
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @fseek(i32* %21, i32 0, i32 %22)
%24 = load i32, i32* %6
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %15
store i8* null, i8** %3
br label %97
30: ; preds = %15
%31 = load i8*, i8** %8
%32 = load i32, i32* %6
%33 = load i32*, i32** %9
%34 = call i32 @fread(i8* %31, i32 1, i32 %32, i32* %33)
%35 = load i32*, i32** %9
%36 = call i32 @fclose(i32* %35)
%37 = load i8*, i8** %8
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %40
39: ; preds = %30
store i8* null, i8** %3
br label %97
40: ; preds = %30
%41 = load i8*, i8** %8
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = icmp ne i32 %44, 87
br i1 %45, label %64, label %46
46: ; preds = %40
%47 = load i8*, i8** %8
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = icmp ne i32 %50, 188
br i1 %51, label %64, label %52
52: ; preds = %46
%53 = load i8*, i8** %8
%54 = getelementptr inbounds i8, i8* %53, i64 2
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = icmp ne i32 %56, 0
br i1 %57, label %64, label %58
58: ; preds = %52
%59 = load i8*, i8** %8
%60 = getelementptr inbounds i8, i8* %59, i64 3
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %58, %52, %46, %40
%65 = load i8*, i8** %8
%66 = call i32 @free(i8* %65)
store i8* null, i8** %3
br label %97
67: ; preds = %58
%68 = load i8*, i8** %8
%69 = call i32 @stb_decompress_length(i8* %68)
%70 = add nsw i32 %69, 1
%71 = call i64 @malloc(i32 %70)
%72 = inttoptr i64 %71 to i8*
store i8* %72, i8** %7
%73 = load i8*, i8** %7
%74 = icmp ne i8* %73, null
br i1 %74, label %78, label %75
75: ; preds = %67
%76 = load i8*, i8** %8
%77 = call i32 @free(i8* %76)
store i8* null, i8** %3
br label %97
78: ; preds = %67
%79 = load i8*, i8** %7
%80 = load i8*, i8** %8
%81 = load i32, i32* %6
%82 = call i32 @stb_decompress(i8* %79, i8* %80, i32 %81)
%83 = load i32*, i32** %5
store i32 %82, i32* %83
%84 = load i32*, i32** %5
%85 = load i32, i32* %84
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %93
87: ; preds = %78
%88 = load i8*, i8** %7
%89 = load i32*, i32** %5
%90 = load i32, i32* %89
%91 = zext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %88, i64 %91
store i8 0, i8* %92
br label %93
93: ; preds = %87, %78
%94 = load i8*, i8** %8
%95 = call i32 @free(i8* %94)
%96 = load i8*, i8** %7
store i8* %96, i8** %3
br label %97
97: ; preds = %93, %75, %64, %39, %29, %14
%98 = load i8*, i8** %3
ret i8* %98
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @stb_decompress_fromfile(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %46, label %5
5: ; preds = %2
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %3, i32 0, i32 %6)
%8 = tail call i32 @ftell(i32* %3)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %3, i32 0, i32 %9)
%11 = tail call i64 @malloc(i32 %8)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %46, label %14
14: ; preds = %5
%15 = tail call i32 @fread(i8* %12, i32 1, i32 %8, i32* %3)
%16 = tail call i32 @fclose(i32* %3)
%17 = load i8, i8* %12
%18 = icmp eq i8 %17, 87
br i1 %18, label %19, label %43
19: ; preds = %14
%20 = getelementptr inbounds i8, i8* %12, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, -68
br i1 %22, label %23, label %43
23: ; preds = %19
%24 = getelementptr inbounds i8, i8* %12, i64 2
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %43
27: ; preds = %23
%28 = getelementptr inbounds i8, i8* %12, i64 3
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = tail call i32 @stb_decompress_length(i8* %12)
%33 = add nsw i32 %32, 1
%34 = tail call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
%36 = icmp eq i64 %34, 0
br i1 %36, label %43, label %37
37: ; preds = %31
%38 = tail call i32 @stb_decompress(i8* %35, i8* %12, i32 %8)
store i32 %38, i32* %1
%39 = icmp eq i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = zext i32 %38 to i64
%42 = getelementptr inbounds i8, i8* %35, i64 %41
store i8 0, i8* %42
br label %43
43: ; preds = %37, %40, %31, %14, %19, %23, %27
%44 = phi i8* [ null, %27 ], [ null, %23 ], [ null, %19 ], [ null, %14 ], [ null, %31 ], [ %35, %40 ], [ %35, %37 ]
%45 = tail call i32 @free(i8* %12)
br label %46
46: ; preds = %43, %5, %2
%47 = phi i8* [ null, %2 ], [ null, %5 ], [ %44, %43 ]
ret i8* %47
}