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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ memcmp(char *, char *, int);
int strlen(char *);
int __trie_check_magic(FILE *fp) {
  int res;
  char read_magic[sizeof(*"TRIE") * strlen("TRIE")];
  res = fread(read_magic, sizeof(*"TRIE"), strlen("TRIE"), fp);
  assert(res == strlen("TRIE"));
  if (res != strlen("TRIE"))
    return -1;
  return (memcmp(read_magic, "TRIE", sizeof(read_magic)) == 0) ? 0 : -1;
}


x86 assembly (clang, -O0):
<__trie_check_magic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
call   1040 <strlen@plt>
cltq
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe78(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    0xe4f(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    0xe29(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
je     11fc <__trie_check_magic+0xbc>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    122d <__trie_check_magic+0xed>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    %eax,%edx
lea    0xdf3(%rip),%rsi
call   1050 <memcmp@plt>
mov    %rax,%rdx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__trie_check_magic>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
lea    0xeab(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
cltq
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1040 <strlen@plt>
xor    %edi,%edi
cmp    %eax,%r12d
sete   %dil
call   1060 <assert@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%r12d
jne    11d1 <__trie_check_magic+0x91>
lea    0xe3f(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1050 <memcmp@plt>
neg    %rax
sbb    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"TRIE\00"
define i32 @__trie_check_magic(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32* %0, i32** %3
%8 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = sext i32 %8 to i64
%10 = mul i64 1, %9
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = load i32*, i32** %3
%15 = call i32 @fread(i8* %12, i32 1, i32 %13, i32* %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32 %16, %17
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %4
%22 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %1
store i32 -1, i32* %2
store i32 1, i32* %7
br label %31
25: ; preds = %1
%26 = trunc i64 %10 to i32
%27 = call i64 @memcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 0, i32 -1
store i32 %30, i32* %2
store i32 1, i32* %7
br label %31
31: ; preds = %25, %24
%32 = load i8*, i8** %5
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [5 x i8] c"TRIE\00"
define i32 @__trie_check_magic(i32* nocapture %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = sext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @fread(i8* %4, i32 1, i32 %5, i32* %0)
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %6, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %6, %11
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %2)
%15 = icmp ne i64 %14, 0
%16 = sext i1 %15 to i32
br label %17
17: ; preds = %1, %13
%18 = phi i32 [ %16, %13 ], [ -1, %1 ]
ret i32 %18
}