#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 fread(char *, int, int, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
long mp3edit_get_size_from_index(int /*<<< orphan*/ *, long *, long *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int mp3edit_isvalid_index(FILE *mpegfp, FILE *indxfp) {
  long mpeg_size;
  long indx_mpeg_size;
  long sec, usec;
  char buf[3];
  if (!mpegfp || !indxfp) {
    return 0;
  }
  if (fseek(mpegfp, 0, SEEK_END) == -1) {
    return 0;
  }
  mpeg_size = ftell(mpegfp);
  indx_mpeg_size = mp3edit_get_size_from_index(indxfp, &sec, &usec);
  if (indx_mpeg_size == -1) {
    return -1;
  }
  if (indx_mpeg_size + 128 == mpeg_size) {
    if (fseek(mpegfp, -128, SEEK_END) == 0) {
      if (fread(buf, sizeof(buf), 1, mpegfp) == 1) {
        if (!strncmp(buf, "TAG", 3)) {
          indx_mpeg_size += 128;
        }
      }
    }
  }
  if (fseek(mpegfp, 0, SEEK_SET) == -1) {
    return 0;
  }
  return mpeg_size == indx_mpeg_size;
}


x86 assembly (clang, -O0):
<mp3edit_isvalid_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1176 <mp3edit_isvalid_index+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1182 <mp3edit_isvalid_index+0x32>
movl   $0x0,-0x4(%rbp)
jmp    12af <mp3edit_isvalid_index+0x15f>
mov    -0x10(%rbp),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
jne    11ab <mp3edit_isvalid_index+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    12af <mp3edit_isvalid_index+0x15f>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1070 <mp3edit_get_size_from_index@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    11e4 <mp3edit_isvalid_index+0x94>
movl   $0xffffffff,-0x4(%rbp)
jmp    12af <mp3edit_isvalid_index+0x15f>
mov    -0x28(%rbp),%rax
add    $0x80,%rax
cmp    -0x20(%rbp),%rax
jne    1273 <mp3edit_isvalid_index+0x123>
mov    -0x10(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
mov    $0xffffff80,%esi
call   1060 <fseek@plt>
cmp    $0x0,%eax
jne    126e <mp3edit_isvalid_index+0x11e>
lea    -0x3b(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x3,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1269 <mp3edit_isvalid_index+0x119>
lea    -0x3b(%rbp),%rdi
lea    0xdbd(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1264 <mp3edit_isvalid_index+0x114>
mov    -0x28(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x28(%rbp)
jmp    1269 <mp3edit_isvalid_index+0x119>
jmp    126e <mp3edit_isvalid_index+0x11e>
jmp    1273 <mp3edit_isvalid_index+0x123>
mov    -0x10(%rbp),%rdi
mov    0x2d5a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
jne    129c <mp3edit_isvalid_index+0x14c>
movl   $0x0,-0x4(%rbp)
jmp    12af <mp3edit_isvalid_index+0x15f>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp3edit_isvalid_index>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebp,%ebp
test   %rdi,%rdi
je     1241 <mp3edit_isvalid_index+0xf1>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1241 <mp3edit_isvalid_index+0xf1>
mov    %rdi,%r12
mov    0x2e69(%rip),%r13
mov    0x0(%r13),%edx
xor    %ebp,%ebp
xor    %esi,%esi
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
je     1241 <mp3edit_isvalid_index+0xf1>
mov    %r12,%rdi
call   1050 <ftell@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <mp3edit_get_size_from_index@plt>
cmp    $0xffffffffffffffff,%rax
je     123c <mp3edit_isvalid_index+0xec>
mov    %rax,%r15
add    $0x80,%rax
cmp    %r14,%rax
jne    1217 <mp3edit_isvalid_index+0xc7>
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    $0xffffff80,%esi
call   1060 <fseek@plt>
test   %eax,%eax
jne    1217 <mp3edit_isvalid_index+0xc7>
lea    0x5(%rsp),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1217 <mp3edit_isvalid_index+0xc7>
lea    0xdfe(%rip),%rsi
lea    0x5(%rsp),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
cmove  %r14,%r15
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %r12,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
je     1241 <mp3edit_isvalid_index+0xf1>
xor    %ebp,%ebp
cmp    %r15,%r14
sete   %bpl
jmp    1241 <mp3edit_isvalid_index+0xf1>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [4 x i8] c"TAG\00"
@SEEK_SET = global i32 0
define i32 @mp3edit_isvalid_index(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca [3 x i8]
store i32* %0, i32** %4
store i32* %1, i32** %5
%11 = load i32*, i32** %4
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32*, i32** %5
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %13, %2
store i32 0, i32* %3
br label %67
17: ; preds = %13
%18 = load i32*, i32** %4
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %18, i32 0, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 0, i32* %3
br label %67
23: ; preds = %17
%24 = load i32*, i32** %4
%25 = call i64 @ftell(i32* %24)
store i64 %25, i64* %6
%26 = load i32*, i32** %5
%27 = call i64 @mp3edit_get_size_from_index(i32* %26, i64* %8, i64* %9)
store i64 %27, i64* %7
%28 = load i64, i64* %7
%29 = icmp eq i64 %28, -1
br i1 %29, label %30, label %31
30: ; preds = %23
store i32 -1, i32* %3
br label %67
31: ; preds = %23
%32 = load i64, i64* %7
%33 = add nsw i64 %32, 128
%34 = load i64, i64* %6
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %56
36: ; preds = %31
%37 = load i32*, i32** %4
%38 = load i32, i32* @SEEK_END
%39 = call i32 @fseek(i32* %37, i32 -128, i32 %38)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %55
41: ; preds = %36
%42 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%43 = load i32*, i32** %4
%44 = call i32 @fread(i8* %42, i32 3, i32 1, i32* %43)
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %54
46: ; preds = %41
%47 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%48 = call i32 @strncmp(i8* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%49 = icmp ne i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %46
%51 = load i64, i64* %7
%52 = add nsw i64 %51, 128
store i64 %52, i64* %7
br label %53
53: ; preds = %50, %46
br label %54
54: ; preds = %53, %41
br label %55
55: ; preds = %54, %36
br label %56
56: ; preds = %55, %31
%57 = load i32*, i32** %4
%58 = load i32, i32* @SEEK_SET
%59 = call i32 @fseek(i32* %57, i32 0, i32 %58)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %62
61: ; preds = %56
store i32 0, i32* %3
br label %67
62: ; preds = %56
%63 = load i64, i64* %6
%64 = load i64, i64* %7
%65 = icmp eq i64 %63, %64
%66 = zext i1 %65 to i32
store i32 %66, i32* %3
br label %67
67: ; preds = %62, %61, %30, %22, %16
%68 = load i32, i32* %3
ret i32 %68
}

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