#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;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *strstr(char *, char *);
short trailerContainsHTML(FILE *file) {
  fseek(file, -512, SEEK_END);
  char *htmlBuf = (char *)calloc(512, 1);
  fread(htmlBuf, 512, 1, file);
  short tailExists = (strstr(htmlBuf, "</html>") != NULL);
  free(htmlBuf);
  return tailExists;
}


x86 assembly (clang, -O0):
<trailerContainsHTML>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffe00,%esi
call   1060 <fseek@plt>
mov    $0x200,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %ax,-0x12(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movswl -0x12(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trailerContainsHTML>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffe00,%esi
call   1060 <fseek@plt>
mov    $0x200,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [8 x i8] c"</html>\00"
define signext i16 @trailerContainsHTML(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i16
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = load i32, i32* @SEEK_END
%7 = call i32 @fseek(i32* %5, i32 -512, i32 %6)
%8 = call i64 @calloc(i32 512, i32 1)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = load i32*, i32** %2
%12 = call i32 @fread(i8* %10, i32 512, i32 1, i32* %11)
%13 = load i8*, i8** %3
%14 = call i32* @strstr(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i32* %14, null
%16 = zext i1 %15 to i32
%17 = trunc i32 %16 to i16
store i16 %17, i16* %4
%18 = load i8*, i8** %3
%19 = call i32 @free(i8* %18)
%20 = load i16, i16* %4
ret i16 %20
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [8 x i8] c"</html>\00"
define signext i16 @trailerContainsHTML(i32* nocapture %0) {
%2 = load i32, i32* @SEEK_END
%3 = tail call i32 @fseek(i32* %0, i32 -512, i32 %2)
%4 = tail call i64 @calloc(i32 512, i32 1)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @fread(i8* %5, i32 512, i32 1, i32* %0)
%7 = tail call i32* @strstr(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i32* %7, null
%9 = zext i1 %8 to i16
%10 = tail call i32 @free(i8* %5)
ret i16 %9
}