int header_type(const char *header, char **split) {
  if (*split = strstr(header, "\r\n\r\n")) {
    return 0;
  } else if (*split = strstr(header, "\n\n")) {
    return 1;
  } else if (strrchr(header, '\n') == (strrchr(header, '\r') + 1)) {
    *split = strrchr(header, '\r');
    return 0;
  } else if (*split = strrchr(header, '\n')) {
    io_debug("%s:%s():%d:  ",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/pete/freenote-probe/refs/heads/master/"
             "src/header-parse.c",
             __func__, 213);
    io_debug("Possibly bad header.\n");
    return 1;
  } else {
    io_debug("%s:%s():%d:  ",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/pete/freenote-probe/refs/heads/master/"
             "src/header-parse.c",
             __func__, 216);
    io_debug("This header can't be right.\n");
    return -1;
  }
}


x86 assembly (clang, -O0):
<header_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <strstr@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
je     116d <header_type+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    1282 <header_type+0x152>
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1050 <strstr@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
je     119a <header_type+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    1282 <header_type+0x152>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xd,%esi
call   1030 <strrchr@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11f2 <header_type+0xc2>
mov    -0x10(%rbp),%rdi
mov    $0xd,%esi
call   1030 <strrchr@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1282 <header_type+0x152>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strrchr@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
je     124c <header_type+0x11c>
lea    0xdf0(%rip),%rdi
lea    0xdf7(%rip),%rsi
lea    0xe83(%rip),%rdx
mov    $0xd5,%ecx
mov    $0x0,%al
call   1040 <io_debug@plt>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <io_debug@plt>
movl   $0x1,-0x4(%rbp)
jmp    1282 <header_type+0x152>
lea    0xdb5(%rip),%rdi
lea    0xdbc(%rip),%rsi
lea    0xe48(%rip),%rdx
mov    $0xd8,%ecx
mov    $0x0,%al
call   1040 <io_debug@plt>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <io_debug@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<header_type>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xebc(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,(%rbx)
xor    %r14d,%r14d
test   %rax,%rax
jne    1171 <header_type+0x41>
lea    0xeaa(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strstr@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     117f <header_type+0x4f>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
mov    $0xa,%esi
call   1030 <strrchr@plt>
mov    %rax,%r15
mov    %rbp,%rdi
mov    $0xd,%esi
call   1030 <strrchr@plt>
lea    0x1(%rax),%rcx
cmp    %rcx,%r15
je     11de <header_type+0xae>
mov    %r15,(%rbx)
lea    0xe59(%rip),%rdi
lea    0xe60(%rip),%rsi
lea    0xeec(%rip),%rdx
test   %r15,%r15
je     11e3 <header_type+0xb3>
mov    $0xd5,%ecx
xor    %eax,%eax
call   1040 <io_debug@plt>
lea    0xee0(%rip),%rdi
xor    %eax,%eax
call   1040 <io_debug@plt>
jmp    116b <header_type+0x3b>
mov    %rax,(%rbx)
jmp    1171 <header_type+0x41>
mov    $0xd8,%ecx
xor    %eax,%eax
call   1040 <io_debug@plt>
lea    0xed5(%rip),%rdi
xor    %eax,%eax
call   1040 <io_debug@plt>
mov    $0xffffffff,%r14d
jmp    1171 <header_type+0x41>

LLVM IR (-O0):
@.str = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.1 = [3 x i8] c"\0A\0A\00"
@.str.2 = [14 x i8] c"%s:%s():%d: \00"
@.str.3 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pete/freenote-probe/refs/heads/master/src/header-parse.c\00"
@__func__.header_type = [12 x i8] c"header_type\00"
@.str.4 = [22 x i8] c"Possibly bad header.\0A\00"
@.str.5 = [29 x i8] c"This header can't be right.\0A\00"
define i32 @header_type(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
store i8* %0, i8** %4
store i8** %1, i8*** %5
%6 = load i8*, i8** %4
%7 = call i8* @strstr(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = load i8**, i8*** %5
store i8* %7, i8** %8
%9 = icmp ne i8* %7, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %39
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i8* @strstr(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8**, i8*** %5
store i8* %13, i8** %14
%15 = icmp ne i8* %13, null
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 1, i32* %3
br label %39
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = call i8* @strrchr(i8* %18, i32 10)
%20 = load i8*, i8** %4
%21 = call i8* @strrchr(i8* %20, i32 13)
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = icmp eq i8* %19, %22
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i8*, i8** %4
%26 = call i8* @strrchr(i8* %25, i32 13)
%27 = load i8**, i8*** %5
store i8* %26, i8** %27
store i32 0, i32* %3
br label %39
28: ; preds = %17
%29 = load i8*, i8** %4
%30 = call i8* @strrchr(i8* %29, i32 10)
%31 = load i8**, i8*** %5
store i8* %30, i8** %31
%32 = icmp ne i8* %30, null
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @io_debug to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.header_type, i64 0, i64 0), i32 213)
%35 = call i32 (i8*, ...) bitcast (i32 (...)* @io_debug to i32 (i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %39
36: ; preds = %28
%37 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @io_debug to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.header_type, i64 0, i64 0), i32 216)
%38 = call i32 (i8*, ...) bitcast (i32 (...)* @io_debug to i32 (i8*, ...)*)(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
39: ; preds = %36, %33, %24, %16, %10
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.1 = [3 x i8] c"\0A\0A\00"
@.str.2 = [14 x i8] c"%s:%s():%d: \00"
@.str.3 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pete/freenote-probe/refs/heads/master/src/header-parse.c\00"
@__func__.header_type = [12 x i8] c"header_type\00"
@.str.4 = [22 x i8] c"Possibly bad header.\0A\00"
@.str.5 = [29 x i8] c"This header can't be right.\0A\00"
define i32 @header_type(i8* %0, i8** nocapture writeonly %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %22
5: ; preds = %2
%6 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %6, i8** %1
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i32 10)
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i32 13)
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = icmp eq i8* %9, %11
br i1 %12, label %13, label %14
13: ; preds = %8
store i8* %10, i8** %1
br label %22
14: ; preds = %8
store i8* %9, i8** %1
%15 = icmp eq i8* %9, null
br i1 %15, label %19, label %16
16: ; preds = %14
%17 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @io_debug to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.header_type, i64 0, i64 0), i32 213)
%18 = tail call i32 (i8*, ...) bitcast (i32 (...)* @io_debug to i32 (i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %22
19: ; preds = %14
%20 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @io_debug to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.header_type, i64 0, i64 0), i32 216)
%21 = tail call i32 (i8*, ...) bitcast (i32 (...)* @io_debug to i32 (i8*, ...)*)(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %22
22: ; preds = %5, %2, %19, %16, %13
%23 = phi i32 [ 0, %13 ], [ 1, %16 ], [ -1, %19 ], [ 0, %2 ], [ 1, %5 ]
ret i32 %23
}