#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 add_checksum_and_stuff(unsigned char *, int, int);
int /*<<< orphan*/ memcpy(unsigned char *, void *, int);
int create_frame(unsigned char *frame, unsigned char command_type, void *param,
                 int param_size, int max_size) {
  int min_size;
  unsigned char *auxptr;
  int size;
  auxptr = frame;
  *auxptr = 0xCF;
  auxptr++;
  min_size = (((1) + (sizeof(unsigned char)) + (sizeof(unsigned short)) + (1)) +
              param_size);
  if (min_size >= max_size) {
    return (-5);
  }
  *auxptr = command_type;
  auxptr++;
  if (param_size > 0) {
    memcpy(auxptr, param, param_size);
    auxptr += param_size;
  }
  size = add_checksum_and_stuff(
      (frame + (1)), (min_size - ((1) + (1) + (sizeof(unsigned short)))),
      max_size - ((1) + (1)));
  auxptr = (frame + size + (1));
  *auxptr = 0xDF;
  return (size + (1) + (1));
}


x86 assembly (clang, -O0):
<create_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movb   $0xcf,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
movslq -0x24(%rbp),%rax
add    $0x5,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jl     117b <create_frame+0x5b>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1201 <create_frame+0xe1>
mov    -0x11(%rbp),%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    11bb <create_frame+0x9b>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x24(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
movslq -0x2c(%rbp),%rax
sub    $0x4,%rax
mov    %eax,%esi
mov    -0x28(%rbp),%edx
sub    $0x2,%edx
call   1040 <add_checksum_and_stuff@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movb   $0xdf,(%rax)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_frame>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
movb   $0xcf,(%rdi)
lea    0x5(%rbp),%ecx
mov    $0xfffffffb,%eax
cmp    %r8d,%ecx
jge    1177 <create_frame+0x57>
mov    %r8d,%r14d
mov    %rdi,%rbx
lea    0x1(%rdi),%r15
mov    %sil,0x1(%rdi)
test   %ebp,%ebp
jle    1159 <create_frame+0x39>
lea    0x2(%rbx),%rdi
mov    %rdx,%rsi
mov    %ebp,%edx
call   1030 <memcpy@plt>
add    $0x1,%ebp
add    $0xfffffffe,%r14d
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <add_checksum_and_stuff@plt>
cltq
movb   $0xdf,0x1(%rbx,%rax,1)
add    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @create_frame(i8* %0, i8 zeroext %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
store i8* %0, i8** %7
store i8 %1, i8* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%15 = load i8*, i8** %7
store i8* %15, i8** %13
%16 = load i8*, i8** %13
store i8 -49, i8* %16
%17 = load i8*, i8** %13
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %13
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = add i64 5, %20
%22 = trunc i64 %21 to i32
store i32 %22, i32* %12
%23 = load i32, i32* %12
%24 = load i32, i32* %11
%25 = icmp sge i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %5
store i32 -5, i32* %6
br label %62
27: ; preds = %5
%28 = load i8, i8* %8
%29 = load i8*, i8** %13
store i8 %28, i8* %29
%30 = load i8*, i8** %13
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %13
%32 = load i32, i32* %10
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %27
%35 = load i8*, i8** %13
%36 = load i8*, i8** %9
%37 = load i32, i32* %10
%38 = call i32 @memcpy(i8* %35, i8* %36, i32 %37)
%39 = load i32, i32* %10
%40 = load i8*, i8** %13
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %40, i64 %41
store i8* %42, i8** %13
br label %43
43: ; preds = %34, %27
%44 = load i8*, i8** %7
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = sub i64 %47, 4
%49 = trunc i64 %48 to i32
%50 = load i32, i32* %11
%51 = sub nsw i32 %50, 2
%52 = call i32 @add_checksum_and_stuff(i8* %45, i32 %49, i32 %51)
store i32 %52, i32* %14
%53 = load i8*, i8** %7
%54 = load i32, i32* %14
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = getelementptr inbounds i8, i8* %56, i64 1
store i8* %57, i8** %13
%58 = load i8*, i8** %13
store i8 -33, i8* %58
%59 = load i32, i32* %14
%60 = add nsw i32 %59, 1
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
br label %62
62: ; preds = %43, %26
%63 = load i32, i32* %6
ret i32 %63
}

LLVM IR (-O2):
define i32 @create_frame(i8* %0, i8 zeroext %1, i8* %2, i32 %3, i32 %4) {
store i8 -49, i8* %0
%6 = add i32 %3, 5
%7 = icmp slt i32 %6, %4
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %1, i8* %9
%10 = icmp sgt i32 %3, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %0, i64 2
%13 = tail call i32 @memcpy(i8* %12, i8* %2, i32 %3)
br label %14
14: ; preds = %11, %8
%15 = add i32 %3, 1
%16 = add nsw i32 %4, -2
%17 = tail call i32 @add_checksum_and_stuff(i8* %9, i32 %15, i32 %16)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8 -33, i8* %20
%21 = add nsw i32 %17, 2
br label %22
22: ; preds = %5, %14
%23 = phi i32 [ %21, %14 ], [ -5, %5 ]
ret i32 %23
}