#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*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ sq905c_first_decompress(unsigned char *,
                                           unsigned char const *, int);
int /*<<< orphan*/ sq905c_second_decompress(unsigned char *, unsigned char *,
                                            int, int);
void v4lconvert_decode_sq905c(const unsigned char *src, unsigned char *dst,
                              int width, int height) {
  int size;
  unsigned char *temp_data;
  const unsigned char *raw;
  raw = src + 0x50;
  size = width * height / 2;
  temp_data = malloc(size);
  if (!temp_data)
    goto out;
  sq905c_first_decompress(temp_data, raw, size);
  sq905c_second_decompress(dst, temp_data, width, height);
out:
  free(temp_data);
}


x86 assembly (clang, -O0):
<v4lconvert_decode_sq905c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1190 <v4lconvert_decode_sq905c+0x50>
jmp    11b3 <v4lconvert_decode_sq905c+0x73>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <sq905c_first_decompress@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <sq905c_second_decompress@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v4lconvert_decode_sq905c>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r13
mov    %ecx,%eax
imul   %edx,%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1196 <v4lconvert_decode_sq905c+0x56>
add    $0x50,%r13
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1050 <sq905c_first_decompress@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1040 <sq905c_second_decompress@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @v4lconvert_decode_sq905c(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 80
store i8* %13, i8** %11
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = mul nsw i32 %14, %15
%17 = sdiv i32 %16, 2
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %10
%20 = load i8*, i8** %10
%21 = icmp ne i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %4
br label %33
23: ; preds = %4
%24 = load i8*, i8** %10
%25 = load i8*, i8** %11
%26 = load i32, i32* %9
%27 = call i32 @sq905c_first_decompress(i8* %24, i8* %25, i32 %26)
%28 = load i8*, i8** %6
%29 = load i8*, i8** %10
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = call i32 @sq905c_second_decompress(i8* %28, i8* %29, i32 %30, i32 %31)
br label %33
33: ; preds = %23, %22
%34 = load i8*, i8** %10
%35 = call i32 @free(i8* %34)
ret void
}

LLVM IR (-O2):
define void @v4lconvert_decode_sq905c(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = mul nsw i32 %3, %2
%6 = sdiv i32 %5, 2
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %0, i64 80
%11 = tail call i32 @sq905c_first_decompress(i8* %7, i8* %10, i32 %6)
%12 = tail call i32 @sq905c_second_decompress(i8* %1, i8* %7, i32 %2, i32 %3)
br label %13
13: ; preds = %4, %9
%14 = tail call i32 @free(i8* %7)
ret void
}