#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 char uint8_t;

/* Variables and functions */
char *memchr(char *, char, size_t);
int already_armored(uint8_t *in, size_t insize) {
  uint8_t *from;
  uint8_t *p;
  for (from = in;
       (p = memchr(from, '\n', insize - (size_t)(from - in))) != NULL;
       from = p + 1) {
    if (*(p - 1) != '\r') {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<already_armored>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sub    %rax,%rdx
mov    $0xa,%esi
call   1030 <memchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1189 <already_armored+0x79>
mov    -0x28(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0xd,%eax
je     1173 <already_armored+0x63>
movl   $0x0,-0x4(%rbp)
jmp    1190 <already_armored+0x80>
jmp    1178 <already_armored+0x68>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1128 <already_armored+0x18>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<already_armored>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    $0xa,%esi
mov    %rbp,%rdx
call   1030 <memchr@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     1167 <already_armored+0x57>
add    %rbp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0xd,-0x1(%rax)
jne    1164 <already_armored+0x54>
add    $0x1,%rax
mov    %rbx,%rdx
sub    %rax,%rdx
mov    %rax,%rdi
mov    $0xa,%esi
call   1030 <memchr@plt>
test   %rax,%rax
jne    1140 <already_armored+0x30>
jmp    1167 <already_armored+0x57>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @already_armored(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i8*, i8** %4
store i8* %8, i8** %6
br label %9
9: ; preds = %28, %2
%10 = load i8*, i8** %6
%11 = load i64, i64* %5
%12 = load i8*, i8** %6
%13 = load i8*, i8** %4
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = sub i64 %11, %16
%18 = call i8* @memchr(i8* %10, i8 signext 10, i64 %17)
store i8* %18, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %31
20: ; preds = %9
%21 = load i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i64 -1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 13
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 0, i32* %3
br label %32
27: ; preds = %20
br label %28
28: ; preds = %27
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** %6
br label %9
31: ; preds = %9
store i32 1, i32* %3
br label %32
32: ; preds = %31, %26
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @already_armored(i8* %0, i64 %1) {
%3 = ptrtoint i8* %0 to i64
%4 = add i64 %3, %1
%5 = tail call i8* @memchr(i8* %0, i8 signext 10, i64 %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %18, label %12
7: ; preds = %12
%8 = ptrtoint i8* %17 to i64
%9 = sub i64 %4, %8
%10 = tail call i8* @memchr(i8* %17, i8 signext 10, i64 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %18, label %12
12: ; preds = %2, %7
%13 = phi i8* [ %10, %7 ], [ %5, %2 ]
%14 = getelementptr inbounds i8, i8* %13, i64 -1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 13
%17 = getelementptr inbounds i8, i8* %13, i64 1
br i1 %16, label %7, label %18
18: ; preds = %12, %7, %2
%19 = phi i32 [ 1, %2 ], [ 1, %7 ], [ 0, %12 ]
ret i32 %19
}