#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;
char *easy_malloc(size_t);
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 *);
char *extract_string_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 *rss_string = easy_malloc((size_t)(end - start + 1) * sizeof(char));
  memcpy(rss_string, start, (size_t)(end - start) * sizeof(char));
  rss_string[end - start] = '\0';
  return rss_string;
}


x86 assembly (clang, -O0):
<extract_string_from_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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_string_from_line+0x67>
mov    -0x10(%rbp),%rdi
call   1040 <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   1050 <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,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1060 <strchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rax
sub    %rax,%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1030 <easy_malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rax
sub    %rax,%rdx
shl    $0x0,%rdx
call   1070 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_string_from_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
call   1090 <strstr@plt>
test   %rax,%rax
je     11df <extract_string_from_line+0x6f>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1090 <strstr@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %rax,%r15
movsbl %r14b,%esi
mov    %r15,%rdi
call   1060 <strchr@plt>
mov    %rax,%rbx
sub    %r15,%rbx
lea    0x1(%rbx),%rdi
call   1030 <easy_malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <memcpy@plt>
movb   $0x0,0x0(%rbp,%rbx,1)
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x36(%rax),%rsi
lea    0xe0e(%rip),%rdi
mov    %rbx,%rdx
call   1050 <write_error_var@plt>
mov    0x2ddf(%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 i8* @extract_string_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*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i8* @strstr(i8* %11, i8* %12)
store i8* %13, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %25, label %15
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = call i64 @strlen(i8* %16)
%18 = add i64 53, %17
%19 = add i64 %18, 1
store i64 %19, i64* %7
%20 = load i64, i64* %7
%21 = load i8*, i8** %5
%22 = call i32 @write_error_var(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i64 %20, i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %3
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = call i8* @strstr(i8* %26, i8* %27)
%29 = load i8*, i8** %5
%30 = call i64 @strlen(i8* %29)
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8* %31, i8** %8
%32 = load i8*, i8** %8
%33 = load i8, i8* %6
%34 = call i8* @strchr(i8* %32, i8 signext %33)
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = load i8*, i8** %8
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = add nsw i64 %39, 1
%41 = mul i64 %40, 1
%42 = call i8* @easy_malloc(i64 %41)
store i8* %42, i8** %10
%43 = load i8*, i8** %10
%44 = load i8*, i8** %8
%45 = load i8*, i8** %9
%46 = load i8*, i8** %8
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = mul i64 %49, 1
%51 = call i32 @memcpy(i8* %43, i8* %44, i64 %50)
%52 = load i8*, i8** %10
%53 = load i8*, i8** %9
%54 = load i8*, i8** %8
%55 = ptrtoint i8* %53 to i64
%56 = ptrtoint i8* %54 to i64
%57 = sub i64 %55, %56
%58 = getelementptr inbounds i8, i8* %52, i64 %57
store i8 0, i8* %58
%59 = load i8*, i8** %10
ret i8* %59
}

LLVM IR (-O2):
@.str = [54 x i8] c"Reached premature end of file while searching for %s.\00"
@EXIT_FAILURE = global i32 0
define i8* @extract_string_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 = tail call i8* @easy_malloc(i64 %20)
%22 = tail call i32 @memcpy(i8* %21, i8* %15, i64 %19)
%23 = getelementptr inbounds i8, i8* %21, i64 %19
store i8 0, i8* %23
ret i8* %21
}