#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 *calloc(scalar_t__, int);
int /*<<< orphan*/ strcat(char *, char const *);
char *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char const *);
scalar_t__ strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
char *get_url_from_link(char const *link) {
  char const *s;
  char *tmpstr;
  if (NULL == link)
    return NULL;
  while (' ' == *link)
    link++;
  if (0 == strncmp("http://", link, 7))
    s = link + 7;
  else if (0 == strncmp("https://", link, 8))
    s = link + 8;
  else if (0 == strncmp("ftp://", link, 6))
    s = link + 6;
  else {
    if ('/' == *link)
      return strdup(link);
    tmpstr = calloc(strlen(link) + 2, 1);
    if (NULL == tmpstr)
      return NULL;
    strcpy(tmpstr, "/");
    strcat(tmpstr, link);
    return tmpstr;
  }
  if (NULL == (s = strchr(s, '/')))
    return NULL;
  return strdup(s);
}


x86 assembly (clang, -O0):
<get_url_from_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1195 <get_url_from_link+0x25>
movq   $0x0,-0x8(%rbp)
jmp    1326 <get_url_from_link+0x1b6>
jmp    119a <get_url_from_link+0x2a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x20,%eax
cmp    %ecx,%eax
jne    11bf <get_url_from_link+0x4f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    119a <get_url_from_link+0x2a>
mov    -0x10(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11f3 <get_url_from_link+0x83>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x18(%rbp)
jmp    12ec <get_url_from_link+0x17c>
mov    -0x10(%rbp),%rsi
lea    0xe0a(%rip),%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1227 <get_url_from_link+0xb7>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    12e7 <get_url_from_link+0x177>
mov    -0x10(%rbp),%rsi
lea    0xddf(%rip),%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    125b <get_url_from_link+0xeb>
mov    -0x10(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x18(%rbp)
jmp    12e2 <get_url_from_link+0x172>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x2f,%eax
cmp    %ecx,%eax
jne    1281 <get_url_from_link+0x111>
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1326 <get_url_from_link+0x1b6>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x2,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    12b8 <get_url_from_link+0x148>
movq   $0x0,-0x8(%rbp)
jmp    1326 <get_url_from_link+0x1b6>
mov    -0x20(%rbp),%rdi
lea    0xd53(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1326 <get_url_from_link+0x1b6>
jmp    12e7 <get_url_from_link+0x177>
jmp    12ec <get_url_from_link+0x17c>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1319 <get_url_from_link+0x1a9>
movq   $0x0,-0x8(%rbp)
jmp    1326 <get_url_from_link+0x1b6>
mov    -0x18(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_url_from_link>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1260 <get_url_from_link+0xf0>
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x20,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     1190 <get_url_from_link+0x20>
lea    0xe5f(%rip),%rdi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11ef <get_url_from_link+0x7f>
lea    0xe4e(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11f6 <get_url_from_link+0x86>
lea    0xe3e(%rip),%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11fd <get_url_from_link+0x8d>
cmpb   $0x2f,(%rbx)
jne    1226 <get_url_from_link+0xb6>
mov    %rbx,%rdi
jmp    121a <get_url_from_link+0xaa>
mov    $0x7,%eax
jmp    1202 <get_url_from_link+0x92>
mov    $0x8,%eax
jmp    1202 <get_url_from_link+0x92>
mov    $0x6,%eax
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1260 <get_url_from_link+0xf0>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <strdup@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     1260 <get_url_from_link+0xf0>
mov    %rax,%r14
lea    0xdcb(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
jmp    1263 <get_url_from_link+0xf3>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@.str.1 = [9 x i8] c"https://\00"
@.str.2 = [7 x i8] c"ftp://\00"
@.str.3 = [2 x i8] c"/\00"
define i8* @get_url_from_link(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %37, label %3
3: ; preds = %1, %3
%4 = phi i8* [ %7, %3 ], [ %0, %1 ]
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 32
%7 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %6, label %3, label %8
8: ; preds = %3
%9 = tail call i64 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %4, i32 7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %30, label %11
11: ; preds = %8
%12 = tail call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %30, label %14
14: ; preds = %11
%15 = tail call i64 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 6)
%16 = icmp eq i64 %15, 0
br i1 %16, label %30, label %17
17: ; preds = %14
%18 = load i8, i8* %4
%19 = icmp eq i8 %18, 47
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i8* @strdup(i8* %4)
br label %37
22: ; preds = %17
%23 = tail call i64 @strlen(i8* %4)
%24 = add nsw i64 %23, 2
%25 = tail call i8* @calloc(i64 %24, i32 1)
%26 = icmp eq i8* %25, null
br i1 %26, label %37, label %27
27: ; preds = %22
%28 = tail call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%29 = tail call i32 @strcat(i8* %25, i8* %4)
br label %37
30: ; preds = %14, %11, %8
%31 = phi i64 [ 7, %8 ], [ 8, %11 ], [ 6, %14 ]
%32 = getelementptr inbounds i8, i8* %4, i64 %31
%33 = tail call i8* @strchr(i8* %32, i8 signext 47)
%34 = icmp eq i8* %33, null
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = tail call i8* @strdup(i8* %33)
br label %37
37: ; preds = %30, %22, %1, %35, %27, %20
%38 = phi i8* [ %36, %35 ], [ %21, %20 ], [ %25, %27 ], [ null, %1 ], [ null, %22 ], [ null, %30 ]
ret i8* %38
}