#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*/ EXIT_FAILURE;
int atoi(char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
char *strchr(char *, char const);
size_t strlen(char const *);
char *strstr(char const *, char const *);
int /*<<< orphan*/ write_error_var(char *, size_t, char const *);
int extract_number_from_line(char *line, const char *start_string,
                             const char end_char) {
  if (!(line = strstr((const char *)line, start_string))) {
    size_t size =
        strlen("Reached premature end of file while searching for %s.") +
        strlen(start_string) + 1;
    write_error_var("Reached premature end of file while searching for %s.",
                    size, start_string);
    exit(EXIT_FAILURE);
  }
  char *start = strstr(line, start_string) + strlen(start_string);
  char *end = strchr(start, end_char);
  char number_string[end - start + 1];
  memcpy(number_string, start, (size_t)end - (size_t)start);
  number_string[end - start] = '\0';
  return atoi((const char *)number_string);
}


x86 assembly (clang, -O0):
<extract_number_from_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11d7 <extract_number_from_line+0x67>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x35,%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe3c(%rip),%rdi
call   1040 <write_error_var@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rax,%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rsp,%rdx
mov    %rdx,-0x38(%rbp)
add    $0x10,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rax
sub    %rax,%rdx
call   1060 <memcpy@plt>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,(%rdi,%rax,1)
call   1070 <atoi@plt>
mov    -0x38(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_number_from_line>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
call   1090 <strstr@plt>
test   %rax,%rax
je     11ef <extract_number_from_line+0x7f>
mov    %rax,%rdi
mov    %r15,%rsi
call   1090 <strstr@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1030 <strlen@plt>
add    %rax,%r12
movsbl %r14b,%esi
mov    %r12,%rdi
call   1050 <strchr@plt>
mov    %rax,%r14
sub    %r12,%r14
lea    0x10(%r14),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1060 <memcpy@plt>
movb   $0x0,(%r14,%rbx,1)
mov    %rbx,%rdi
call   1070 <atoi@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    0x36(%rax),%rsi
lea    0xdfe(%rip),%rdi
mov    %r15,%rdx
call   1040 <write_error_var@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"Reached premature end of file while searching for %s.\00"
@EXIT_FAILURE = global i32 0
define i32 @extract_number_from_line(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i8* @strstr(i8* %12, i8* %13)
store i8* %14, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %26, label %16
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
%19 = add i64 53, %18
%20 = add i64 %19, 1
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = load i8*, i8** %5
%23 = call i32 @write_error_var(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i64 %21, i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %3
%27 = load i8*, i8** %4
%28 = load i8*, i8** %5
%29 = call i8* @strstr(i8* %27, i8* %28)
%30 = load i8*, i8** %5
%31 = call i64 @strlen(i8* %30)
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = load i8, i8* %6
%35 = call i8* @strchr(i8* %33, i8 signext %34)
store i8* %35, i8** %9
%36 = load i8*, i8** %9
%37 = load i8*, i8** %8
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = add nsw i64 %40, 1
%42 = call i8* @llvm.stacksave()
store i8* %42, i8** %10
%43 = alloca i8, i64 %41
store i64 %41, i64* %11
%44 = load i8*, i8** %8
%45 = load i8*, i8** %9
%46 = ptrtoint i8* %45 to i64
%47 = load i8*, i8** %8
%48 = ptrtoint i8* %47 to i64
%49 = sub i64 %46, %48
%50 = call i32 @memcpy(i8* %43, i8* %44, i64 %49)
%51 = load i8*, i8** %9
%52 = load i8*, i8** %8
%53 = ptrtoint i8* %51 to i64
%54 = ptrtoint i8* %52 to i64
%55 = sub i64 %53, %54
%56 = getelementptr inbounds i8, i8* %43, i64 %55
store i8 0, i8* %56
%57 = call i32 @atoi(i8* %43)
%58 = load i8*, i8** %10
ret i32 %57
}

LLVM IR (-O2):
@.str = [54 x i8] c"Reached premature end of file while searching for %s.\00"
@EXIT_FAILURE = global i32 0
define i32 @extract_number_from_line(i8* %0, i8* %1, i8 signext %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = add i64 %7, 54
%9 = tail call i32 @write_error_var(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i64 %8, i8* %1)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %3
%13 = tail call i8* @strstr(i8* %4, i8* dereferenceable(1) %1)
%14 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = tail call i8* @strchr(i8* dereferenceable(1) %15, i8 signext %2)
%17 = ptrtoint i8* %16 to i64
%18 = ptrtoint i8* %15 to i64
%19 = sub i64 %17, %18
%20 = add nsw i64 %19, 1
%21 = alloca i8, i64 %20
%22 = call i32 @memcpy(i8* %21, i8* %15, i64 %19)
%23 = getelementptr inbounds i8, i8* %21, i64 %19
store i8 0, i8* %23
%24 = call i32 @atoi(i8* %21)
ret i32 %24
}