#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 *);
char *findheadend(char *resp) {
  int i;
  for (i = 0; i < strlen(resp) - 1; i++) {
    if (resp[i] == '\n' && resp[i + 1] == '\r') {
      i += 3;
      return resp + i;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<findheadend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a1 <findheadend+0x91>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    118e <findheadend+0x7e>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    118e <findheadend+0x7e>
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11a9 <findheadend+0x99>
jmp    1193 <findheadend+0x83>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1123 <findheadend+0x13>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findheadend>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
xor    %r14d,%r14d
cmp    $0x2,%eax
jl     115d <findheadend+0x4d>
xor    %ebx,%ebx
jmp    1146 <findheadend+0x36>
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbx
jge    115d <findheadend+0x4d>
cmpb   $0xa,(%r15,%rbx,1)
jne    1130 <findheadend+0x20>
cmpb   $0xd,0x1(%r15,%rbx,1)
jne    1130 <findheadend+0x20>
lea    (%r15,%rbx,1),%r14
add    $0x3,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @findheadend(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %36, %1
%6 = load i32, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = sub nsw i32 %8, 1
%10 = icmp slt i32 %6, %9
br i1 %10, label %11, label %39
11: ; preds = %5
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %35
19: ; preds = %11
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 13
br i1 %27, label %28, label %35
28: ; preds = %19
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 3
store i32 %30, i32* %4
%31 = load i8*, i8** %3
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8* %34, i8** %2
br label %40
35: ; preds = %19, %11
br label %36
36: ; preds = %35
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %5
39: ; preds = %5
store i8* null, i8** %2
br label %40
40: ; preds = %39, %28
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
define i8* @findheadend(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 1
br i1 %3, label %4, label %23
4: ; preds = %1, %18
%5 = phi i64 [ %9, %18 ], [ 0, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 10
%9 = add nuw nsw i64 %5, 1
br i1 %8, label %10, label %18
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 13
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = add nuw i64 %5, 3
%16 = and i64 %15, 4294967295
%17 = getelementptr inbounds i8, i8* %0, i64 %16
br label %23
18: ; preds = %4, %10
%19 = tail call i32 @strlen(i8* %0)
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %9, %21
br i1 %22, label %4, label %23
23: ; preds = %18, %1, %14
%24 = phi i8* [ %17, %14 ], [ null, %1 ], [ null, %18 ]
ret i8* %24
}