#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*/ run(char *, char *, char *, char *);
int filter(int len, unsigned char *str) {
  static int state = 0;
  static char *prefix = "\30B000000";
  int i;
  for (i = 0; i < len; ++i) {
    if (str[i] == prefix[state])
      ++state;
    else
      state = 0;
    if (!prefix[state]) {
      run("rz", "-t", "10", (char *)0);
      state = 0;
    }
  }
  return len;
}


x86 assembly (clang, -O0):
<filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c9 <filter+0xb9>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    0x2ee3(%rip),%rcx
movslq 0x2ee8(%rip),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    116c <filter+0x5c>
mov    0x2ed6(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ecd(%rip)
jmp    1176 <filter+0x66>
movl   $0x0,0x2ebe(%rip)
mov    0x2eab(%rip),%rax
movslq 0x2eb0(%rip),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11b6 <filter+0xa6>
lea    0xe74(%rip),%rdi
lea    0xe70(%rip),%rsi
lea    0xe6c(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <run@plt>
movl   $0x0,0x2e7e(%rip)
jmp    11bb <filter+0xab>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <filter+0x16>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,0x4(%rsp)
test   %edi,%edi
jle    11a8 <filter+0x98>
mov    %rsi,%rbx
mov    0x4(%rsp),%ebp
mov    0x2ef7(%rip),%r12d
xor    %r14d,%r14d
lea    0xec1(%rip),%r15
lea    0xec9(%rip),%r13
jmp    1159 <filter+0x49>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %r14,%rbp
je     11a8 <filter+0x98>
movzbl (%rbx,%r14,1),%eax
movslq %r12d,%rcx
movsbl (%rcx,%r15,1),%ecx
cmp    %ecx,%eax
je     1170 <filter+0x60>
xor    %r12d,%r12d
jmp    1174 <filter+0x64>
nop
add    $0x1,%r12d
mov    %r12d,0x2eb1(%rip)
cmp    $0x8,%r12d
jne    1150 <filter+0x40>
xor    %r12d,%r12d
lea    0xe7e(%rip),%rdi
lea    0xe7a(%rip),%rsi
mov    %r13,%rdx
xor    %ecx,%ecx
call   1030 <run@plt>
movl   $0x0,0x2e86(%rip)
jmp    1150 <filter+0x40>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@filter.state = internal global i32 0
@filter.prefix = internal global i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0)
@.str = [9 x i8] c"\18B000000\00"
@.str.1 = [3 x i8] c"rz\00"
@.str.2 = [3 x i8] c"-t\00"
@.str.3 = [3 x i8] c"10\00"
define i32 @filter(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %6
6: ; preds = %38, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %3
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %41
10: ; preds = %6
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = load i8*, i8** @filter.prefix
%18 = load i32, i32* @filter.state
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %16, %22
br i1 %23, label %24, label %27
24: ; preds = %10
%25 = load i32, i32* @filter.state
%26 = add nsw i32 %25, 1
store i32 %26, i32* @filter.state
br label %28
27: ; preds = %10
store i32 0, i32* @filter.state
br label %28
28: ; preds = %27, %24
%29 = load i8*, i8** @filter.prefix
%30 = load i32, i32* @filter.state
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = icmp ne i8 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %28
%36 = call i32 @run(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* null)
store i32 0, i32* @filter.state
br label %37
37: ; preds = %35, %28
br label %38
38: ; preds = %37
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %6
41: ; preds = %6
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@filter.state = internal unnamed_addr global i32 0
@.str = [9 x i8] c"\18B000000\00"
@.str.1 = [3 x i8] c"rz\00"
@.str.2 = [3 x i8] c"-t\00"
@.str.3 = [3 x i8] c"10\00"
define i32 @filter(i32 returned %0, i8* nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %27
4: ; preds = %2
%5 = zext i32 %0 to i64
%6 = load i32, i32* @filter.state
br label %7
7: ; preds = %4, %23
%8 = phi i32 [ %6, %4 ], [ %24, %23 ]
%9 = phi i64 [ 0, %4 ], [ %25, %23 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = sext i32 %8 to i64
%14 = getelementptr inbounds [9 x i8], [9 x i8]* @.str, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %12, %16
%18 = add nsw i32 %8, 1
%19 = select i1 %17, i32 %18, i32 0
store i32 %19, i32* @filter.state
%20 = icmp eq i32 %19, 8
br i1 %20, label %21, label %23
21: ; preds = %7
%22 = tail call i32 @run(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* null)
store i32 0, i32* @filter.state
br label %23
23: ; preds = %7, %21
%24 = phi i32 [ %19, %7 ], [ 0, %21 ]
%25 = add nuw nsw i64 %9, 1
%26 = icmp eq i64 %25, %5
br i1 %26, label %27, label %7
27: ; preds = %23, %2
ret i32 %0
}