#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 */
scalar_t__ memcmp(char *, char *, int);
char *geterror(char *p, int n) {
  char *end = p + n - 7;
  for (; p < end; ++p) {
    if (memcmp(p, "5:error", 7) == 0) {
      p += 7;
      if (memcmp(p, "4:none", 6) != 0)
        return p;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<geterror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
add    $0xfffffffffffffff9,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11b2 <geterror+0xa2>
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
mov    $0x7,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    119c <geterror+0x8c>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
mov    $0x6,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     1197 <geterror+0x87>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ba <geterror+0xaa>
jmp    119c <geterror+0x8c>
jmp    11a1 <geterror+0x91>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1132 <geterror+0x22>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geterror>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movslq %esi,%rax
lea    (%rdi,%rax,1),%r12
add    $0xfffffffffffffff9,%r12
cmp    %rdi,%r12
jbe    1179 <geterror+0x69>
mov    %rdi,%rbx
lea    0xece(%rip),%r14
lea    0xecf(%rip),%r15
jmp    1149 <geterror+0x39>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %r12,%rbx
jae    1179 <geterror+0x69>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    1140 <geterror+0x30>
add    $0x7,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x6,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1140 <geterror+0x30>
jmp    117b <geterror+0x6b>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"5:error\00"
@.str.1 = [7 x i8] c"4:none\00"
define i8* @geterror(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 -7
store i8* %11, i8** %6
br label %12
12: ; preds = %30, %2
%13 = load i8*, i8** %4
%14 = load i8*, i8** %6
%15 = icmp ult i8* %13, %14
br i1 %15, label %16, label %33
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = call i64 @memcmp(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 7
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = call i64 @memcmp(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = load i8*, i8** %4
store i8* %27, i8** %3
br label %34
28: ; preds = %20
br label %29
29: ; preds = %28, %16
br label %30
30: ; preds = %29
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
br label %12
33: ; preds = %12
store i8* null, i8** %3
br label %34
34: ; preds = %33, %26
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
@.str = [8 x i8] c"5:error\00"
@.str.1 = [7 x i8] c"4:none\00"
define i8* @geterror(i8* %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -7
%6 = icmp ugt i8* %5, %0
br i1 %6, label %7, label %19
7: ; preds = %2, %15
%8 = phi i8* [ %17, %15 ], [ %0, %2 ]
%9 = tail call i64 @memcmp(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %8, i64 7
%13 = tail call i64 @memcmp(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %7, %11
%16 = phi i8* [ %12, %11 ], [ %8, %7 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = icmp ult i8* %17, %5
br i1 %18, label %7, label %19
19: ; preds = %11, %15, %2
%20 = phi i8* [ null, %2 ], [ null, %15 ], [ %12, %11 ]
ret i8* %20
}