#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ assert(int);
char fgetc(int /*<<< orphan*/ *);
char *strstr(char *, char *);
int extractHeader(FILE *blackbox, char *header, int header_max_size,
                  int *header_length) {
  int i;
  char *data_str_location;
  for (i = 0; i < header_max_size - 1; i++) {
    header[i] = fgetc(blackbox);
    header[i + 1] = 0;
    assert(header[i] != EOF);
    data_str_location = strstr(header, "-- Data\n");
    if (data_str_location != NULL) {
      *header_length = (int)(data_str_location - header);
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<extractHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11fc <extractHeader+0xcc>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    0x2e4f(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11e9 <extractHeader+0xb9>
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1203 <extractHeader+0xd3>
jmp    11ee <extractHeader+0xbe>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114e <extractHeader+0x1e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extractHeader>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r12
add    $0xffffffff,%r15d
xor    %ebp,%ebp
test   %r15d,%r15d
cmovle %ebp,%r15d
mov    0x2e8c(%rip),%r14
lea    0xe9d(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %rbp,%r15
je     11b3 <extractHeader+0x83>
mov    %r12,%rdi
call   1030 <fgetc@plt>
mov    %al,(%rbx,%rbp,1)
movb   $0x0,0x1(%rbx,%rbp,1)
add    $0x1,%rbp
xor    %edi,%edi
cmp    (%r14),%al
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1170 <extractHeader+0x40>
sub    %ebx,%eax
mov    (%rsp),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
jmp    11b8 <extractHeader+0x88>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
@.str = [9 x i8] c"-- Data\0A\00"
define i32 @extractHeader(i32* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 0, i32* %10
br label %12
12: ; preds = %53, %4
%13 = load i32, i32* %10
%14 = load i32, i32* %8
%15 = sub nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %56
17: ; preds = %12
%18 = load i32*, i32** %6
%19 = call signext i8 @fgetc(i32* %18)
%20 = load i8*, i8** %7
%21 = load i32, i32* %10
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 %19, i8* %23
%24 = load i8*, i8** %7
%25 = load i32, i32* %10
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 0, i8* %28
%29 = load i8*, i8** %7
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = load i8, i8* @EOF
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %34, %36
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i8*, i8** %7
%41 = call i8* @strstr(i8* %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %41, i8** %11
%42 = load i8*, i8** %11
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %52
44: ; preds = %17
%45 = load i8*, i8** %11
%46 = load i8*, i8** %7
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = trunc i64 %49 to i32
%51 = load i32*, i32** %9
store i32 %50, i32* %51
store i32 0, i32* %5
br label %57
52: ; preds = %17
br label %53
53: ; preds = %52
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %12
56: ; preds = %12
store i32 1, i32* %5
br label %57
57: ; preds = %56, %44
%58 = load i32, i32* %5
ret i32 %58
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [9 x i8] c"-- Data\0A\00"
define i32 @extractHeader(i32* nocapture %0, i8* %1, i32 %2, i32* nocapture writeonly %3) {
%5 = add i32 %2, -1
%6 = call i32 @llvm.smax.i32(i32 %5, i32 0)
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %11, %4
%9 = phi i64 [ %14, %11 ], [ 0, %4 ]
%10 = icmp eq i64 %9, %7
br i1 %10, label %27, label %11
11: ; preds = %8
%12 = tail call signext i8 @fgetc(i32* %0)
%13 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %12, i8* %13
%14 = add nuw nsw i64 %9, 1
%15 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 0, i8* %15
%16 = load i8, i8* @EOF
%17 = icmp ne i8 %12, %16
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
%20 = tail call i8* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %8, label %22
22: ; preds = %11
%23 = ptrtoint i8* %20 to i64
%24 = ptrtoint i8* %1 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
store i32 %26, i32* %3
br label %27
27: ; preds = %8, %22
%28 = phi i32 [ 0, %22 ], [ 1, %8 ]
ret i32 %28
}