#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 */
char *str_append_char(char *, int);
char *str_concat(char *, char *);
char *message_encode(char **messages, int len) {
  char *result = "";
  if (len > 1) {
    int i = 1;
    result = str_concat(result, messages[0]);
    for (i = 1; i < len; i++) {
      char *msg = messages[i];
      result = str_append_char(result, 0xAA);
      result = str_concat(result, msg);
    }
    result =
        str_concat(str_append_char("", 0xFF), str_append_char(result, 0xFE));
  } else if (len == 1) {
    result = str_concat(str_append_char("", 0xFF),
                        str_append_char(messages[0], 0xFE));
  }
  return result;
}


x86 assembly (clang, -O0):
<message_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    11eb <message_encode+0xcb>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1040 <str_concat@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b3 <message_encode+0x93>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xaa,%esi
call   1030 <str_append_char@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <str_concat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1166 <message_encode+0x46>
lea    0xe46(%rip),%rdi
mov    $0xff,%esi
call   1030 <str_append_char@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xfe,%esi
call   1030 <str_append_char@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
call   1040 <str_concat@plt>
mov    %rax,-0x18(%rbp)
jmp    1230 <message_encode+0x110>
cmpl   $0x1,-0xc(%rbp)
jne    122b <message_encode+0x10b>
lea    0xe04(%rip),%rdi
mov    $0xff,%esi
call   1030 <str_append_char@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0xfe,%esi
call   1030 <str_append_char@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
call   1040 <str_concat@plt>
mov    %rax,-0x18(%rbp)
jmp    1230 <message_encode+0x110>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<message_encode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
cmp    $0x2,%esi
jl     118e <message_encode+0x6e>
mov    (%r14),%rsi
lea    0xec4(%rip),%rdi
call   1040 <str_concat@plt>
mov    %rax,%rbx
mov    %ebp,%r15d
mov    $0x1,%ebp
nopl   0x0(%rax)
mov    (%r14,%rbp,8),%r12
mov    %rbx,%rdi
mov    $0xaa,%esi
call   1030 <str_append_char@plt>
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <str_concat@plt>
mov    %rax,%rbx
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1150 <message_encode+0x30>
lea    0xe81(%rip),%rdi
mov    $0xff,%esi
call   1030 <str_append_char@plt>
mov    %rax,%r15
jmp    11aa <message_encode+0x8a>
cmp    $0x1,%ebp
jne    11ca <message_encode+0xaa>
lea    0xe66(%rip),%rdi
mov    $0xff,%esi
call   1030 <str_append_char@plt>
mov    %rax,%r15
mov    (%r14),%rbx
mov    %rbx,%rdi
mov    $0xfe,%esi
call   1030 <str_append_char@plt>
mov    %r15,%rdi
mov    %rax,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <str_concat@plt>
lea    0xe2f(%rip),%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @message_encode(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %39
10: ; preds = %2
store i32 1, i32* %6
%11 = load i8*, i8** %5
%12 = load i8**, i8*** %3
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i8* @str_concat(i8* %11, i8* %14)
store i8* %15, i8** %5
store i32 1, i32* %6
br label %16
16: ; preds = %31, %10
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %34
20: ; preds = %16
%21 = load i8**, i8*** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
store i8* %25, i8** %7
%26 = load i8*, i8** %5
%27 = call i8* @str_append_char(i8* %26, i32 170)
store i8* %27, i8** %5
%28 = load i8*, i8** %5
%29 = load i8*, i8** %7
%30 = call i8* @str_concat(i8* %28, i8* %29)
store i8* %30, i8** %5
br label %31
31: ; preds = %20
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %16
34: ; preds = %16
%35 = call i8* @str_append_char(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 255)
%36 = load i8*, i8** %5
%37 = call i8* @str_append_char(i8* %36, i32 254)
%38 = call i8* @str_concat(i8* %35, i8* %37)
store i8* %38, i8** %5
br label %50
39: ; preds = %2
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %49
42: ; preds = %39
%43 = call i8* @str_append_char(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 255)
%44 = load i8**, i8*** %3
%45 = getelementptr inbounds i8*, i8** %44, i64 0
%46 = load i8*, i8** %45
%47 = call i8* @str_append_char(i8* %46, i32 254)
%48 = call i8* @str_concat(i8* %43, i8* %47)
store i8* %48, i8** %5
br label %49
49: ; preds = %42, %39
br label %50
50: ; preds = %49, %34
%51 = load i8*, i8** %5
ret i8* %51
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @message_encode(i8** nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %19
4: ; preds = %2
%5 = load i8*, i8** %0
%6 = tail call i8* @str_concat(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %4, %8
%9 = phi i64 [ 1, %4 ], [ %15, %8 ]
%10 = phi i8* [ %6, %4 ], [ %14, %8 ]
%11 = getelementptr inbounds i8*, i8** %0, i64 %9
%12 = load i8*, i8** %11
%13 = tail call i8* @str_append_char(i8* %10, i32 170)
%14 = tail call i8* @str_concat(i8* %13, i8* %12)
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %17, label %8
17: ; preds = %8
%18 = tail call i8* @str_append_char(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 255)
br label %24
19: ; preds = %2
%20 = icmp eq i32 %1, 1
br i1 %20, label %21, label %29
21: ; preds = %19
%22 = tail call i8* @str_append_char(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 255)
%23 = load i8*, i8** %0
br label %24
24: ; preds = %17, %21
%25 = phi i8* [ %23, %21 ], [ %14, %17 ]
%26 = phi i8* [ %22, %21 ], [ %18, %17 ]
%27 = tail call i8* @str_append_char(i8* %25, i32 254)
%28 = tail call i8* @str_concat(i8* %26, i8* %27)
br label %29
29: ; preds = %24, %19
%30 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %19 ], [ %28, %24 ]
ret i8* %30
}