#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
void dec_crft(char *data) {
  uint16_t size;
  uint16_t *cur_data;
  int num_val = 0;
  data += 0x10;
  size = *(uint16_t *)data;
  printf("size = %d (0x%x) - ", size, size);
  data += sizeof(uint16_t);
  cur_data = (uint16_t *)data;
  do {
    num_val++;
    cur_data++;
  } while (*cur_data != 0xffff);
  if (*(cur_data + 1) != 0x7fff) {
    printf("Error\n");
    exit(-1);
  }
  printf("num val = %d\n", num_val);
  return;
}


x86 assembly (clang, -O0):
<dec_crft>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0xffff,(%rax)
jne    1170 <dec_crft+0x50>
mov    -0x18(%rbp),%rax
cmpl   $0x7fff,0x4(%rax)
je     11be <dec_crft+0x9e>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    -0x1c(%rbp),%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec_crft>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x10(%rdi),%edx
lea    0xebf(%rip),%rdi
xor    %ebx,%ebx
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
nopl   0x0(%rax)
cmpl   $0xffff,0x18(%r14,%rbx,4)
lea    0x1(%rbx),%rbx
jne    1150 <dec_crft+0x20>
cmpl   $0x7fff,0x18(%r14,%rbx,4)
jne    1181 <dec_crft+0x51>
lea    0xea3(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"size = %d (0x%x) - \00"
@.str.1 = [7 x i8] c"Error\0A\00"
@.str.2 = [14 x i8] c"num val = %d\0A\00"
define void @dec_crft(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 16
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = bitcast i8* %8 to i32*
%10 = load i32, i32* %9
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = load i32, i32* %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 4
store i8* %15, i8** %2
%16 = load i8*, i8** %2
%17 = bitcast i8* %16 to i32*
store i32* %17, i32** %4
br label %18
18: ; preds = %23, %1
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
%21 = load i32*, i32** %4
%22 = getelementptr inbounds i32, i32* %21, i32 1
store i32* %22, i32** %4
br label %23
23: ; preds = %18
%24 = load i32*, i32** %4
%25 = load i32, i32* %24
%26 = icmp ne i32 %25, 65535
br i1 %26, label %18, label %27
27: ; preds = %23
%28 = load i32*, i32** %4
%29 = getelementptr inbounds i32, i32* %28, i64 1
%30 = load i32, i32* %29
%31 = icmp ne i32 %30, 32767
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %27
%36 = load i32, i32* %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %36)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"size = %d (0x%x) - \00"
@.str.2 = [14 x i8] c"num val = %d\0A\00"
@str = [6 x i8] c"Error\00"
define void @dec_crft(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 16
%3 = bitcast i8* %2 to i32*
%4 = load i32, i32* %3
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %4)
%6 = getelementptr inbounds i8, i8* %0, i64 20
%7 = bitcast i8* %6 to i32*
br label %8
8: ; preds = %8, %1
%9 = phi i32* [ %7, %1 ], [ %12, %8 ]
%10 = phi i32 [ 0, %1 ], [ %11, %8 ]
%11 = add nuw nsw i32 %10, 1
%12 = getelementptr inbounds i32, i32* %9, i64 1
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 65535
br i1 %14, label %15, label %8
15: ; preds = %8
%16 = getelementptr inbounds i32, i32* %9, i64 2
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 32767
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %15
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %11)
ret void
}