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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fread(unsigned char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
scalar_t__ is_id3v1(int /*<<< orphan*/ *);
scalar_t__ is_tag_ape2long(unsigned char *);
scalar_t__ memcmp(unsigned char *, char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int is_ape_ver(FILE *fp) {
  char unsigned buf[32];
  size_t savedFilePosition;
  savedFilePosition = ftell(fp);
  memset(buf, 0, sizeof(buf));
  fseek(fp, (is_id3v1(fp) ? -32 - 128 : -32), SEEK_END);
  fread(&buf, 1, sizeof(buf), fp);
  if (memcmp(buf, "APETAGEX", 8) != 0) {
    fseek(fp, savedFilePosition, SEEK_SET);
    return 0;
  }
  fseek(fp, savedFilePosition, SEEK_SET);
  return (int)is_tag_ape2long(buf + 8);
}


x86 assembly (clang, -O0):
<is_ape_ver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <is_id3v1@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rdx
mov    $0xffffffe0,%eax
mov    $0xffffff60,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
movslq %eax,%rsi
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x20,%edx
call   1030 <fread@plt>
lea    -0x30(%rbp),%rdi
lea    0xe0b(%rip),%rsi
mov    $0x8,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     122b <is_ape_ver+0xbb>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
movl   $0x0,-0x4(%rbp)
jmp    1251 <is_ape_ver+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x2d9e(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
lea    -0x30(%rbp),%rdi
add    $0x8,%rdi
call   1040 <is_tag_ape2long@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_ape_ver>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
call   1070 <ftell@plt>
mov    %rax,%r15
mov    %rsp,%r12
xor    %r14d,%r14d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1090 <is_id3v1@plt>
xor    %esi,%esi
test   %rax,%rax
sete   %sil
shl    $0x7,%esi
or     $0xffffffffffffff60,%rsi
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1080 <fseek@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x20,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0xe1d(%rip),%rsi
mov    %r12,%rdi
mov    $0x8,%edx
call   1060 <memcmp@plt>
mov    %rax,%r12
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <fseek@plt>
test   %r12,%r12
jne    1219 <is_ape_ver+0xa9>
lea    0x8(%rsp),%rdi
call   1040 <is_tag_ape2long@plt>
mov    %rax,%r14
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [9 x i8] c"APETAGEX\00"
@SEEK_SET = global i32 0
define i32 @is_ape_ver(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [32 x i8]
%5 = alloca i64
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i64 @ftell(i32* %6)
store i64 %7, i64* %5
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 32)
%10 = load i32*, i32** %3
%11 = load i32*, i32** %3
%12 = call i64 @is_id3v1(i32* %11)
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 -160, i32 -32
%16 = sext i32 %15 to i64
%17 = load i32, i32* @SEEK_END
%18 = call i32 @fseek(i32* %10, i64 %16, i32 %17)
%19 = bitcast [32 x i8]* %4 to i8**
%20 = load i32*, i32** %3
%21 = call i32 @fread(i8** %19, i32 1, i32 32, i32* %20)
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%23 = call i64 @memcmp(i8* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %1
%26 = load i32*, i32** %3
%27 = load i64, i64* %5
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %26, i64 %27, i32 %28)
store i32 0, i32* %2
br label %39
30: ; preds = %1
%31 = load i32*, i32** %3
%32 = load i64, i64* %5
%33 = load i32, i32* @SEEK_SET
%34 = call i32 @fseek(i32* %31, i64 %32, i32 %33)
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%36 = getelementptr inbounds i8, i8* %35, i64 8
%37 = call i64 @is_tag_ape2long(i8* %36)
%38 = trunc i64 %37 to i32
store i32 %38, i32* %2
br label %39
39: ; preds = %30, %25
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [9 x i8] c"APETAGEX\00"
@SEEK_SET = global i32 0
define i32 @is_ape_ver(i32* %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @ftell(i32* %0)
%5 = call i32 @memset(i8* %3, i32 0, i32 32)
%6 = call i64 @is_id3v1(i32* %0)
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i64 -32, i64 -160
%9 = load i32, i32* @SEEK_END
%10 = call i32 @fseek(i32* %0, i64 %8, i32 %9)
%11 = bitcast [32 x i8]* %2 to i8**
%12 = call i32 @fread(i8** %11, i32 1, i32 32, i32* %0)
%13 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%14 = icmp eq i64 %13, 0
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %0, i64 %4, i32 %15)
br i1 %14, label %17, label %21
17: ; preds = %1
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 8
%19 = call i64 @is_tag_ape2long(i8* %18)
%20 = trunc i64 %19 to i32
br label %21
21: ; preds = %1, %17
%22 = phi i32 [ %20, %17 ], [ 0, %1 ]
ret i32 %22
}