#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 *strchr(char *, char);
char *strndup(char *, int);
char *strstr(char const *, char *);
char *get_link(char const *str) {
  char *s, *e, *pre;
  char quoch;
  if (NULL == str)
    return NULL;
  pre = strstr(str, "href=");
  if (NULL == pre)
    return NULL;
  quoch = *(pre + 5);
  s = pre + 6;
  e = strchr(s, quoch);
  if (NULL == e)
    return NULL;
  return strndup(s, e - s);
}


x86 assembly (clang, -O0):
<get_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1155 <get_link+0x25>
movq   $0x0,-0x8(%rbp)
jmp    11dc <get_link+0xac>
mov    -0x10(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    1182 <get_link+0x52>
movq   $0x0,-0x8(%rbp)
jmp    11dc <get_link+0xac>
mov    -0x28(%rbp),%rax
mov    0x5(%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
movsbl -0x29(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11c2 <get_link+0x92>
movq   $0x0,-0x8(%rbp)
jmp    11dc <get_link+0xac>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1040 <strndup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_link>:
push   %rbx
test   %rdi,%rdi
je     116c <get_link+0x3c>
lea    0xec3(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     116c <get_link+0x3c>
mov    %rax,%rbx
movsbl 0x5(%rax),%esi
add    $0x6,%rbx
mov    %rbx,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     116c <get_link+0x3c>
sub    %ebx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
pop    %rbx
jmp    1040 <strndup@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"href=\00"
define i8* @get_link(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* null, %8
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %38
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i8* @strstr(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp eq i8* null, %14
br i1 %15, label %16, label %17
16: ; preds = %11
store i8* null, i8** %2
br label %38
17: ; preds = %11
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i64 5
%20 = load i8, i8* %19
store i8 %20, i8* %7
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 6
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = load i8, i8* %7
%25 = call i8* @strchr(i8* %23, i8 signext %24)
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = icmp eq i8* null, %26
br i1 %27, label %28, label %29
28: ; preds = %17
store i8* null, i8** %2
br label %38
29: ; preds = %17
%30 = load i8*, i8** %4
%31 = load i8*, i8** %5
%32 = load i8*, i8** %4
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = trunc i64 %35 to i32
%37 = call i8* @strndup(i8* %30, i32 %36)
store i8* %37, i8** %2
br label %38
38: ; preds = %29, %28, %16, %10
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
@.str = [6 x i8] c"href=\00"
define noalias i8* @get_link(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 5
%8 = load i8, i8* %7
%9 = getelementptr inbounds i8, i8* %4, i64 6
%10 = tail call i8* @strchr(i8* %9, i8 signext %8)
%11 = icmp eq i8* %10, null
br i1 %11, label %18, label %12
12: ; preds = %6
%13 = ptrtoint i8* %10 to i64
%14 = ptrtoint i8* %9 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = tail call i8* @strndup(i8* %9, i32 %16)
br label %18
18: ; preds = %6, %3, %1, %12
%19 = phi i8* [ %17, %12 ], [ null, %1 ], [ null, %3 ], [ null, %6 ]
ret i8* %19
}