#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 */
char *malloc(scalar_t__);
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *skip_space(char const *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *strrchr(char const *, char);
char *include_file(const char *line, const char *source) {
  char *filename, *p;
  line = skip_space(line);
  if (*line == '(')
    return NULL;
  filename = malloc(strlen(source) + strlen(line) + 1);
  if (!filename)
    return NULL;
  p = strrchr(source, '/');
  if (p && *line != '/') {
    int len = p - source + 1;
    memcpy(filename, source, len);
    strcpy(filename + len, line);
  } else {
    strcpy(filename, line);
  }
  p = strchr(filename, '\n');
  if (p)
    *p = '\0';
  return filename;
}


x86 assembly (clang, -O0):
<include_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <skip_space@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    11aa <include_file+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    128d <include_file+0x11d>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ec <include_file+0x7c>
movq   $0x0,-0x8(%rbp)
jmp    128d <include_file+0x11d>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1254 <include_file+0xe4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1254 <include_file+0xe4>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x20(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1261 <include_file+0xf1>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1285 <include_file+0x115>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<include_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
call   1040 <skip_space@plt>
mov    (%rax),%bpl
cmp    $0x28,%bpl
je     1216 <include_file+0xa6>
mov    %rax,%r14
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     1216 <include_file+0xa6>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     11f7 <include_file+0x87>
mov    %rbx,%rdi
cmp    $0x2f,%bpl
je     11f7 <include_file+0x87>
mov    %rax,%r12
sub    %r15d,%r12d
add    $0x1,%r12d
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1080 <memcpy@plt>
movslq %r12d,%rax
mov    %rbx,%rdi
add    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1218 <include_file+0xa8>
movb   $0x0,(%rax)
jmp    1218 <include_file+0xa8>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @include_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i8* @skip_space(i8* %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 40
br i1 %14, label %15, label %16
15: ; preds = %2
store i8* null, i8** %3
br label %68
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
%19 = load i8*, i8** %4
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %18, %20
%22 = add nsw i64 %21, 1
%23 = call i8* @malloc(i64 %22)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %16
store i8* null, i8** %3
br label %68
27: ; preds = %16
%28 = load i8*, i8** %5
%29 = call i8* @strrchr(i8* %28, i8 signext 47)
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %55
32: ; preds = %27
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 47
br i1 %36, label %37, label %55
37: ; preds = %32
%38 = load i8*, i8** %7
%39 = load i8*, i8** %5
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = add nsw i64 %42, 1
%44 = trunc i64 %43 to i32
store i32 %44, i32* %8
%45 = load i8*, i8** %6
%46 = load i8*, i8** %5
%47 = load i32, i32* %8
%48 = call i32 @memcpy(i8* %45, i8* %46, i32 %47)
%49 = load i8*, i8** %6
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8*, i8** %4
%54 = call i32 @strcpy(i8* %52, i8* %53)
br label %59
55: ; preds = %32, %27
%56 = load i8*, i8** %6
%57 = load i8*, i8** %4
%58 = call i32 @strcpy(i8* %56, i8* %57)
br label %59
59: ; preds = %55, %37
%60 = load i8*, i8** %6
%61 = call i8* @strchr(i8* %60, i8 signext 10)
store i8* %61, i8** %7
%62 = load i8*, i8** %7
%63 = icmp ne i8* %62, null
br i1 %63, label %64, label %66
64: ; preds = %59
%65 = load i8*, i8** %7
store i8 0, i8* %65
br label %66
66: ; preds = %64, %59
%67 = load i8*, i8** %6
store i8* %67, i8** %3
br label %68
68: ; preds = %66, %26, %15
%69 = load i8*, i8** %3
ret i8* %69
}

LLVM IR (-O2):
define i8* @include_file(i8* %0, i8* %1) {
%3 = tail call i8* @skip_space(i8* %0)
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 40
br i1 %5, label %33, label %6
6: ; preds = %2
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = tail call i64 @strlen(i8* %3)
%9 = add i64 %7, 1
%10 = add i64 %9, %8
%11 = tail call i8* @malloc(i64 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %33, label %13
13: ; preds = %6
%14 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%15 = icmp eq i8* %14, null
%16 = icmp eq i8 %4, 47
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %27, label %18
18: ; preds = %13
%19 = ptrtoint i8* %14 to i64
%20 = ptrtoint i8* %1 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
%23 = add i32 %22, 1
%24 = tail call i32 @memcpy(i8* %11, i8* %1, i32 %23)
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %11, i64 %25
br label %27
27: ; preds = %13, %18
%28 = phi i8* [ %26, %18 ], [ %11, %13 ]
%29 = tail call i32 @strcpy(i8* %28, i8* %3)
%30 = tail call i8* @strchr(i8* %11, i8 signext 10)
%31 = icmp eq i8* %30, null
br i1 %31, label %33, label %32
32: ; preds = %27
store i8 0, i8* %30
br label %33
33: ; preds = %27, %32, %6, %2
%34 = phi i8* [ null, %2 ], [ null, %6 ], [ %11, %32 ], [ %11, %27 ]
ret i8* %34
}