#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 /*<<< 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_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);
    fread(&buf, 1, sizeof(buf), fp);
    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,-0x8(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%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    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2e3a(%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    0xe31(%rip),%rsi
mov    $0x3,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     11e8 <is_id3v2+0x98>
jmp    123c <is_id3v2+0xec>
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    0xdd8(%rip),%rsi
mov    $0x3,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1187 <is_id3v2+0x37>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x30(%rbp),%rax
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,%r15
call   1060 <ftell@plt>
mov    %rax,%r14
mov    0x2e70(%rip),%rbp
mov    0x0(%rbp),%edx
xor    %ebx,%ebx
mov    %r15,%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    %r15,%rdi
mov    %rbx,%rsi
call   1070 <fseek@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x3,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    1224 <is_id3v2+0xd4>
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    %r15,%rdi
mov    %r14,%rsi
call   1070 <fseek@plt>
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 [16 x i8]
%4 = alloca i64
%5 = alloca i64
store i32* %0, i32** %2
store i64 0, i64* %5
%6 = load i32*, i32** %2
%7 = call i64 @ftell(i32* %6)
store i64 %7, i64* %4
%8 = load i32*, i32** %2
%9 = load i32, i32* @SEEK_SET
%10 = call i32 @fseek(i32* %8, i64 0, i32 %9)
br label %11
11: ; preds = %47, %1
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 16)
%14 = load i32*, i32** %2
%15 = load i64, i64* %5
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @fseek(i32* %14, i64 %15, i32 %16)
%18 = bitcast [16 x i8]* %3 to i8**
%19 = load i32*, i32** %2
%20 = call i32 @fread(i8** %18, i32 1, i32 16, i32* %19)
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%22 = call i64 @memcmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %11
br label %51
25: ; preds = %11
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 9
%27 = load i8, i8* %26
%28 = sext i8 %27 to i64
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 8
%30 = load i8, i8* %29
%31 = sext i8 %30 to i64
%32 = shl i64 %31, 7
%33 = or i64 %28, %32
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 7
%35 = load i8, i8* %34
%36 = sext i8 %35 to i64
%37 = shl i64 %36, 14
%38 = or i64 %33, %37
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 6
%40 = load i8, i8* %39
%41 = sext i8 %40 to i64
%42 = shl i64 %41, 21
%43 = or i64 %38, %42
%44 = add nsw i64 10, %43
%45 = load i64, i64* %5
%46 = add nsw i64 %45, %44
store i64 %46, i64* %5
br label %47
47: ; preds = %25
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%49 = call i64 @memcmp(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%50 = icmp eq i64 %49, 0
br i1 %50, label %11, label %51
51: ; preds = %47, %24
%52 = load i32*, i32** %2
%53 = load i64, i64* %4
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @fseek(i32* %52, i64 %53, i32 %54)
%56 = load i64, i64* %5
%57 = trunc i64 %56 to i32
ret i32 %57
}

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 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 9
%8 = bitcast [16 x i8]* %2 to i8**
%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 = %20, %1
%13 = phi i64 [ 0, %1 ], [ %36, %20 ]
%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** %8, i32 1, i32 16, i32* %0)
%18 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %39
20: ; preds = %12
%21 = load i8, i8* %7
%22 = sext i8 %21 to i64
%23 = load i8, i8* %9
%24 = sext i8 %23 to i64
%25 = shl nsw i64 %24, 7
%26 = or i64 %25, %22
%27 = load i8, i8* %10
%28 = sext i8 %27 to i64
%29 = shl nsw i64 %28, 14
%30 = or i64 %26, %29
%31 = load i8, i8* %11
%32 = sext i8 %31 to i64
%33 = shl nsw i64 %32, 21
%34 = or i64 %30, %33
%35 = add i64 %13, 10
%36 = add i64 %35, %34
%37 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%38 = icmp eq i64 %37, 0
br i1 %38, label %12, label %39
39: ; preds = %12, %20
%40 = phi i64 [ %13, %12 ], [ %36, %20 ]
%41 = load i32, i32* @SEEK_SET
%42 = call i32 @fseek(i32* %0, i64 %4, i32 %41)
%43 = trunc i64 %40 to i32
ret i32 %43
}