// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/mp3.c
// Function: de_identify_mpegaudio
static int de_identify_mpegaudio(deark *c)
{
	unsigned int x;
	unsigned int ver_id, lyr_id;
	int has_mp1_ext = 0;
	int has_mp2_ext = 0;
	int has_mp3_ext = 0;
	int has_any_ext;
	int looks_valid = 0;
	u8 has_id3v2;
	i64 pos;

	if(!c->detection_data->id3.detection_attempted) {
		de_err(c, "mpegaudio detection requires id3 module");
		return 0;
	}

	if(de_input_file_has_ext(c, "mp3")) {
		has_mp3_ext = 1;
	}
	if(de_input_file_has_ext(c, "mp2")) {
		has_mp2_ext = 1;
	}
	if(de_input_file_has_ext(c, "mp1")) {
		has_mp1_ext = 1;
	}
	else if(de_input_file_has_ext(c, "mpa")) {
		has_mp1_ext = 1;
		has_mp2_ext = 1;
		has_mp3_ext = 1;
	}
	has_any_ext = has_mp3_ext || has_mp2_ext || has_mp1_ext;

	has_id3v2 = c->detection_data->id3.has_id3v2;

	if(!has_id3v2 && !has_any_ext) {
		// TODO: We could try harder to identify MP3.
		return 0;
	}

	if(has_id3v2) {
		pos = (i64)c->detection_data->id3.bytes_at_start;
	}
	else {
		pos = 0;
	}

	x = (unsigned int)de_getu16be(pos);
	if((x&0xffe0) == 0xffe0) {
		ver_id = (x&0x0018)>>3;
		lyr_id = (x&0x0006)>>1;

		if(has_mp3_ext) {
			if((lyr_id==1) && (ver_id!=1)) looks_valid = 1;
		}
		if(has_mp2_ext) {
			if((lyr_id==2) && (ver_id==2 || ver_id==3)) looks_valid = 1;
		}
		if(has_mp1_ext) {
			if((lyr_id==3) && (ver_id==2 || ver_id==3)) looks_valid = 1;
		}
	}

	if(has_id3v2 && looks_valid) return 100;
	if(has_id3v2 && !looks_valid) {
		// This must be lower than the corresponding confidence for other
		// audio formats that might start with ID3v2, like Ogg.
		return 80;
	}
	if(looks_valid) {
		return 100;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
cmpb $0x0, 0x14(%rax)
jne 0xdfc94
movq -0x10(%rbp), %rdi
leaq 0xdce5a(%rip), %rsi     # 0x1bcadb
movb $0x0, %al
callq 0x15bfb0
movl $0x0, -0x4(%rbp)
jmp 0xdfe65
movq -0x10(%rbp), %rdi
leaq 0xdc9ea(%rip), %rsi     # 0x1bc689
callq 0x15d180
cmpl $0x0, %eax
je 0xdfcb0
movl $0x1, -0x28(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xdce48(%rip), %rsi     # 0x1bcb03
callq 0x15d180
cmpl $0x0, %eax
je 0xdfccc
movl $0x1, -0x24(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xf7072(%rip), %rsi     # 0x1d6d49
callq 0x15d180
cmpl $0x0, %eax
je 0xdfcea
movl $0x1, -0x20(%rbp)
jmp 0xdfd16
movq -0x10(%rbp), %rdi
leaq 0xdce12(%rip), %rsi     # 0x1bcb07
callq 0x15d180
cmpl $0x0, %eax
je 0xdfd14
movl $0x1, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x1, -0x28(%rbp)
jmp 0xdfd16
movb $0x1, %al
cmpl $0x0, -0x28(%rbp)
movb %al, -0x41(%rbp)
jne 0xdfd36
movb $0x1, %al
cmpl $0x0, -0x24(%rbp)
movb %al, -0x41(%rbp)
jne 0xdfd36
cmpl $0x0, -0x20(%rbp)
setne %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movb 0x15(%rax), %al
movb %al, -0x31(%rbp)
cmpb $0x0, -0x31(%rbp)
jne 0xdfd67
cmpl $0x0, -0x2c(%rbp)
jne 0xdfd67
movl $0x0, -0x4(%rbp)
jmp 0xdfe65
cmpb $0x0, -0x31(%rbp)
je 0xdfd7e
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x18(%rax), %eax
movq %rax, -0x40(%rbp)
jmp 0xdfd86
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x1651d0
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
andl $0xffe0, %eax           # imm = 0xFFE0
cmpl $0xffe0, %eax           # imm = 0xFFE0
jne 0xdfe1f
movl -0x14(%rbp), %eax
andl $0x18, %eax
shrl $0x3, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
andl $0x6, %eax
shrl %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0xdfddb
cmpl $0x1, -0x1c(%rbp)
jne 0xdfdd9
cmpl $0x1, -0x18(%rbp)
je 0xdfdd9
movl $0x1, -0x30(%rbp)
jmp 0xdfddb
cmpl $0x0, -0x24(%rbp)
je 0xdfdfc
cmpl $0x2, -0x1c(%rbp)
jne 0xdfdfa
cmpl $0x2, -0x18(%rbp)
je 0xdfdf3
cmpl $0x3, -0x18(%rbp)
jne 0xdfdfa
movl $0x1, -0x30(%rbp)
jmp 0xdfdfc
cmpl $0x0, -0x20(%rbp)
je 0xdfe1d
cmpl $0x3, -0x1c(%rbp)
jne 0xdfe1b
cmpl $0x2, -0x18(%rbp)
je 0xdfe14
cmpl $0x3, -0x18(%rbp)
jne 0xdfe1b
movl $0x1, -0x30(%rbp)
jmp 0xdfe1d
jmp 0xdfe1f
movzbl -0x31(%rbp), %eax
cmpl $0x0, %eax
je 0xdfe37
cmpl $0x0, -0x30(%rbp)
je 0xdfe37
movl $0x64, -0x4(%rbp)
jmp 0xdfe65
movzbl -0x31(%rbp), %eax
cmpl $0x0, %eax
je 0xdfe4f
cmpl $0x0, -0x30(%rbp)
jne 0xdfe4f
movl $0x50, -0x4(%rbp)
jmp 0xdfe65
cmpl $0x0, -0x30(%rbp)
je 0xdfe5e
movl $0x64, -0x4(%rbp)
jmp 0xdfe65
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop