#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_SET;
int 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_id3v2(FILE *fp) {
  char buf[16];
  size_t savedFilePosition;
  long id3v2size = 0;
  savedFilePosition = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  do {
    memset(buf, 0, sizeof(buf));
    fseek(fp, id3v2size, SEEK_SET);
    if (fread(&buf, 1, sizeof(buf), fp) != sizeof(buf)) {
      fseek(fp, savedFilePosition, SEEK_SET);
      return 0;
    }
    if (memcmp(buf, "ID3", 3) != 0) {
      break;
    }
    id3v2size += 10 + (((long)(buf[9])) | ((long)(buf[8]) << 7) |
                       ((long)(buf[7]) << 14) | ((long)(buf[6]) << 21));
  } while (memcmp(buf, "ID3", 3) == 0);
  fseek(fp, savedFilePosition, SEEK_SET);
  return (int)id3v2size;
}


x86 assembly (clang, -O0):
<is_id3v2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1030 <fread@plt>
cltq
cmp    $0x10,%rax
je     11f2 <is_id3v2+0xa2>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
movl   $0x0,-0x4(%rbp)
jmp    1287 <is_id3v2+0x137>
lea    -0x20(%rbp),%rdi
lea    0xe03(%rip),%rsi
mov    $0x3,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1216 <is_id3v2+0xc6>
jmp    126a <is_id3v2+0x11a>
movsbq -0x17(%rbp),%rax
movsbq -0x18(%rbp),%rcx
shl    $0x7,%rcx
or     %rcx,%rax
movsbq -0x19(%rbp),%rcx
shl    $0xe,%rcx
or     %rcx,%rax
movsbq -0x1a(%rbp),%rcx
shl    $0x15,%rcx
or     %rcx,%rax
add    $0xa,%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xdaa(%rip),%rsi
mov    $0x3,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1187 <is_id3v2+0x37>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2d67(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x30(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_id3v2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
call   1060 <ftell@plt>
mov    %rax,%r15
mov    0x2e70(%rip),%rbp
mov    0x0(%rbp),%edx
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rsp,%r12
lea    0xe77(%rip),%r13
nopl   0x0(%rax)
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x0(%rbp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <fseek@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x10,%eax
jne    1239 <is_id3v2+0xe9>
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x3,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    1229 <is_id3v2+0xd9>
movsbq 0x9(%rsp),%rax
movsbq 0x8(%rsp),%rcx
shl    $0x7,%rcx
or     %rax,%rcx
movsbq 0x7(%rsp),%rax
shl    $0xe,%rax
movsbq 0x6(%rsp),%rdx
shl    $0x15,%rdx
or     %rax,%rdx
or     %rcx,%rdx
add    %rdx,%rbx
add    $0xa,%rbx
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x3,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     1190 <is_id3v2+0x40>
mov    0x0(%rbp),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <fseek@plt>
jmp    1249 <is_id3v2+0xf9>
mov    0x0(%rbp),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <fseek@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [4 x i8] c"ID3\00"
define i32 @is_id3v2(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_SET
%6 = tail call i32 @fseek(i32* %0, i64 0, i32 %5)
%7 = bitcast [16 x i8]* %2 to i8**
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 9
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 8
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 7
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 6
br label %12
12: ; preds = %25, %1
%13 = phi i64 [ 0, %1 ], [ %41, %25 ]
%14 = call i32 @memset(i8* %3, i32 0, i32 16)
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %0, i64 %13, i32 %15)
%17 = call i32 @fread(i8** %7, i32 1, i32 16, i32* %0)
%18 = icmp eq i32 %17, 16
br i1 %18, label %22, label %19
19: ; preds = %12
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %0, i64 %4, i32 %20)
br label %49
22: ; preds = %12
%23 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %44
25: ; preds = %22
%26 = load i8, i8* %8
%27 = sext i8 %26 to i64
%28 = load i8, i8* %9
%29 = sext i8 %28 to i64
%30 = shl nsw i64 %29, 7
%31 = or i64 %30, %27
%32 = load i8, i8* %10
%33 = sext i8 %32 to i64
%34 = shl nsw i64 %33, 14
%35 = or i64 %31, %34
%36 = load i8, i8* %11
%37 = sext i8 %36 to i64
%38 = shl nsw i64 %37, 21
%39 = or i64 %35, %38
%40 = add i64 %13, 10
%41 = add i64 %40, %39
%42 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%43 = icmp eq i64 %42, 0
br i1 %43, label %12, label %44
44: ; preds = %22, %25
%45 = phi i64 [ %13, %22 ], [ %41, %25 ]
%46 = load i32, i32* @SEEK_SET
%47 = call i32 @fseek(i32* %0, i64 %4, i32 %46)
%48 = trunc i64 %45 to i32
br label %49
49: ; preds = %44, %19
%50 = phi i32 [ 0, %19 ], [ %48, %44 ]
ret i32 %50
}