#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 atoi(char const *);
int /*<<< orphan*/ chomp(char *);
int /*<<< orphan*/ copy_str(char *, size_t const, char *);
scalar_t__ is_path_absolute(char const *);
char *malloc(size_t const);
int /*<<< orphan*/ strcat(char *, char const *);
char *strchr(char const *, char);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
char *parse_file_spec(const char spec[], int *line_num) {
  char *path_buf;
  const char *colon;
  int colon_lookup_offset = 0;
  const size_t bufs_len = 2 + strlen(spec) + 1 + 1;
  path_buf = malloc(bufs_len);
  if (path_buf == NULL) {
    return NULL;
  }
  if (is_path_absolute(spec)) {
    path_buf[0] = '\0';
  } else {
    copy_str(path_buf, bufs_len, "./");
  }
  colon = strchr(spec + colon_lookup_offset, ':');
  if (colon != NULL) {
    strncat(path_buf, spec, colon - spec);
    *line_num = atoi(colon + 1);
  } else {
    strcat(path_buf, spec);
    *line_num = 1;
  }
  chomp(path_buf);
  return path_buf;
}


x86 assembly (clang, -O0):
<parse_file_spec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x2,%eax
add    $0x1,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e4 <parse_file_spec+0x54>
movq   $0x0,-0x8(%rbp)
jmp    1297 <parse_file_spec+0x107>
mov    -0x10(%rbp),%rdi
call   10b0 <is_path_absolute@plt>
cmp    $0x0,%rax
je     1203 <parse_file_spec+0x73>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    1217 <parse_file_spec+0x87>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    0xdee(%rip),%rdx
call   1060 <copy_str@plt>
mov    -0x10(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     126f <parse_file_spec+0xdf>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1050 <strncat@plt>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1286 <parse_file_spec+0xf6>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x20(%rbp),%rdi
call   1080 <chomp@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_file_spec>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r13
call   1030 <strlen@plt>
add    $0x4,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     122d <parse_file_spec+0x9d>
mov    %r13,%rdi
call   10b0 <is_path_absolute@plt>
test   %rax,%rax
je     11cd <parse_file_spec+0x3d>
movb   $0x0,(%r15)
jmp    11df <parse_file_spec+0x4f>
lea    0xe2c(%rip),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <copy_str@plt>
mov    %r13,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1212 <parse_file_spec+0x82>
mov    %rax,%rbx
mov    %ebx,%edx
sub    %r13d,%edx
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <strncat@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1090 <atoi@plt>
jmp    1222 <parse_file_spec+0x92>
mov    %r15,%rdi
mov    %r13,%rsi
call   10a0 <strcat@plt>
mov    $0x1,%eax
mov    %eax,(%r14)
mov    %r15,%rdi
call   1080 <chomp@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"./\00"
define i8* @parse_file_spec(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 4
%5 = sext i32 %4 to i64
%6 = tail call i8* @malloc(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %30, label %8
8: ; preds = %2
%9 = tail call i64 @is_path_absolute(i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %8
store i8 0, i8* %6
br label %14
12: ; preds = %8
%13 = tail call i32 @copy_str(i8* %6, i64 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %11
%15 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%16 = icmp eq i8* %15, null
br i1 %16, label %25, label %17
17: ; preds = %14
%18 = ptrtoint i8* %15 to i64
%19 = ptrtoint i8* %0 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = tail call i32 @strncat(i8* %6, i8* %0, i32 %21)
%23 = getelementptr inbounds i8, i8* %15, i64 1
%24 = tail call i32 @atoi(i8* %23)
br label %27
25: ; preds = %14
%26 = tail call i32 @strcat(i8* %6, i8* %0)
br label %27
27: ; preds = %25, %17
%28 = phi i32 [ 1, %25 ], [ %24, %17 ]
store i32 %28, i32* %1
%29 = tail call i32 @chomp(i8* %6)
br label %30
30: ; preds = %2, %27
ret i8* %6
}