#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char const *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int get_data_size(const char *buffer, int size) {
  int len;
  char head[11];
  if (size < 10)
    return -1;
  if (strncmp(buffer, "#8", 2) != 0)
    return -1;
  strncpy(head, buffer, 10);
  head[10] = 0;
  if (1 != sscanf(head + 2, "%d", &len))
    fprintf(stderr, "Error: received malformed header\n");
  else if (len != size - 10)
    fprintf(stderr, "Error: inconsistent data length in header, %i != %i\n",
            len, size - 10);
  else
    return len;
  return -1;
}


x86 assembly (clang, -O0):
<get_data_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1165 <get_data_size+0x25>
movl   $0xffffffff,-0x4(%rbp)
jmp    1236 <get_data_size+0xf6>
mov    -0x10(%rbp),%rdi
lea    0xe90(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1190 <get_data_size+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    1236 <get_data_size+0xf6>
lea    -0x23(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x19(%rbp)
lea    -0x23(%rbp),%rdi
add    $0x2,%rdi
lea    0xe4e(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     11e9 <get_data_size+0xa9>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    122f <get_data_size+0xef>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0xa,%ecx
cmp    %ecx,%eax
je     121f <get_data_size+0xdf>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
sub    $0xa,%ecx
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    122a <get_data_size+0xea>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1236 <get_data_size+0xf6>
jmp    122f <get_data_size+0xef>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_data_size>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%r14d
cmp    $0xa,%esi
jl     11e3 <get_data_size+0xa3>
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe9d(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11e3 <get_data_size+0xa3>
lea    0x5(%rsp),%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xf(%rsp)
lea    0x7(%rsp),%rdi
lea    0xe6e(%rip),%rsi
mov    %rsp,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11b1 <get_data_size+0x71>
mov    (%rsp),%edx
add    $0xfffffff6,%ebp
cmp    %ebp,%edx
jne    11ca <get_data_size+0x8a>
mov    %edx,%r14d
jmp    11e3 <get_data_size+0xa3>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11e3 <get_data_size+0xa3>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"Error: received malformed header\0A\00"
@.str.3 = [53 x i8] c"Error: inconsistent data length in header, %i != %i\0A\00"
define i32 @get_data_size(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [11 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %43
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 -1, i32* %3
br label %43
16: ; preds = %11
%17 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = call i32 @strncpy(i8* %17, i8* %18, i32 10)
%20 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 10
store i8 0, i8* %20
%21 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%24 = icmp ne i32 1, %23
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %42
28: ; preds = %16
%29 = load i32, i32* %6
%30 = load i32, i32* %5
%31 = sub nsw i32 %30, 10
%32 = icmp ne i32 %29, %31
br i1 %32, label %33, label %39
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i32, i32* %6
%36 = load i32, i32* %5
%37 = sub nsw i32 %36, 10
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %37)
br label %41
39: ; preds = %28
%40 = load i32, i32* %6
store i32 %40, i32* %3
br label %43
41: ; preds = %33
br label %42
42: ; preds = %41, %25
store i32 -1, i32* %3
br label %43
43: ; preds = %42, %39, %15, %10
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [3 x i8] c"\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"Error: received malformed header\0A\00"
@.str.3 = [53 x i8] c"Error: inconsistent data length in header, %i != %i\0A\00"
define i32 @get_data_size(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca [11 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %1, 10
br i1 %7, label %27, label %8
8: ; preds = %2
%9 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = call i32 @strncpy(i8* %6, i8* %0, i32 10)
%13 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 10
store i8 0, i8* %13
%14 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 2
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%16 = icmp eq i32 %15, 1
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %27
20: ; preds = %11
%21 = load i32, i32* %3
%22 = add nsw i32 %1, -10
%23 = icmp eq i32 %21, %22
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %22)
br label %27
27: ; preds = %17, %24, %20, %8, %2
%28 = phi i32 [ -1, %2 ], [ -1, %8 ], [ %21, %20 ], [ -1, %24 ], [ -1, %17 ]
ret i32 %28
}