#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 */
char *strchr(char *, char);
int /*<<< orphan*/ warn(char *);
bool next_header(char **ptr) {
  char *p = *ptr;
  p = strchr(p, '\r');
  if (p == NULL) {
    warn("invalid request");
    return false;
  }
  *p = 0;
  p++;
  if (*p != '\n') {
    warn("invalid request");
    return false;
  }
  *p = 0;
  p++;
  *ptr = p;
  return true;
}


x86 assembly (clang, -O0):
<next_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xd,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116c <next_header+0x4c>
lea    0xea5(%rip),%rdi
call   1030 <warn@plt>
movl   $0x0,-0x4(%rbp)
jmp    11cc <next_header+0xac>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     11a7 <next_header+0x87>
lea    0xe6a(%rip),%rdi
call   1030 <warn@plt>
movl   $0x0,-0x4(%rbp)
jmp    11cc <next_header+0xac>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_header>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rdi
mov    $0xd,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1151 <next_header+0x31>
movb   $0x0,(%rax)
cmpb   $0xa,0x1(%rax)
jne    1151 <next_header+0x31>
movb   $0x0,0x1(%rax)
add    $0x2,%rax
mov    %rax,(%rbx)
mov    $0x1,%eax
pop    %rbx
ret
lea    0xea8(%rip),%rdi
call   1030 <warn@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [16 x i8] c"invalid request\00"
define i32 @next_header(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = tail call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 13)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @warn(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %15
7: ; preds = %1
store i8 0, i8* %3
%8 = getelementptr inbounds i8, i8* %3, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 10
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 @warn(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %15
13: ; preds = %7
store i8 0, i8* %8
%14 = getelementptr inbounds i8, i8* %3, i64 2
store i8* %14, i8** %0
br label %15
15: ; preds = %13, %11, %5
%16 = phi i32 [ 0, %5 ], [ 0, %11 ], [ 1, %13 ]
ret i32 %16
}