#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(char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int makeCommand_canon(const char *cmd, int cmdLen, char *data) {
  int dataLen = 0;
  int length;
  char cmdHdr[] = "\x1b[K";
  char cmdSeparator[] = "\x00\x1e";
  memcpy(data, cmdHdr, (sizeof((cmdHdr)) - 1));
  dataLen = (sizeof((cmdHdr)) - 1);
  length = cmdLen + 4;
  memcpy(data + dataLen, &length, 1);
  memset(data + dataLen + 1, 0, 1);
  dataLen += 2;
  memcpy(data + dataLen, cmdSeparator, (sizeof((cmdSeparator)) - 1));
  dataLen += (sizeof((cmdSeparator)) - 1);
  length = cmdLen + 2;
  memset(data + dataLen, 0, 1);
  memcpy(data + dataLen + 1, &length, 1);
  dataLen += 2;
  memcpy(data + dataLen, cmd, cmdLen);
  dataLen += cmdLen;
  return dataLen;
}


x86 assembly (clang, -O0):
<makeCommand_canon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0xec0(%rip),%eax
mov    %eax,-0x24(%rbp)
mov    0xeba(%rip),%ax
mov    %ax,-0x27(%rbp)
mov    0xeb2(%rip),%al
mov    %al,-0x25(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rsi
xor    %eax,%eax
mov    $0x3,%edx
call   1040 <memcpy@plt>
movl   $0x3,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <memset@plt>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    -0x27(%rbp),%rsi
xor    %eax,%eax
mov    $0x2,%edx
call   1040 <memcpy@plt>
movslq -0x1c(%rbp),%rax
add    $0x2,%rax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
xor    %eax,%eax
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
xor    %eax,%eax
call   1040 <memcpy@plt>
mov    -0xc(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeCommand_canon>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%r15
movl   $0x4b5b1b,0x14(%rsp)
movb   $0x0,0xe(%rsp)
movw   $0x1e00,0xc(%rsp)
lea    0x14(%rsp),%rsi
mov    $0x3,%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <memcpy@plt>
lea    0x4(%r14),%eax
mov    %eax,0x10(%rsp)
lea    0x3(%rbx),%rdi
lea    0x10(%rsp),%r12
mov    %r12,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <memcpy@plt>
lea    0x4(%rbx),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <memset@plt>
lea    0x5(%rbx),%rdi
lea    0xc(%rsp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <memcpy@plt>
lea    0x2(%r14),%eax
mov    %eax,0x10(%rsp)
lea    0x7(%rbx),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <memset@plt>
lea    0x8(%rbx),%rdi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <memcpy@plt>
add    $0x9,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <memcpy@plt>
add    $0x9,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@__const.makeCommand_canon.cmdSeparator = [3 x i8] c"\00\1E\00"
define i32 @makeCommand_canon(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca [3 x i8]
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
store i32 4938523, i32* %5
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%10 = call i32 (i8*, ...) @memcpy(i8* %2, i32* %5, i64 3)
%11 = add nsw i32 %1, 4
store i32 %11, i32* %4
%12 = getelementptr inbounds i8, i8* %2, i64 3
%13 = call i32 (i8*, ...) @memcpy(i8* %12, i32* %4, i32 1)
%14 = getelementptr inbounds i8, i8* %2, i64 4
%15 = call i32 @memset(i8* %14, i32 0, i32 1)
%16 = getelementptr inbounds i8, i8* %2, i64 5
%17 = call i32 (i8*, ...) @memcpy(i8* %16, i8* %9, i64 2)
%18 = add nsw i32 %1, 2
store i32 %18, i32* %4
%19 = getelementptr inbounds i8, i8* %2, i64 7
%20 = call i32 @memset(i8* %19, i32 0, i32 1)
%21 = getelementptr inbounds i8, i8* %2, i64 8
%22 = call i32 (i8*, ...) @memcpy(i8* %21, i32* %4, i32 1)
%23 = getelementptr inbounds i8, i8* %2, i64 9
%24 = call i32 (i8*, ...) @memcpy(i8* %23, i8* %0, i32 %1)
%25 = add nsw i32 %1, 9
ret i32 %25
}