#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*/ USARTPutc(int);
void putMessage(char *buf, unsigned char len) {
  unsigned char idx;
  char ch;
  USARTPutc(0x7E);
  for (idx = 0; idx < len; idx++) {
    if ((buf[idx] != 0x7E) && (buf[idx] != 0x7D)) {
      USARTPutc(buf[idx]);
      continue;
    }
    ch = buf[idx];
    ch ^= 0x20;
    USARTPutc(0x7D);
    USARTPutc(ch);
  }
  USARTPutc(0x7E);
}


x86 assembly (clang, -O0):
<putMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    $0x7e,%edi
call   1030 <USARTPutc@plt>
movb   $0x0,-0xa(%rbp)
movzbl -0xa(%rbp),%eax
movzbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jge    11b8 <putMessage+0xa8>
mov    -0x8(%rbp),%rax
movzbl -0xa(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
je     1180 <putMessage+0x70>
mov    -0x8(%rbp),%rax
movzbl -0xa(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7d,%eax
je     1180 <putMessage+0x70>
mov    -0x8(%rbp),%rax
movzbl -0xa(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <USARTPutc@plt>
jmp    11ab <putMessage+0x9b>
mov    -0x8(%rbp),%rax
movzbl -0xa(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0xb(%rbp)
movsbl -0xb(%rbp),%eax
xor    $0x20,%eax
mov    %al,-0xb(%rbp)
mov    $0x7d,%edi
call   1030 <USARTPutc@plt>
movsbl -0xb(%rbp),%edi
call   1030 <USARTPutc@plt>
mov    -0xa(%rbp),%al
add    $0x1,%al
mov    %al,-0xa(%rbp)
jmp    1130 <putMessage+0x20>
mov    $0x7e,%edi
call   1030 <USARTPutc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putMessage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x7e,%edi
call   1030 <USARTPutc@plt>
test   %ebp,%ebp
je     116e <putMessage+0x5e>
movzbl %bpl,%r15d
xor    %ebx,%ebx
jmp    1152 <putMessage+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %bpl,%edi
call   1030 <USARTPutc@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
je     116e <putMessage+0x5e>
movzbl (%r14,%rbx,1),%ebp
lea    -0x7d(%rbp),%eax
cmp    $0x1,%al
ja     1140 <putMessage+0x30>
xor    $0x20,%bpl
mov    $0x7d,%edi
call   1030 <USARTPutc@plt>
jmp    1140 <putMessage+0x30>
mov    $0x7e,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <USARTPutc@plt>

LLVM IR (-O0):
define void @putMessage(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
%7 = call i32 @USARTPutc(i32 126)
store i8 0, i8* %5
br label %8
8: ; preds = %52, %2
%9 = load i8, i8* %5
%10 = zext i8 %9 to i32
%11 = load i8, i8* %4
%12 = zext i8 %11 to i32
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %55
14: ; preds = %8
%15 = load i8*, i8** %3
%16 = load i8, i8* %5
%17 = zext i8 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 126
br i1 %21, label %22, label %38
22: ; preds = %14
%23 = load i8*, i8** %3
%24 = load i8, i8* %5
%25 = zext i8 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 125
br i1 %29, label %30, label %38
30: ; preds = %22
%31 = load i8*, i8** %3
%32 = load i8, i8* %5
%33 = zext i8 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = call i32 @USARTPutc(i32 %36)
br label %52
38: ; preds = %22, %14
%39 = load i8*, i8** %3
%40 = load i8, i8* %5
%41 = zext i8 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
store i8 %43, i8* %6
%44 = load i8, i8* %6
%45 = sext i8 %44 to i32
%46 = xor i32 %45, 32
%47 = trunc i32 %46 to i8
store i8 %47, i8* %6
%48 = call i32 @USARTPutc(i32 125)
%49 = load i8, i8* %6
%50 = sext i8 %49 to i32
%51 = call i32 @USARTPutc(i32 %50)
br label %52
52: ; preds = %38, %30
%53 = load i8, i8* %5
%54 = add i8 %53, 1
store i8 %54, i8* %5
br label %8
55: ; preds = %8
%56 = call i32 @USARTPutc(i32 126)
ret void
}

LLVM IR (-O2):
define void @putMessage(i8* nocapture %0, i8 zeroext %1) {
%3 = tail call i32 @USARTPutc(i32 126)
%4 = icmp eq i8 %1, 0
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = zext i8 %1 to i64
br label %7
7: ; preds = %5, %16
%8 = phi i64 [ 0, %5 ], [ %20, %16 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = add i8 %10, -125
%12 = icmp ult i8 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = xor i8 %10, 32
%15 = tail call i32 @USARTPutc(i32 125)
br label %16
16: ; preds = %7, %13
%17 = phi i8 [ %14, %13 ], [ %10, %7 ]
%18 = sext i8 %17 to i32
%19 = tail call i32 @USARTPutc(i32 %18)
%20 = add nuw nsw i64 %8, 1
%21 = icmp eq i64 %20, %6
br i1 %21, label %22, label %7
22: ; preds = %16, %2
%23 = tail call i32 @USARTPutc(i32 126)
ret void
}