#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 long uLong;
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 fread(char *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char *malloc(long);
int /*<<< orphan*/ printf(char *);
char *readhtml(char *path, uLong *tlen) {
  static char *filebuf;
  FILE *f = fopen(path, "rb");
  if (f == NULL) {
    printf("Invalid config path.");
  }
  fseek(f, 0, SEEK_END);
  long pos = ftell(f);
  fseek(f, 0, SEEK_SET);
  *tlen = pos;
  filebuf = malloc(pos);
  if (filebuf == NULL) {
    printf("No enough memory.\n");
  }
  int nread = fread(filebuf, pos, 1, f);
  if (!nread) {
    printf("Failed to read the config file.\n");
  }
  fclose(f);
  return filebuf;
}


x86 assembly (clang, -O0):
<readhtml>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <readhtml+0x3b>
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,0x2e65(%rip)
cmpq   $0x0,0x2e5d(%rip)
jne    1215 <readhtml+0xa5>
lea    0xe08(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e44(%rip),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1247 <readhtml+0xd7>
lea    0xde9(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2e09(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readhtml>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xe71(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a8 <readhtml+0x28>
lea    0xe60(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%r15
mov    0x2e0b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r15,(%r14)
mov    %r15,%rdi
call   1080 <malloc@plt>
mov    %rax,0x2e7d(%rip)
test   %rax,%rax
jne    1203 <readhtml+0x83>
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e65(%rip),%rax
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jne    1226 <readhtml+0xa6>
lea    0xdf7(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2e33(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@readhtml.filebuf = internal global i8* null
@.str = [3 x i8] c"rb\00"
@.str.1 = [21 x i8] c"Invalid config path.\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [19 x i8] c"No enough memory.\0A\00"
@.str.3 = [33 x i8] c"Failed to read the config file.\0A\00"
define i8* @readhtml(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
store i64* %1, i64** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32*, i32** %5
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %5
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %6
%20 = load i32*, i32** %5
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @fseek(i32* %20, i32 0, i32 %21)
%23 = load i64, i64* %6
%24 = load i64*, i64** %4
store i64 %23, i64* %24
%25 = load i64, i64* %6
%26 = call i8* @malloc(i64 %25)
store i8* %26, i8** @readhtml.filebuf
%27 = load i8*, i8** @readhtml.filebuf
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %14
%30 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %14
%32 = load i8*, i8** @readhtml.filebuf
%33 = load i64, i64* %6
%34 = load i32*, i32** %5
%35 = call i32 @fread(i8* %32, i64 %33, i32 1, i32* %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %31
%39 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %31
%41 = load i32*, i32** %5
%42 = call i32 @fclose(i32* %41)
%43 = load i8*, i8** @readhtml.filebuf
ret i8* %43
}

LLVM IR (-O2):
@readhtml.filebuf = internal unnamed_addr global i8* null
@.str = [3 x i8] c"rb\00"
@.str.1 = [21 x i8] c"Invalid config path.\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@str = [32 x i8] c"Failed to read the config file.\00"
@str.4 = [18 x i8] c"No enough memory.\00"
define i8* @readhtml(i8* nocapture %0, i64* 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 %5, label %7
5: ; preds = %2
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %3, i32 0, i32 %8)
%10 = tail call i64 @ftell(i32* %3)
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %3, i32 0, i32 %11)
store i64 %10, i64* %1
%13 = tail call i8* @malloc(i64 %10)
store i8* %13, i8** @readhtml.filebuf
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
%17 = load i8*, i8** @readhtml.filebuf
br label %18
18: ; preds = %15, %7
%19 = phi i8* [ %17, %15 ], [ %13, %7 ]
%20 = tail call i32 @fread(i8* %19, i64 %10, i32 1, i32* %3)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = tail call i32 @fclose(i32* %3)
%26 = load i8*, i8** @readhtml.filebuf
ret i8* %26
}