#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*/ dv_error(char *);
scalar_t__ errno;
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
long strtol(char *, char **, int /*<<< orphan*/);
long parse_header_line(char *line, char *header) {
  if (errno) {
    dv_error("");
  }
  if (strncmp(line, header, strlen(header))) {
    return -1;
  }
  char *startptr = line + strlen(header);
  if (*startptr == '\0') {
    dv_error("Failed to parse header.");
  }
  char *endptr;
  long ret = strtol(line + strlen(header), &endptr, 0);
  if (errno) {
    dv_error("Failed to parse header.");
  }
  if (*endptr != '\0' && *endptr != '\n') {
    dv_error("Failed to parse header.");
  }
  if (ret < 0) {
    dv_error("The value of header is negative.");
  }
  return ret;
}


x86 assembly (clang, -O0):
<parse_header_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e89(%rip),%rax
cmpq   $0x0,(%rax)
je     116d <parse_header_line+0x2d>
lea    0xed0(%rip),%rdi
call   1060 <dv_error@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11ac <parse_header_line+0x6c>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    127a <parse_header_line+0x13a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e9 <parse_header_line+0xa9>
lea    0xe1c(%rip),%rdi
call   1060 <dv_error@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
cltq
add    %rax,%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    0x2dc7(%rip),%rax
cmpq   $0x0,(%rax)
je     122f <parse_header_line+0xef>
lea    0xdd6(%rip),%rdi
call   1060 <dv_error@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     125b <parse_header_line+0x11b>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     125b <parse_header_line+0x11b>
lea    0xdaa(%rip),%rdi
call   1060 <dv_error@plt>
cmpq   $0x0,-0x30(%rbp)
jge    1272 <parse_header_line+0x132>
lea    0xdab(%rip),%rdi
call   1060 <dv_error@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_header_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e8b(%rip),%r12
cmpq   $0x0,(%r12)
je     1168 <parse_header_line+0x28>
lea    0xed5(%rip),%rdi
call   1060 <dv_error@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    $0xffffffffffffffff,%r15
test   %rax,%rax
jne    1201 <parse_header_line+0xc1>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x0,(%r14,%rax,1)
jne    11a6 <parse_header_line+0x66>
lea    0xe5f(%rip),%rdi
call   1060 <dv_error@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r14
mov    %rsp,%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,%r15
cmpq   $0x0,(%r12)
je     11d6 <parse_header_line+0x96>
lea    0xe2f(%rip),%rdi
call   1060 <dv_error@plt>
mov    (%rsp),%rax
mov    (%rax),%al
test   %al,%al
je     11f0 <parse_header_line+0xb0>
cmp    $0xa,%al
je     11f0 <parse_header_line+0xb0>
lea    0xe15(%rip),%rdi
call   1060 <dv_error@plt>
test   %r15,%r15
jns    1201 <parse_header_line+0xc1>
lea    0xe1c(%rip),%rdi
call   1060 <dv_error@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [24 x i8] c"Failed to parse header.\00"
@.str.2 = [33 x i8] c"The value of header is negative.\00"
define i64 @parse_header_line(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i64, i64* @errno
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @dv_error(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = call i64 @strncmp(i8* %14, i8* %15, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %13
store i64 -1, i64* %3
br label %63
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %21
%32 = call i32 @dv_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %21
%34 = load i8*, i8** %4
%35 = load i8*, i8** %5
%36 = call i32 @strlen(i8* %35)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = call i64 @strtol(i8* %38, i8** %7, i32 0)
store i64 %39, i64* %8
%40 = load i64, i64* @errno
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %33
%43 = call i32 @dv_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %42, %33
%45 = load i8*, i8** %7
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %56
49: ; preds = %44
%50 = load i8*, i8** %7
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 10
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 @dv_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %56
56: ; preds = %54, %49, %44
%57 = load i64, i64* %8
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @dv_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %61
61: ; preds = %59, %56
%62 = load i64, i64* %8
store i64 %62, i64* %3
br label %63
63: ; preds = %61, %20
%64 = load i64, i64* %3
ret i64 %64
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [24 x i8] c"Failed to parse header.\00"
@.str.2 = [33 x i8] c"The value of header is negative.\00"
define i64 @parse_header_line(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = load i64, i64* @errno
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @dv_error(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = tail call i32 @strlen(i8* %1)
%10 = tail call i64 @strncmp(i8* %0, i8* %1, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %40
12: ; preds = %8
%13 = tail call i32 @strlen(i8* %1)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @dv_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
%21 = bitcast i8** %3 to i8*
%22 = tail call i32 @strlen(i8* %1)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = call i64 @strtol(i8* %24, i8** %3, i32 0)
%26 = load i64, i64* @errno
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %20
%29 = tail call i32 @dv_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %20
%31 = load i8*, i8** %3
%32 = load i8, i8* %31
switch i8 %32, label %33 [
i8 0, label %35
i8 10, label %35
]
33: ; preds = %30
%34 = tail call i32 @dv_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %30, %30, %33
%36 = icmp slt i64 %25, 0
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = tail call i32 @dv_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %35
br label %40
40: ; preds = %8, %39
%41 = phi i64 [ %25, %39 ], [ -1, %8 ]
ret i64 %41
}