#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 /*<<< orphan*/ read_timestamp(char const *, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ *);
int strcspn(char const *, char *);
int strspn(char const *, char *);
char *xstrndup(char const *, int);
char *filename_from_header(const char *header) {
  int first_space = strcspn(header, " \t\n");
  int h = first_space;
  while (header[h] == ' ') {
    int i;
    i = strspn(header + h, " \t");
    if (!header[h + i])
      break;
    if (!read_timestamp(header + h + i, NULL, NULL))
      break;
    h += i + 1;
    h += strcspn(header + h, " \t\n");
  }
  if (header[h] == '\n' && h > first_space)
    h = first_space;
  return xstrndup(header, h);
}


x86 assembly (clang, -O0):
<filename_from_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <strcspn@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    120a <filename_from_header+0xca>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
lea    0xe78(%rip),%rsi
call   1040 <strspn@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11b0 <filename_from_header+0x70>
jmp    120a <filename_from_header+0xca>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1030 <read_timestamp@plt>
cmp    $0x0,%eax
jne    11dc <filename_from_header+0x9c>
jmp    120a <filename_from_header+0xca>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
lea    0xe06(%rip),%rsi
call   1050 <strcspn@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1165 <filename_from_header+0x25>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1231 <filename_from_header+0xf1>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1231 <filename_from_header+0xf1>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1060 <xstrndup@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filename_from_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
lea    0xeab(%rip),%rsi
call   1050 <strcspn@plt>
mov    %eax,%r12d
movslq %eax,%rbp
mov    0x0(%r13,%rbp,1),%al
cmp    $0x20,%al
jne    11e5 <filename_from_header+0xa5>
add    %r13,%rbp
lea    0xe91(%rip),%r14
mov    %r12d,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strspn@plt>
lea    (%rax,%rbx,1),%r15d
movslq %r15d,%rcx
cmpb   $0x0,0x0(%r13,%rcx,1)
je     11db <filename_from_header+0x9b>
cltq
add    %rax,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <read_timestamp@plt>
test   %eax,%eax
je     11db <filename_from_header+0x9b>
lea    0x1(%r15),%eax
movslq %eax,%rdi
add    %r13,%rdi
lea    0xe40(%rip),%rsi
call   1050 <strcspn@plt>
lea    (%rax,%r15,1),%ebx
add    $0x1,%ebx
movslq %ebx,%rax
lea    (%rax,%r13,1),%rbp
cmpb   $0x20,0x0(%r13,%rax,1)
je     1180 <filename_from_header+0x40>
movslq %ebx,%rax
mov    0x0(%r13,%rax,1),%al
jmp    11e8 <filename_from_header+0xa8>
mov    %r12d,%ebx
cmp    %r12d,%ebx
cmovle %ebx,%r12d
cmp    $0xa,%al
cmovne %ebx,%r12d
mov    %r13,%rdi
mov    %r12d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <xstrndup@plt>

LLVM IR (-O0):
@.str = [4 x i8] c" \09\0A\00"
@.str.1 = [3 x i8] c" \09\00"
define i8* @filename_from_header(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strcspn(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %7, i32* %3
%8 = load i32, i32* %3
store i32 %8, i32* %4
br label %9
9: ; preds = %43, %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 32
br i1 %16, label %17, label %55
17: ; preds = %9
%18 = load i8*, i8** %2
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = call i32 @strspn(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %22, i32* %5
%23 = load i8*, i8** %2
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = add nsw i32 %24, %25
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %17
br label %55
32: ; preds = %17
%33 = load i8*, i8** %2
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = call i32 @read_timestamp(i8* %39, i32* null, i32* null)
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %32
br label %55
43: ; preds = %32
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
%46 = load i32, i32* %4
%47 = add nsw i32 %46, %45
store i32 %47, i32* %4
%48 = load i8*, i8** %2
%49 = load i32, i32* %4
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = call i32 @strcspn(i8* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%53 = load i32, i32* %4
%54 = add nsw i32 %53, %52
store i32 %54, i32* %4
br label %9
55: ; preds = %42, %31, %9
%56 = load i8*, i8** %2
%57 = load i32, i32* %4
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 10
br i1 %62, label %63, label %69
63: ; preds = %55
%64 = load i32, i32* %4
%65 = load i32, i32* %3
%66 = icmp sgt i32 %64, %65
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = load i32, i32* %3
store i32 %68, i32* %4
br label %69
69: ; preds = %67, %63, %55
%70 = load i8*, i8** %2
%71 = load i32, i32* %4
%72 = call i8* @xstrndup(i8* %70, i32 %71)
ret i8* %72
}

LLVM IR (-O2):
@.str = [4 x i8] c" \09\0A\00"
@.str.1 = [3 x i8] c" \09\00"
define i8* @filename_from_header(i8* %0) {
%2 = tail call i32 @strcspn(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 32
br i1 %6, label %7, label %36
7: ; preds = %1, %21
%8 = phi i8* [ %28, %21 ], [ %4, %1 ]
%9 = phi i32 [ %26, %21 ], [ %2, %1 ]
%10 = tail call i32 @strspn(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = add nsw i32 %10, %9
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %31, label %16
16: ; preds = %7
%17 = sext i32 %10 to i64
%18 = getelementptr inbounds i8, i8* %8, i64 %17
%19 = tail call i32 @read_timestamp(i8* %18, i32* null, i32* null)
%20 = icmp eq i32 %19, 0
br i1 %20, label %31, label %21
21: ; preds = %16
%22 = add i32 %11, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = tail call i32 @strcspn(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%26 = add nsw i32 %25, %22
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 32
br i1 %30, label %7, label %31
31: ; preds = %16, %7, %21
%32 = phi i32 [ %26, %21 ], [ %9, %7 ], [ %9, %16 ]
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %0, i64 %33
%35 = load i8, i8* %34
br label %36
36: ; preds = %31, %1
%37 = phi i8 [ %35, %31 ], [ %5, %1 ]
%38 = phi i32 [ %32, %31 ], [ %2, %1 ]
%39 = icmp eq i8 %37, 10
%40 = icmp sgt i32 %38, %2
%41 = select i1 %39, i1 %40, i1 false
%42 = select i1 %41, i32 %2, i32 %38
%43 = tail call i8* @xstrndup(i8* %0, i32 %42)
ret i8* %43
}