#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 */

/* Variables and functions */
int /*<<< orphan*/ memcpy(int *, unsigned char *, int);
int synchsafe_to_int(unsigned char *, int);
int id3v2_size(unsigned char data[14]) {
  int major_version;
  unsigned char id3v2_flags;
  int id3v2_len = 0;
  int head;
  memcpy(&head, data, 4);
  head = head;
  if ((head & 0xffffff00) == 0x49443300) {
    major_version = head & 0xff;
    id3v2_flags = data[5];
    id3v2_len = 10 + synchsafe_to_int(&data[6], 4);
    if (id3v2_flags & 0x40) {
      if (major_version != 3)
        id3v2_len += synchsafe_to_int(&data[10], 4);
      else
        id3v2_len += ((int *)&data[10])[0];
    }
    id3v2_len += (id3v2_flags & 0x10) ? 10 : 0;
  }
  return id3v2_len;
}


x86 assembly (clang, -O0):
<id3v2_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x18(%rbp),%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0xffffff00,%eax
cmp    $0x49443300,%eax
jne    11ee <id3v2_size+0xce>
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x5(%rax),%al
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x6,%rdi
mov    $0x4,%esi
call   1030 <synchsafe_to_int@plt>
add    $0xa,%eax
mov    %eax,-0x14(%rbp)
movzbl -0xd(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     11d4 <id3v2_size+0xb4>
cmpl   $0x3,-0xc(%rbp)
je     11c2 <id3v2_size+0xa2>
mov    -0x8(%rbp),%rdi
add    $0xa,%rdi
mov    $0x4,%esi
call   1030 <synchsafe_to_int@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11cf <id3v2_size+0xaf>
mov    -0x8(%rbp),%rax
mov    0xa(%rax),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11d4 <id3v2_size+0xb4>
movzbl -0xd(%rbp),%edx
and    $0x10,%edx
xor    %eax,%eax
mov    $0xa,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id3v2_size>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x4(%rsp),%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0x4(%rsp),%ebp
mov    %ebp,%eax
and    $0xffffff00,%eax
xor    %ebx,%ebx
cmp    $0x49443300,%eax
jne    119a <id3v2_size+0x7a>
movzbl 0x5(%r14),%ebx
lea    0x6(%r14),%rdi
mov    $0x4,%esi
call   1030 <synchsafe_to_int@plt>
mov    %eax,%r15d
add    $0xa,%r15d
test   $0x40,%bl
je     118e <id3v2_size+0x6e>
add    $0xa,%r14
cmp    $0x3,%bpl
jne    117e <id3v2_size+0x5e>
add    (%r14),%r15d
jmp    118e <id3v2_size+0x6e>
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <synchsafe_to_int@plt>
add    %eax,%r15d
shl    $0x1b,%ebx
sar    $0x1f,%ebx
and    $0xa,%ebx
add    %r15d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @id3v2_size(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%7 = load i8*, i8** %2
%8 = call i32 @memcpy(i32* %6, i8* %7, i32 4)
%9 = load i32, i32* %6
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = and i32 %10, -256
%12 = icmp eq i32 %11, 1229206272
br i1 %12, label %13, label %54
13: ; preds = %1
%14 = load i32, i32* %6
%15 = and i32 %14, 255
store i32 %15, i32* %3
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 5
%18 = load i8, i8* %17
store i8 %18, i8* %4
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 6
%21 = call i32 @synchsafe_to_int(i8* %20, i32 4)
%22 = add nsw i32 10, %21
store i32 %22, i32* %5
%23 = load i8, i8* %4
%24 = zext i8 %23 to i32
%25 = and i32 %24, 64
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %45
27: ; preds = %13
%28 = load i32, i32* %3
%29 = icmp ne i32 %28, 3
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i64 10
%33 = call i32 @synchsafe_to_int(i8* %32, i32 4)
%34 = load i32, i32* %5
%35 = add nsw i32 %34, %33
store i32 %35, i32* %5
br label %44
36: ; preds = %27
%37 = load i8*, i8** %2
%38 = getelementptr inbounds i8, i8* %37, i64 10
%39 = bitcast i8* %38 to i32*
%40 = getelementptr inbounds i32, i32* %39, i64 0
%41 = load i32, i32* %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, %41
store i32 %43, i32* %5
br label %44
44: ; preds = %36, %30
br label %45
45: ; preds = %44, %13
%46 = load i8, i8* %4
%47 = zext i8 %46 to i32
%48 = and i32 %47, 16
%49 = icmp ne i32 %48, 0
%50 = zext i1 %49 to i64
%51 = select i1 %49, i32 10, i32 0
%52 = load i32, i32* %5
%53 = add nsw i32 %52, %51
store i32 %53, i32* %5
br label %54
54: ; preds = %45, %1
%55 = load i32, i32* %5
ret i32 %55
}

LLVM IR (-O2):
define i32 @id3v2_size(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @memcpy(i32* %2, i8* %0, i32 4)
%5 = load i32, i32* %2
%6 = and i32 %5, -256
%7 = icmp eq i32 %6, 1229206272
br i1 %7, label %8, label %34
8: ; preds = %1
%9 = getelementptr inbounds i8, i8* %0, i64 5
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %0, i64 6
%12 = call i32 @synchsafe_to_int(i8* %11, i32 4)
%13 = add nsw i32 %12, 10
%14 = zext i8 %10 to i32
%15 = and i32 %14, 64
%16 = icmp eq i32 %15, 0
br i1 %16, label %28, label %17
17: ; preds = %8
%18 = and i32 %5, 255
%19 = icmp eq i32 %18, 3
%20 = getelementptr inbounds i8, i8* %0, i64 10
br i1 %19, label %24, label %21
21: ; preds = %17
%22 = call i32 @synchsafe_to_int(i8* %20, i32 4)
%23 = add nsw i32 %22, %13
br label %28
24: ; preds = %17
%25 = bitcast i8* %20 to i32*
%26 = load i32, i32* %25
%27 = add nsw i32 %26, %13
br label %28
28: ; preds = %21, %24, %8
%29 = phi i32 [ %23, %21 ], [ %27, %24 ], [ %13, %8 ]
%30 = and i32 %14, 16
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i32 0, i32 10
%33 = add nsw i32 %29, %32
br label %34
34: ; preds = %28, %1
%35 = phi i32 [ %33, %28 ], [ 0, %1 ]
ret i32 %35
}