#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*/ gen_ka2_checksum(char *, int, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int make_keep_alive2_pkt2(uint8_t *buf, uint8_t cnt, uint8_t *flag,
                          uint8_t *rand, uint8_t *key, uint8_t *host_ip) {
  int index = 0;
  *(buf + index++) = 0x07;
  *(buf + index++) = cnt;
  *(buf + index++) = 0x28;
  memcpy(buf + index, "\x00\x0b\x03", 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, 4);
  index += 4;
  int checksum_p = index;
  memset(buf + index, 0, 4);
  index += 4;
  memcpy(buf + index, host_ip, 4);
  index += 4;
  memset(buf + index, 0, 8);
  index += 8;
  gen_ka2_checksum(buf, index, buf + checksum_p);
  return index;
}


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

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

LLVM IR (-O0):
@.str = [4 x i8] c"\00\0B\03\00"
define i32 @make_keep_alive2_pkt2(i8* %0, i8 signext %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %7
store i8 %1, i8* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* %5, i8** %12
store i32 0, i32* %13
%15 = load i8*, i8** %7
%16 = load i32, i32* %13
%17 = add nsw i32 %16, 1
store i32 %17, i32* %13
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
store i8 7, i8* %19
%20 = load i8, i8* %8
%21 = load i8*, i8** %7
%22 = load i32, i32* %13
%23 = add nsw i32 %22, 1
store i32 %23, i32* %13
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 %20, i8* %25
%26 = load i8*, i8** %7
%27 = load i32, i32* %13
%28 = add nsw i32 %27, 1
store i32 %28, i32* %13
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 40, i8* %30
%31 = load i8*, i8** %7
%32 = load i32, i32* %13
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i32 @memcpy(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%36 = load i32, i32* %13
%37 = add nsw i32 %36, 3
store i32 %37, i32* %13
%38 = load i8*, i8** %7
%39 = load i32, i32* %13
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8*, i8** %9
%43 = call i32 @memcpy(i8* %41, i8* %42, i32 2)
%44 = load i32, i32* %13
%45 = add nsw i32 %44, 2
store i32 %45, i32* %13
%46 = load i8*, i8** %7
%47 = load i32, i32* %13
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8*, i8** %10
%51 = call i32 @memcpy(i8* %49, i8* %50, i32 2)
%52 = load i32, i32* %13
%53 = add nsw i32 %52, 2
store i32 %53, i32* %13
%54 = load i8*, i8** %7
%55 = load i32, i32* %13
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = call i32 @memset(i8* %57, i32 0, i32 6)
%59 = load i32, i32* %13
%60 = add nsw i32 %59, 6
store i32 %60, i32* %13
%61 = load i8*, i8** %7
%62 = load i32, i32* %13
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8*, i8** %11
%66 = call i32 @memcpy(i8* %64, i8* %65, i32 4)
%67 = load i32, i32* %13
%68 = add nsw i32 %67, 4
store i32 %68, i32* %13
%69 = load i8*, i8** %7
%70 = load i32, i32* %13
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = call i32 @memset(i8* %72, i32 0, i32 4)
%74 = load i32, i32* %13
%75 = add nsw i32 %74, 4
store i32 %75, i32* %13
%76 = load i32, i32* %13
store i32 %76, i32* %14
%77 = load i8*, i8** %7
%78 = load i32, i32* %13
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
%81 = call i32 @memset(i8* %80, i32 0, i32 4)
%82 = load i32, i32* %13
%83 = add nsw i32 %82, 4
store i32 %83, i32* %13
%84 = load i8*, i8** %7
%85 = load i32, i32* %13
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
%88 = load i8*, i8** %12
%89 = call i32 @memcpy(i8* %87, i8* %88, i32 4)
%90 = load i32, i32* %13
%91 = add nsw i32 %90, 4
store i32 %91, i32* %13
%92 = load i8*, i8** %7
%93 = load i32, i32* %13
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %92, i64 %94
%96 = call i32 @memset(i8* %95, i32 0, i32 8)
%97 = load i32, i32* %13
%98 = add nsw i32 %97, 8
store i32 %98, i32* %13
%99 = load i8*, i8** %7
%100 = load i32, i32* %13
%101 = load i8*, i8** %7
%102 = load i32, i32* %14
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %101, i64 %103
%105 = call i32 @gen_ka2_checksum(i8* %99, i32 %100, i8* %104)
%106 = load i32, i32* %13
ret i32 %106
}

LLVM IR (-O2):
@.str = [4 x i8] c"\00\0B\03\00"
define i32 @make_keep_alive2_pkt2(i8* %0, i8 signext %1, i8* %2, i8* %3, i8* %4, i8* %5) {
store i8 7, i8* %0
%7 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %1, i8* %7
%8 = getelementptr inbounds i8, i8* %0, i64 2
store i8 40, i8* %8
%9 = getelementptr inbounds i8, i8* %0, i64 3
%10 = tail call i32 @memcpy(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%11 = getelementptr inbounds i8, i8* %0, i64 6
%12 = tail call i32 @memcpy(i8* %11, i8* %2, i32 2)
%13 = getelementptr inbounds i8, i8* %0, i64 8
%14 = tail call i32 @memcpy(i8* %13, i8* %3, i32 2)
%15 = getelementptr inbounds i8, i8* %0, i64 10
%16 = tail call i32 @memset(i8* %15, i32 0, i32 6)
%17 = getelementptr inbounds i8, i8* %0, i64 16
%18 = tail call i32 @memcpy(i8* %17, i8* %4, i32 4)
%19 = getelementptr inbounds i8, i8* %0, i64 20
%20 = tail call i32 @memset(i8* %19, i32 0, i32 4)
%21 = getelementptr inbounds i8, i8* %0, i64 24
%22 = tail call i32 @memset(i8* %21, i32 0, i32 4)
%23 = getelementptr inbounds i8, i8* %0, i64 28
%24 = tail call i32 @memcpy(i8* %23, i8* %5, i32 4)
%25 = getelementptr inbounds i8, i8* %0, i64 32
%26 = tail call i32 @memset(i8* %25, i32 0, i32 8)
%27 = tail call i32 @gen_ka2_checksum(i8* %0, i32 40, i8* %21)
ret i32 40
}