#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(char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int is_id3v1(FILE *fp) {
  int n = 0;
  char buf[16];
  size_t savedFilePosition;
  savedFilePosition = ftell(fp);
  fseek(fp, 0, SEEK_END);
  do {
    n++;
    memset(buf, 0, sizeof(buf));
    fseek(fp, ((-128) * n) - 3, SEEK_END);
    fread(&buf, 1, sizeof(buf), fp);
    if (memcmp(buf, "APETAGEX", 8) == 0)
      break;
  } while (memcmp(buf + 3, "TAG", 3) == 0);
  fseek(fp, savedFilePosition, SEEK_SET);
  return (n - 1) * 128;
}


x86 assembly (clang, -O0):
<is_id3v1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
imul   $0xffffff80,-0xc(%rbp),%eax
sub    $0x3,%eax
movslq %eax,%rsi
mov    0x2e31(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1030 <fread@plt>
lea    -0x20(%rbp),%rdi
lea    0xe20(%rip),%rsi
mov    $0x8,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    11f9 <is_id3v1+0xa9>
jmp    1221 <is_id3v1+0xd1>
jmp    11fe <is_id3v1+0xae>
lea    -0x20(%rbp),%rdi
add    $0x3,%rdi
lea    0xdfc(%rip),%rsi
mov    $0x3,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1186 <is_id3v1+0x36>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
shl    $0x7,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_id3v1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r15
call   1060 <ftell@plt>
mov    %rax,0x8(%rsp)
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
lea    0x10(%rsp),%r13
lea    0xe74(%rip),%rbp
lea    0xe76(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%r12
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x83(%rbx),%rsi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
call   1070 <fseek@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     1210 <is_id3v1+0xc0>
lea    0x13(%rsp),%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1050 <memcmp@plt>
lea    -0x80(%r12),%rbx
test   %rax,%rax
je     11a0 <is_id3v1+0x50>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    0x8(%rsp),%rsi
call   1070 <fseek@plt>
neg    %r12d
mov    %r12d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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