#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*/ abort_crypto_lib(char *);
int /*<<< orphan*/ free(char *);
char *malloc_wrapper(int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int /*<<< orphan*/ parse_item(char *, int);
void parse_pair_item(char *message, int size) {
  if (size <= 1 + (int)sizeof(int))
    abort_crypto_lib("Incorrect size for pair item");
  int size_f = *((int *)((void *)message + 1));
  if (size_f < 0 || size_f > size - 1 - (int)sizeof(int))
    abort_crypto_lib("Incorrect size for pair item");
  int size_s = size - 1 - (int)sizeof(int) - size_f;
  char *buffer_f = malloc_wrapper(size_f);
  memcpy(buffer_f, message + 1 + (int)sizeof(int), (unsigned int)size_f);
  char *buffer_s = malloc_wrapper(size_s);
  memcpy(buffer_s, message + 1 + (int)sizeof(int) + size_f,
         (unsigned int)size_s);
  if (size_f <= 1 || size_s <= 1)
    abort_crypto_lib("Incorrect size for pair item");
  parse_item(buffer_f, size_f);
  parse_item(buffer_s, size_s);
  free(buffer_f);
  free(buffer_s);
}


x86 assembly (clang, -O0):
<parse_pair_item>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jg     1175 <parse_pair_item+0x25>
lea    0xe90(%rip),%rdi
call   1070 <abort_crypto_lib@plt>
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     119d <parse_pair_item+0x4d>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
sub    $0x4,%ecx
cmp    %ecx,%eax
jle    11a9 <parse_pair_item+0x59>
lea    0xe5c(%rip),%rdi
call   1070 <abort_crypto_lib@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
sub    $0x4,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <malloc_wrapper@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
add    $0x4,%rsi
mov    -0x10(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x14(%rbp),%edi
call   1060 <malloc_wrapper@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
add    $0x4,%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
cmpl   $0x1,-0x10(%rbp)
jle    121b <parse_pair_item+0xcb>
cmpl   $0x1,-0x14(%rbp)
jg     1227 <parse_pair_item+0xd7>
lea    0xdde(%rip),%rdi
call   1070 <abort_crypto_lib@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <parse_item@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <parse_item@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_pair_item>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r15
cmp    $0x5,%esi
jg     116f <parse_pair_item+0x1f>
lea    0xe96(%rip),%rdi
call   1070 <abort_crypto_lib@plt>
movslq 0x1(%r15),%r14
add    $0xfffffffb,%ebx
test   %r14,%r14
js     1180 <parse_pair_item+0x30>
cmp    %r14d,%ebx
jge    118c <parse_pair_item+0x3c>
lea    0xe79(%rip),%rdi
call   1070 <abort_crypto_lib@plt>
sub    %r14d,%ebx
mov    %r14d,%edi
call   1060 <malloc_wrapper@plt>
mov    %rax,%r12
lea    0x5(%r15),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   1050 <memcpy@plt>
mov    %ebx,%edi
call   1060 <malloc_wrapper@plt>
mov    %rax,%r13
lea    (%r15,%r14,1),%rsi
add    $0x5,%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1050 <memcpy@plt>
cmp    $0x2,%r14d
jl     11d0 <parse_pair_item+0x80>
cmp    $0x1,%ebx
jg     11dc <parse_pair_item+0x8c>
lea    0xe29(%rip),%rdi
call   1070 <abort_crypto_lib@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1040 <parse_item@plt>
mov    %r13,%rdi
mov    %ebx,%esi
call   1040 <parse_item@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Incorrect size for pair item\00"
define void @parse_pair_item(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 5
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @abort_crypto_lib(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i8*, i8** %3
%15 = getelementptr i8, i8* %14, i64 1
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %13
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
%24 = sub nsw i32 %23, 4
%25 = icmp sgt i32 %21, %24
br i1 %25, label %26, label %28
26: ; preds = %20, %13
%27 = call i32 @abort_crypto_lib(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %20
%29 = load i32, i32* %4
%30 = sub nsw i32 %29, 1
%31 = sub nsw i32 %30, 4
%32 = load i32, i32* %5
%33 = sub nsw i32 %31, %32
store i32 %33, i32* %6
%34 = load i32, i32* %5
%35 = call i8* @malloc_wrapper(i32 %34)
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = getelementptr inbounds i8, i8* %38, i64 4
%40 = load i32, i32* %5
%41 = call i32 @memcpy(i8* %36, i8* %39, i32 %40)
%42 = load i32, i32* %6
%43 = call i8* @malloc_wrapper(i32 %42)
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = getelementptr inbounds i8, i8* %46, i64 4
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i32, i32* %6
%52 = call i32 @memcpy(i8* %44, i8* %50, i32 %51)
%53 = load i32, i32* %5
%54 = icmp sle i32 %53, 1
br i1 %54, label %58, label %55
55: ; preds = %28
%56 = load i32, i32* %6
%57 = icmp sle i32 %56, 1
br i1 %57, label %58, label %60
58: ; preds = %55, %28
%59 = call i32 @abort_crypto_lib(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %60
60: ; preds = %58, %55
%61 = load i8*, i8** %7
%62 = load i32, i32* %5
%63 = call i32 @parse_item(i8* %61, i32 %62)
%64 = load i8*, i8** %8
%65 = load i32, i32* %6
%66 = call i32 @parse_item(i8* %64, i32 %65)
%67 = load i8*, i8** %7
%68 = call i32 @free(i8* %67)
%69 = load i8*, i8** %8
%70 = call i32 @free(i8* %69)
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Incorrect size for pair item\00"
define void @parse_pair_item(i8* %0, i32 %1) {
%3 = icmp slt i32 %1, 6
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @abort_crypto_lib(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = getelementptr i8, i8* %0, i64 1
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
%10 = icmp slt i32 %9, 0
%11 = add nsw i32 %1, -5
%12 = icmp slt i32 %11, %9
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = tail call i32 @abort_crypto_lib(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %6, %14
%17 = sub nsw i32 %11, %9
%18 = tail call i8* @malloc_wrapper(i32 %9)
%19 = getelementptr i8, i8* %0, i64 5
%20 = tail call i32 @memcpy(i8* %18, i8* %19, i32 %9)
%21 = tail call i8* @malloc_wrapper(i32 %17)
%22 = sext i32 %9 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = tail call i32 @memcpy(i8* %21, i8* %23, i32 %17)
%25 = icmp slt i32 %9, 2
%26 = icmp slt i32 %17, 2
%27 = select i1 %25, i1 true, i1 %26
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = tail call i32 @abort_crypto_lib(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %16, %28
%31 = tail call i32 @parse_item(i8* %18, i32 %9)
%32 = tail call i32 @parse_item(i8* %21, i32 %17)
%33 = tail call i32 @free(i8* %18)
%34 = tail call i32 @free(i8* %21)
ret void
}