#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 */
scalar_t__ ends_with(char *, char *);
int /*<<< orphan*/ free(char *);
char *pkg_name_from_fname(int /*<<< orphan*/ *, char *);
scalar_t__ starts_with(char *, char *);
char *trim_any_str(char *, char *);
char *trim_str(char *);
char *import_from_line(char *line) {
  char *trimmed;
  char *file_name;
  char *pkg_name;
  if (starts_with(line, "#include ")) {
    trimmed = trim_str(&line[8]);
    if (starts_with(trimmed, "\"") && ends_with(trimmed, "\"")) {
      file_name = trim_any_str(trimmed, "\"");
      pkg_name = pkg_name_from_fname(NULL, file_name);
      free(file_name);
      free(trimmed);
      return pkg_name;
    }
    free(trimmed);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<import_from_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1070 <starts_with@plt>
cmp    $0x0,%rax
je     1218 <import_from_line+0xb8>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1050 <trim_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1070 <starts_with@plt>
cmp    $0x0,%rax
je     120f <import_from_line+0xaf>
mov    -0x18(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <ends_with@plt>
cmp    $0x0,%rax
je     120f <import_from_line+0xaf>
mov    -0x18(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1040 <trim_any_str@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <pkg_name_from_fname@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1220 <import_from_line+0xc0>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<import_from_line>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xe91(%rip),%rsi
call   1070 <starts_with@plt>
test   %rax,%rax
je     11d9 <import_from_line+0x79>
add    $0x8,%rbx
mov    %rbx,%rdi
call   1050 <trim_str@plt>
mov    %rax,%r14
lea    0xe7b(%rip),%rsi
mov    %rax,%rdi
call   1070 <starts_with@plt>
test   %rax,%rax
je     11dd <import_from_line+0x7d>
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
call   1060 <ends_with@plt>
test   %rax,%rax
je     11dd <import_from_line+0x7d>
lea    0xe53(%rip),%rsi
mov    %r14,%rdi
call   1040 <trim_any_str@plt>
mov    %rax,%r15
xor    %edi,%edi
mov    %rax,%rsi
call   1080 <pkg_name_from_fname@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11df <import_from_line+0x7f>
xor    %ebx,%ebx
jmp    11e7 <import_from_line+0x87>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"#include \00"
@.str.1 = [2 x i8] c"\22\00"
define i8* @import_from_line(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @starts_with(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %34
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 8
%13 = call i8* @trim_str(i8* %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i64 @starts_with(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %10
%18 = load i8*, i8** %4
%19 = call i64 @ends_with(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = call i8* @trim_any_str(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = call i8* @pkg_name_from_fname(i32* null, i8* %24)
store i8* %25, i8** %6
%26 = load i8*, i8** %5
%27 = call i32 @free(i8* %26)
%28 = load i8*, i8** %4
%29 = call i32 @free(i8* %28)
%30 = load i8*, i8** %6
store i8* %30, i8** %2
br label %35
31: ; preds = %17, %10
%32 = load i8*, i8** %4
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %31, %1
store i8* null, i8** %2
br label %35
35: ; preds = %34, %21
%36 = load i8*, i8** %2
ret i8* %36
}

LLVM IR (-O2):
@.str = [10 x i8] c"#include \00"
@.str.1 = [2 x i8] c"\22\00"
define i8* @import_from_line(i8* %0) {
%2 = tail call i64 @starts_with(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 8
%6 = tail call i8* @trim_str(i8* %5)
%7 = tail call i64 @starts_with(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = tail call i64 @ends_with(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = tail call i8* @trim_any_str(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i8* @pkg_name_from_fname(i32* null, i8* %13)
%15 = tail call i32 @free(i8* %13)
br label %16
16: ; preds = %4, %9, %12
%17 = phi i8* [ %14, %12 ], [ null, %9 ], [ null, %4 ]
%18 = tail call i32 @free(i8* %6)
br label %19
19: ; preds = %16, %1
%20 = phi i8* [ null, %1 ], [ %17, %16 ]
ret i8* %20
}