#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 */
#define DO 132
#define DONT 131
char IAC;
#define SB 130
int SE;
#define WILL 129
#define WONT 128
char *nextitem(char *current) {
  if ((*current & 0xff) != IAC) {
    return current + 1;
  }
  switch (*(current + 1) & 0xff) {
  case DO:
  case DONT:
  case WILL:
  case WONT:
    return current + 3;
  case SB: {
    register char *look = current + 2;
    for (;;) {
      if ((*look++ & 0xff) == IAC) {
        if ((*look++ & 0xff) == SE) {
          return look;
        }
      }
    }
  }
  default:
    return current + 2;
  }
}


x86 assembly (clang, -O0):
<nextitem>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xff,%eax
mov    0x2eb5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1137 <nextitem+0x37>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    120b <nextitem+0x10b>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %eax,-0x1c(%rbp)
add    $0xffffff80,%eax
sub    $0x2,%eax
jb     117c <nextitem+0x7c>
jmp    1153 <nextitem+0x53>
mov    -0x1c(%rbp),%eax
sub    $0x82,%eax
je     118d <nextitem+0x8d>
jmp    1166 <nextitem+0x66>
mov    -0x1c(%rbp),%eax
add    $0xffffff7d,%eax
sub    $0x1,%eax
ja     11ff <nextitem+0xff>
jmp    117c <nextitem+0x7c>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
jmp    120b <nextitem+0x10b>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
and    $0xff,%eax
mov    0x2e19(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11fa <nextitem+0xfa>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
and    $0xff,%eax
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%eax
jne    11f5 <nextitem+0xf5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    120b <nextitem+0x10b>
jmp    11fa <nextitem+0xfa>
jmp    1199 <nextitem+0x99>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<nextitem>:
movzbl (%rdi),%ecx
mov    0x2ec6(%rip),%rax
movsbl (%rax),%edx
lea    0x1(%rdi),%rax
cmp    %edx,%ecx
jne    112e <nextitem+0x2e>
mov    (%rax),%al
add    $0x80,%al
cmp    $0x4,%al
ja     1127 <nextitem+0x27>
cmp    $0x2,%al
je     112f <nextitem+0x2f>
add    $0x3,%rdi
jmp    112b <nextitem+0x2b>
add    $0x2,%rdi
mov    %rdi,%rax
ret
add    $0x2,%rdi
mov    0x2eae(%rip),%rax
mov    (%rax),%edx
nopl   0x0(%rax)
mov    %rdi,%rax
add    $0x1,%rdi
cmp    %cl,(%rax)
jne    1140 <nextitem+0x40>
movzbl 0x1(%rax),%esi
add    $0x2,%rax
mov    %rax,%rdi
cmp    %esi,%edx
jne    1140 <nextitem+0x40>
jmp    112e <nextitem+0x2e>

LLVM IR (-O0):
@IAC = global i8 0
@SE = global i32 0
define i8* @nextitem(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = and i32 %7, 255
%9 = load i8, i8* @IAC
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %8, %10
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8* %14, i8** %2
br label %51
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = and i32 %19, 255
switch i32 %20, label %48 [
i32 132, label %21
i32 131, label %21
i32 129, label %21
i32 128, label %21
i32 130, label %24
]
21: ; preds = %15, %15, %15, %15
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 3
store i8* %23, i8** %2
br label %51
24: ; preds = %15
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 2
store i8* %26, i8** %4
br label %27
27: ; preds = %47, %24
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
%30 = load i8, i8* %28
%31 = sext i8 %30 to i32
%32 = and i32 %31, 255
%33 = load i8, i8* @IAC
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %32, %34
br i1 %35, label %36, label %47
36: ; preds = %27
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
%39 = load i8, i8* %37
%40 = sext i8 %39 to i32
%41 = and i32 %40, 255
%42 = load i32, i32* @SE
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = load i8*, i8** %4
store i8* %45, i8** %2
br label %51
46: ; preds = %36
br label %47
47: ; preds = %46, %27
br label %27
48: ; preds = %15
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i64 2
store i8* %50, i8** %2
br label %51
51: ; preds = %48, %44, %21, %12
%52 = load i8*, i8** %2
ret i8* %52
}

LLVM IR (-O2):
@IAC = global i8 0
@SE = global i32 0
define i8* @nextitem(i8* %0) {
%2 = load i8, i8* %0
%3 = zext i8 %2 to i32
%4 = load i8, i8* @IAC
%5 = sext i8 %4 to i32
%6 = icmp eq i32 %3, %5
%7 = getelementptr inbounds i8, i8* %0, i64 1
br i1 %6, label %8, label %29
8: ; preds = %1
%9 = load i8, i8* %7
switch i8 %9, label %27 [
i8 -124, label %10
i8 -125, label %10
i8 -127, label %10
i8 -128, label %10
i8 -126, label %12
]
10: ; preds = %8, %8, %8, %8
%11 = getelementptr inbounds i8, i8* %0, i64 3
br label %29
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = load i32, i32* @SE
br label %15
15: ; preds = %25, %12
%16 = phi i8* [ %13, %12 ], [ %26, %25 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %16
%19 = icmp eq i8 %18, %2
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = getelementptr inbounds i8, i8* %16, i64 2
%22 = load i8, i8* %17
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %14, %23
br i1 %24, label %29, label %25
25: ; preds = %20, %15
%26 = phi i8* [ %21, %20 ], [ %17, %15 ]
br label %15
27: ; preds = %8
%28 = getelementptr inbounds i8, i8* %0, i64 2
br label %29
29: ; preds = %20, %1, %27, %10
%30 = phi i8* [ %28, %27 ], [ %11, %10 ], [ %7, %1 ], [ %21, %20 ]
ret i8* %30
}