#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 char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int make_keep_alive2_pkt1(uint8_t *buf, uint8_t cnt, uint8_t *flag,
                          uint8_t *rand, uint8_t *key) {
  int index = 0;
  *(buf + index++) = 0x07;
  *(buf + index++) = cnt;
  *(buf + index++) = 0x28;
  memcpy(buf + index, "\x00\x0b\x01", 3);
  index += 3;
  memcpy(buf + index, flag, 2);
  index += 2;
  memcpy(buf + index, rand, 2);
  index += 2;
  memset(buf + index, 0, 6);
  index += 6;
  memcpy(buf + index, key, 4);
  index += 4;
  memset(buf + index, 0, 20);
  index += 20;
  return index;
}


x86 assembly (clang, -O0):
<make_keep_alive2_pkt1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x7,(%rax,%rcx,1)
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x28,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
lea    0xe65(%rip),%rsi
mov    $0x3,%edx
call   1040 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1030 <memset@plt>
mov    -0x2c(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    -0x2c(%rbp),%eax
add    $0x14,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_keep_alive2_pkt1>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rdi,%rbx
movb   $0x7,(%rdi)
mov    %sil,0x1(%rdi)
movb   $0x28,0x2(%rdi)
add    $0x3,%rdi
lea    0xeb6(%rip),%rsi
mov    $0x3,%edx
call   1040 <memcpy@plt>
lea    0x6(%rbx),%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
lea    0x8(%rbx),%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
lea    0xa(%rbx),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1030 <memset@plt>
lea    0x10(%rbx),%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x14,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    $0x28,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\00\0B\01\00"
define i32 @make_keep_alive2_pkt1(i8* %0, i8 signext %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %6
store i8 %1, i8* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
store i32 0, i32* %11
%12 = load i8*, i8** %6
%13 = load i32, i32* %11
%14 = add nsw i32 %13, 1
store i32 %14, i32* %11
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
store i8 7, i8* %16
%17 = load i8, i8* %7
%18 = load i8*, i8** %6
%19 = load i32, i32* %11
%20 = add nsw i32 %19, 1
store i32 %20, i32* %11
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 %17, i8* %22
%23 = load i8*, i8** %6
%24 = load i32, i32* %11
%25 = add nsw i32 %24, 1
store i32 %25, i32* %11
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 40, i8* %27
%28 = load i8*, i8** %6
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = call i32 @memcpy(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 3
store i32 %34, i32* %11
%35 = load i8*, i8** %6
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8*, i8** %8
%40 = call i32 @memcpy(i8* %38, i8* %39, i32 2)
%41 = load i32, i32* %11
%42 = add nsw i32 %41, 2
store i32 %42, i32* %11
%43 = load i8*, i8** %6
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8*, i8** %9
%48 = call i32 @memcpy(i8* %46, i8* %47, i32 2)
%49 = load i32, i32* %11
%50 = add nsw i32 %49, 2
store i32 %50, i32* %11
%51 = load i8*, i8** %6
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = call i32 @memset(i8* %54, i32 0, i32 6)
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 6
store i32 %57, i32* %11
%58 = load i8*, i8** %6
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i8*, i8** %10
%63 = call i32 @memcpy(i8* %61, i8* %62, i32 4)
%64 = load i32, i32* %11
%65 = add nsw i32 %64, 4
store i32 %65, i32* %11
%66 = load i8*, i8** %6
%67 = load i32, i32* %11
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
%70 = call i32 @memset(i8* %69, i32 0, i32 20)
%71 = load i32, i32* %11
%72 = add nsw i32 %71, 20
store i32 %72, i32* %11
%73 = load i32, i32* %11
ret i32 %73
}

LLVM IR (-O2):
@.str = [4 x i8] c"\00\0B\01\00"
define i32 @make_keep_alive2_pkt1(i8* %0, i8 signext %1, i8* %2, i8* %3, i8* %4) {
store i8 7, i8* %0
%6 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %1, i8* %6
%7 = getelementptr inbounds i8, i8* %0, i64 2
store i8 40, i8* %7
%8 = getelementptr inbounds i8, i8* %0, i64 3
%9 = tail call i32 @memcpy(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%10 = getelementptr inbounds i8, i8* %0, i64 6
%11 = tail call i32 @memcpy(i8* %10, i8* %2, i32 2)
%12 = getelementptr inbounds i8, i8* %0, i64 8
%13 = tail call i32 @memcpy(i8* %12, i8* %3, i32 2)
%14 = getelementptr inbounds i8, i8* %0, i64 10
%15 = tail call i32 @memset(i8* %14, i32 0, i32 6)
%16 = getelementptr inbounds i8, i8* %0, i64 16
%17 = tail call i32 @memcpy(i8* %16, i8* %4, i32 4)
%18 = getelementptr inbounds i8, i8* %0, i64 20
%19 = tail call i32 @memset(i8* %18, i32 0, i32 20)
ret i32 40
}