#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 int u_int8_t;

/* Variables and functions */
int /*<<< orphan*/ slip_send(int, int);
void write_to_serial(int outfd, void *inbuf, int len) {
  u_int8_t *p = inbuf;
  int i, ecode;
  for (i = 0; i < len; i++) {
    switch (p[i]) {
    case 0300:
      slip_send(outfd, 0333);
      slip_send(outfd, 0334);
      break;
    case 0333:
      slip_send(outfd, 0333);
      slip_send(outfd, 0335);
      break;
    default:
      slip_send(outfd, p[i]);
      break;
    }
  }
  slip_send(outfd, 0300);
  do {
  } while (0);
}


x86 assembly (clang, -O0):
<write_to_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d2 <write_to_serial+0xc2>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x2c(%rbp)
sub    $0xc0,%eax
je     116e <write_to_serial+0x5e>
jmp    115b <write_to_serial+0x4b>
mov    -0x2c(%rbp),%eax
sub    $0xdb,%eax
je     118d <write_to_serial+0x7d>
jmp    11ac <write_to_serial+0x9c>
mov    -0x4(%rbp),%edi
mov    $0xdb,%esi
call   1030 <slip_send@plt>
mov    -0x4(%rbp),%edi
mov    $0xdc,%esi
call   1030 <slip_send@plt>
jmp    11bf <write_to_serial+0xaf>
mov    -0x4(%rbp),%edi
mov    $0xdb,%esi
call   1030 <slip_send@plt>
mov    -0x4(%rbp),%edi
mov    $0xdd,%esi
call   1030 <slip_send@plt>
jmp    11bf <write_to_serial+0xaf>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1030 <slip_send@plt>
jmp    11c4 <write_to_serial+0xb4>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1131 <write_to_serial+0x21>
mov    -0x4(%rbp),%edi
mov    $0xc0,%esi
call   1030 <slip_send@plt>
jmp    11e4 <write_to_serial+0xd4>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_serial>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r12d
test   %edx,%edx
jle    1170 <write_to_serial+0x60>
mov    %rsi,%r14
mov    %edx,%r15d
xor    %ebx,%ebx
jmp    1155 <write_to_serial+0x45>
nopl   0x0(%rax)
mov    $0xdc,%ebp
mov    %r12d,%edi
mov    $0xdb,%esi
call   1030 <slip_send@plt>
mov    %r12d,%edi
mov    %ebp,%esi
call   1030 <slip_send@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
je     1170 <write_to_serial+0x60>
mov    (%r14,%rbx,4),%ebp
cmp    $0xc0,%ebp
je     1130 <write_to_serial+0x20>
cmp    $0xdb,%ebp
jne    1142 <write_to_serial+0x32>
mov    $0xdd,%ebp
jmp    1135 <write_to_serial+0x25>
mov    %r12d,%edi
mov    $0xc0,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <slip_send@plt>

LLVM IR (-O0):
define void @write_to_serial(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
%11 = bitcast i8* %10 to i32*
store i32* %11, i32** %7
store i32 0, i32* %8
br label %12
12: ; preds = %41, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %44
16: ; preds = %12
%17 = load i32*, i32** %7
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
switch i32 %21, label %32 [
i32 192, label %22
i32 219, label %27
]
22: ; preds = %16
%23 = load i32, i32* %4
%24 = call i32 @slip_send(i32 %23, i32 219)
%25 = load i32, i32* %4
%26 = call i32 @slip_send(i32 %25, i32 220)
br label %40
27: ; preds = %16
%28 = load i32, i32* %4
%29 = call i32 @slip_send(i32 %28, i32 219)
%30 = load i32, i32* %4
%31 = call i32 @slip_send(i32 %30, i32 221)
br label %40
32: ; preds = %16
%33 = load i32, i32* %4
%34 = load i32*, i32** %7
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = call i32 @slip_send(i32 %33, i32 %38)
br label %40
40: ; preds = %32, %27, %22
br label %41
41: ; preds = %40
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %12
44: ; preds = %12
%45 = load i32, i32* %4
%46 = call i32 @slip_send(i32 %45, i32 192)
br label %47
47: ; preds = %44
br label %48
48: ; preds = %47
ret void
}

LLVM IR (-O2):
define void @write_to_serial(i32 %0, i8* nocapture %1, i32 %2) {
%4 = bitcast i8* %1 to i32*
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %21
6: ; preds = %3
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %16
%9 = phi i64 [ 0, %6 ], [ %19, %16 ]
%10 = getelementptr inbounds i32, i32* %4, i64 %9
%11 = load i32, i32* %10
switch i32 %11, label %16 [
i32 192, label %13
i32 219, label %12
]
12: ; preds = %8
br label %13
13: ; preds = %8, %12
%14 = phi i32 [ 221, %12 ], [ 220, %8 ]
%15 = tail call i32 @slip_send(i32 %0, i32 219)
br label %16
16: ; preds = %13, %8
%17 = phi i32 [ %11, %8 ], [ %14, %13 ]
%18 = tail call i32 @slip_send(i32 %0, i32 %17)
%19 = add nuw nsw i64 %9, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %21, label %8
21: ; preds = %16, %3
%22 = tail call i32 @slip_send(i32 %0, i32 192)
ret void
}