#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 */
scalar_t__ CheckForHeader(unsigned char const *);
int /*<<< orphan*/ DoDecode(unsigned char const *, unsigned short);
unsigned short ReadShort(unsigned char const **);
int /*<<< orphan*/ printf(char *, unsigned short);
void DecodeAnimation(const unsigned char *data, unsigned short offset) {
  const unsigned char *p;
  p = data + offset;
  if (CheckForHeader(p)) {
    int i;
    unsigned short number;
    p += 4;
    number = ReadShort(&p);
    printf("number: %hu\n", number);
    if (number < 16) {
      number = 16;
    }
    for (i = 0; i < number; ++i) {
      printf("%04hX\n", ReadShort(&p));
    }
  } else {
    DoDecode(data, offset);
  }
}


x86 assembly (clang, -O0):
<DecodeAnimation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    -0x8(%rbp),%rax
movzwl -0xa(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <CheckForHeader@plt>
cmp    $0x0,%rax
je     11f5 <DecodeAnimation+0xb5>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <ReadShort@plt>
mov    %ax,-0x1e(%rbp)
lea    0xe68(%rip),%rdi
movzwl -0x1e(%rbp),%esi
call   1030 <printf@plt>
movzwl -0x1e(%rbp),%eax
cmp    $0x10,%eax
jge    11b4 <DecodeAnimation+0x74>
movw   $0x10,-0x1e(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
movzwl -0x1e(%rbp),%ecx
cmp    %ecx,%eax
jge    11f0 <DecodeAnimation+0xb0>
lea    -0x18(%rbp),%rdi
call   1050 <ReadShort@plt>
lea    0xe33(%rip),%rdi
movzwl %ax,%esi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bb <DecodeAnimation+0x7b>
jmp    1202 <DecodeAnimation+0xc2>
mov    -0x8(%rbp),%rdi
movzwl -0xa(%rbp),%esi
call   1040 <DoDecode@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DecodeAnimation>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%ebx
add    %rdi,%rbx
mov    %rbx,%rdi
call   1060 <CheckForHeader@plt>
test   %rax,%rax
je     11c1 <DecodeAnimation+0x81>
add    $0x4,%rbx
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1050 <ReadShort@plt>
movzwl %ax,%ebx
lea    0xe81(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
cmp    $0x11,%bx
mov    $0x10,%eax
cmovae %ebx,%eax
movzwl %ax,%ebp
lea    0xe71(%rip),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <ReadShort@plt>
movzwl %ax,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0xffffffff,%ebp
jne    11a0 <DecodeAnimation+0x60>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
movzwl %bp,%esi
mov    %r14,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <DoDecode@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"number: %hu\0A\00"
@.str.1 = [7 x i8] c"%04hX\0A\00"
define void @DecodeAnimation(i8* %0, i16 zeroext %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i16
store i8* %0, i8** %3
store i16 %1, i16* %4
%8 = load i8*, i8** %3
%9 = load i16, i16* %4
%10 = zext i16 %9 to i32
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = call i64 @CheckForHeader(i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %39
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 4
store i8* %18, i8** %5
%19 = call zeroext i16 @ReadShort(i8** %5)
store i16 %19, i16* %7
%20 = load i16, i16* %7
%21 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i16 zeroext %20)
%22 = load i16, i16* %7
%23 = zext i16 %22 to i32
%24 = icmp slt i32 %23, 16
br i1 %24, label %25, label %26
25: ; preds = %16
store i16 16, i16* %7
br label %26
26: ; preds = %25, %16
store i32 0, i32* %6
br label %27
27: ; preds = %35, %26
%28 = load i32, i32* %6
%29 = load i16, i16* %7
%30 = zext i16 %29 to i32
%31 = icmp slt i32 %28, %30
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = call zeroext i16 @ReadShort(i8** %5)
%34 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i16 zeroext %33)
br label %35
35: ; preds = %32
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %27
38: ; preds = %27
br label %43
39: ; preds = %2
%40 = load i8*, i8** %3
%41 = load i16, i16* %4
%42 = call i32 @DoDecode(i8* %40, i16 zeroext %41)
br label %43
43: ; preds = %39, %38
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"number: %hu\0A\00"
@.str.1 = [7 x i8] c"%04hX\0A\00"
define void @DecodeAnimation(i8* %0, i16 zeroext %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = zext i16 %1 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = tail call i64 @CheckForHeader(i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %6, i64 4
store i8* %10, i8** %3
%11 = call zeroext i16 @ReadShort(i8** %3)
%12 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i16 zeroext %11)
%13 = icmp ugt i16 %11, 16
%14 = select i1 %13, i16 %11, i16 16
%15 = zext i16 %14 to i32
br label %16
16: ; preds = %9, %16
%17 = phi i32 [ 0, %9 ], [ %20, %16 ]
%18 = call zeroext i16 @ReadShort(i8** %3)
%19 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i16 zeroext %18)
%20 = add nuw nsw i32 %17, 1
%21 = icmp eq i32 %20, %15
br i1 %21, label %24, label %16
22: ; preds = %2
%23 = tail call i32 @DoDecode(i8* %0, i16 zeroext %1)
br label %24
24: ; preds = %16, %22
ret void
}