#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*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
unsigned int init_keypack(unsigned char *key_p, unsigned char *key,
                          unsigned int keySizeInBytes) {
  memset(key_p, 0, 400 + 2);
  unsigned int result = keySizeInBytes + 2;
  unsigned char pad = 0x01;
  unsigned char keypack_sizeInBytes = (keySizeInBytes + 2);
  key_p[0] = keypack_sizeInBytes;
  memcpy((unsigned char *)key_p + 1, key, keySizeInBytes);
  memcpy((unsigned char *)key_p + (1 + keySizeInBytes), &pad, 1);
  return result;
}


x86 assembly (clang, -O0):
<init_keypack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x192,%edx
call   1030 <memset@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
movb   $0x1,-0x19(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
add    %rax,%rdi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_keypack>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %esi,%esi
mov    $0x192,%edx
call   1030 <memset@plt>
lea    0x2(%rbx),%ebp
movb   $0x1,0x7(%rsp)
mov    %bpl,(%r15)
lea    0x1(%r15),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
add    $0x1,%ebx
add    %r15,%rbx
lea    0x7(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1040 <memcpy@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @init_keypack(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%11 = call i32 @memset(i8* %10, i32 0, i32 402)
%12 = load i32, i32* %6
%13 = add i32 %12, 2
store i32 %13, i32* %7
store i8 1, i8* %8
%14 = load i32, i32* %6
%15 = add i32 %14, 2
%16 = trunc i32 %15 to i8
store i8 %16, i8* %9
%17 = load i8, i8* %9
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 %17, i8* %19
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = call i32 @memcpy(i8* %21, i8* %22, i32 %23)
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = add i32 1, %26
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = call i32 @memcpy(i8* %29, i8* %8, i32 1)
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
define i32 @init_keypack(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8
%5 = tail call i32 @memset(i8* %0, i32 0, i32 402)
%6 = add i32 %2, 2
store i8 1, i8* %4
%7 = trunc i32 %6 to i8
store i8 %7, i8* %0
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = tail call i32 @memcpy(i8* %8, i8* %1, i32 %2)
%10 = add i32 %2, 1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = call i32 @memcpy(i8* %12, i8* %4, i32 1)
ret i32 %6
}