#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 strlen(char const *);
char *strstr(char const *, char *);
char *tor_memstr(char const *, int, char *);
const char *find_start_of_next_routerstatus(const char *s) {
  const char *eos, *footer, *sig;
  if ((eos = strstr(s, "\nr ")))
    ++eos;
  else
    eos = s + strlen(s);
  footer = tor_memstr(s, eos - s, "\ndirectory-footer");
  sig = tor_memstr(s, eos - s, "\ndirectory-signature");
  if (footer && sig)
    return (((footer) > (sig)) ? (sig) : (footer)) + 1;
  else if (footer)
    return footer + 1;
  else if (sig)
    return sig + 1;
  else
    return eos;
}


x86 assembly (clang, -O0):
<find_start_of_next_routerstatus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     116b <find_start_of_next_routerstatus+0x3b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    118c <find_start_of_next_routerstatus+0x5c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xe60(%rip),%rdx
call   1030 <tor_memstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    0xe51(%rip),%rdx
call   1030 <tor_memstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1218 <find_start_of_next_routerstatus+0xe8>
cmpq   $0x0,-0x28(%rbp)
je     1218 <find_start_of_next_routerstatus+0xe8>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    11ff <find_start_of_next_routerstatus+0xcf>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1207 <find_start_of_next_routerstatus+0xd7>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1258 <find_start_of_next_routerstatus+0x128>
cmpq   $0x0,-0x20(%rbp)
je     1234 <find_start_of_next_routerstatus+0x104>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1258 <find_start_of_next_routerstatus+0x128>
cmpq   $0x0,-0x28(%rbp)
je     1250 <find_start_of_next_routerstatus+0x120>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1258 <find_start_of_next_routerstatus+0x128>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_start_of_next_routerstatus>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xebf(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1154 <find_start_of_next_routerstatus+0x24>
mov    %rax,%r14
add    $0x1,%r14
jmp    1162 <find_start_of_next_routerstatus+0x32>
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%r14
add    %r15,%r14
mov    %r14d,%ebp
sub    %r15d,%ebp
lea    0xe95(%rip),%rdx
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <tor_memstr@plt>
mov    %rax,%rbx
lea    0xe93(%rip),%rdx
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <tor_memstr@plt>
test   %rbx,%rbx
je     11a4 <find_start_of_next_routerstatus+0x74>
test   %rax,%rax
je     11a4 <find_start_of_next_routerstatus+0x74>
cmp    %rax,%rbx
cmova  %rax,%rbx
add    $0x1,%rbx
jmp    11bd <find_start_of_next_routerstatus+0x8d>
test   %rbx,%rbx
je     11af <find_start_of_next_routerstatus+0x7f>
add    $0x1,%rbx
jmp    11bd <find_start_of_next_routerstatus+0x8d>
lea    0x1(%rax),%rcx
test   %rax,%rax
cmovne %rcx,%r14
mov    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\0Ar \00"
@.str.1 = [18 x i8] c"\0Adirectory-footer\00"
@.str.2 = [21 x i8] c"\0Adirectory-signature\00"
define i8* @find_start_of_next_routerstatus(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %4
br label %19
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
store i8* %18, i8** %4
br label %19
19: ; preds = %13, %10
%20 = load i8*, i8** %3
%21 = load i8*, i8** %4
%22 = load i8*, i8** %3
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = call i8* @tor_memstr(i8* %20, i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %5
%28 = load i8*, i8** %3
%29 = load i8*, i8** %4
%30 = load i8*, i8** %3
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %31, %32
%34 = trunc i64 %33 to i32
%35 = call i8* @tor_memstr(i8* %28, i32 %34, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i8* %35, i8** %6
%36 = load i8*, i8** %5
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %52
38: ; preds = %19
%39 = load i8*, i8** %6
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %52
41: ; preds = %38
%42 = load i8*, i8** %5
%43 = load i8*, i8** %6
%44 = icmp ugt i8* %42, %43
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = load i8*, i8** %6
br label %49
47: ; preds = %41
%48 = load i8*, i8** %5
br label %49
49: ; preds = %47, %45
%50 = phi i8* [ %46, %45 ], [ %48, %47 ]
%51 = getelementptr inbounds i8, i8* %50, i64 1
store i8* %51, i8** %2
br label %66
52: ; preds = %38, %19
%53 = load i8*, i8** %5
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i64 1
store i8* %57, i8** %2
br label %66
58: ; preds = %52
%59 = load i8*, i8** %6
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i8*, i8** %6
%63 = getelementptr inbounds i8, i8* %62, i64 1
store i8* %63, i8** %2
br label %66
64: ; preds = %58
%65 = load i8*, i8** %4
store i8* %65, i8** %2
br label %66
66: ; preds = %64, %61, %55, %49
%67 = load i8*, i8** %2
ret i8* %67
}

LLVM IR (-O2):
@.str = [4 x i8] c"\0Ar \00"
@.str.1 = [18 x i8] c"\0Adirectory-footer\00"
@.str.2 = [21 x i8] c"\0Adirectory-signature\00"
define i8* @find_start_of_next_routerstatus(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
br label %10
6: ; preds = %1
%7 = tail call i32 @strlen(i8* %0)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
br label %10
10: ; preds = %6, %4
%11 = phi i8* [ %5, %4 ], [ %9, %6 ]
%12 = ptrtoint i8* %11 to i64
%13 = ptrtoint i8* %0 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = tail call i8* @tor_memstr(i8* %0, i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i8* @tor_memstr(i8* %0, i32 %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp ne i8* %16, null
%19 = icmp ne i8* %17, null
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %21, label %25
21: ; preds = %10
%22 = icmp ugt i8* %16, %17
%23 = select i1 %22, i8* %17, i8* %16
%24 = getelementptr inbounds i8, i8* %23, i64 1
br label %31
25: ; preds = %10
br i1 %18, label %26, label %28
26: ; preds = %25
%27 = getelementptr inbounds i8, i8* %16, i64 1
br label %31
28: ; preds = %25
%29 = getelementptr inbounds i8, i8* %17, i64 1
%30 = select i1 %19, i8* %29, i8* %11
br label %31
31: ; preds = %28, %26, %21
%32 = phi i8* [ %24, %21 ], [ %27, %26 ], [ %30, %28 ]
ret i8* %32
}