#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strstr(char *, char *);
int extract_video_id(char *target, char *dest) {
  int i, count = 0;
  if (strstr(target, "http://"))
    count += 7;
  else if (strstr(target, "https://"))
    count += 8;
  if (strstr(target, "www."))
    count += 4;
  if (strstr(target, "youtube.com")) {
    if (!strstr(target, "watch?v=")) {
      fprintf(stderr, "Invalid url %s\n", target);
    } else {
      count += 11;
      count += 9;
    }
  } else if (strstr(target, "youtu.be")) {
    count += 9;
  } else {
    fprintf(stderr, "Invalid URL %s\n", target);
    return 1;
  }
  for (i = 0; i < 11; i++, count++)
    dest[i] = target[count];
  dest[11] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<extract_video_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xebe(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     115f <extract_video_id+0x3f>
mov    -0x20(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x20(%rbp)
jmp    1187 <extract_video_id+0x67>
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     1182 <extract_video_id+0x62>
mov    -0x20(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x20(%rbp)
jmp    1187 <extract_video_id+0x67>
mov    -0x10(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     11aa <extract_video_id+0x8a>
mov    -0x20(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     1213 <extract_video_id+0xf3>
mov    -0x10(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
jne    11fc <extract_video_id+0xdc>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe39(%rip),%rsi
call   1030 <fprintf@plt>
jmp    120e <extract_video_id+0xee>
mov    -0x20(%rbp),%eax
add    $0xb,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x9,%eax
mov    %eax,-0x20(%rbp)
jmp    1265 <extract_video_id+0x145>
mov    -0x10(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     123b <extract_video_id+0x11b>
mov    -0x20(%rbp),%eax
add    $0x9,%eax
mov    %eax,-0x20(%rbp)
jmp    1260 <extract_video_id+0x140>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf5(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b2 <extract_video_id+0x192>
jmp    1265 <extract_video_id+0x145>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xb,-0x1c(%rbp)
jge    12a3 <extract_video_id+0x183>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    126c <extract_video_id+0x14c>
mov    -0x18(%rbp),%rax
movb   $0x0,0xb(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_video_id>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xecc(%rip),%rsi
call   1040 <strstr@plt>
mov    $0x7,%ebp
test   %rax,%rax
jne    115e <extract_video_id+0x3e>
lea    0xebe(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
shl    $0x3,%ebp
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
lea    0x4(%rbp),%r15d
test   %rax,%rax
cmove  %ebp,%r15d
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     11a6 <extract_video_id+0x86>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     11c4 <extract_video_id+0xa4>
add    $0x14,%r15d
jmp    11dc <extract_video_id+0xbc>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     1247 <extract_video_id+0x127>
add    $0x9,%r15d
jmp    11dc <extract_video_id+0xbc>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    %r15d,%eax
mov    (%rbx,%rax,1),%cl
mov    %cl,(%r14)
mov    0x1(%rbx,%rax,1),%cl
mov    %cl,0x1(%r14)
mov    0x2(%rbx,%rax,1),%cl
mov    %cl,0x2(%r14)
mov    0x3(%rbx,%rax,1),%cl
mov    %cl,0x3(%r14)
mov    0x4(%rbx,%rax,1),%cl
mov    %cl,0x4(%r14)
mov    0x5(%rbx,%rax,1),%cl
mov    %cl,0x5(%r14)
mov    0x6(%rbx,%rax,1),%cl
mov    %cl,0x6(%r14)
mov    0x7(%rbx,%rax,1),%cl
mov    %cl,0x7(%r14)
mov    0x8(%rbx,%rax,1),%cl
mov    %cl,0x8(%r14)
mov    0x9(%rbx,%rax,1),%cl
mov    %cl,0x9(%r14)
mov    0xa(%rbx,%rax,1),%al
mov    %al,0xa(%r14)
movb   $0x0,0xb(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%eax
jmp    123c <extract_video_id+0x11c>

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
@.str.1 = [9 x i8] c"https://\00"
@.str.2 = [5 x i8] c"www.\00"
@.str.3 = [12 x i8] c"youtube.com\00"
@.str.4 = [9 x i8] c"watch?v=\00"
@stderr = global i32 0
@.str.5 = [16 x i8] c"Invalid url %s\0A\00"
@.str.6 = [9 x i8] c"youtu.be\00"
@.str.7 = [16 x i8] c"Invalid URL %s\0A\00"
define i32 @extract_video_id(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = call i64 @strstr(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* %7
%13 = add nsw i32 %12, 7
store i32 %13, i32* %7
br label %22
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i64 @strstr(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 8
store i32 %20, i32* %7
br label %21
21: ; preds = %18, %14
br label %22
22: ; preds = %21, %11
%23 = load i8*, i8** %4
%24 = call i64 @strstr(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 4
store i32 %28, i32* %7
br label %29
29: ; preds = %26, %22
%30 = load i8*, i8** %4
%31 = call i64 @strstr(i8* %30, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %47
33: ; preds = %29
%34 = load i8*, i8** %4
%35 = call i64 @strstr(i8* %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp ne i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %4
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %39)
br label %46
41: ; preds = %33
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 11
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 9
store i32 %45, i32* %7
br label %46
46: ; preds = %41, %37
br label %59
47: ; preds = %29
%48 = load i8*, i8** %4
%49 = call i64 @strstr(i8* %48, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 9
store i32 %53, i32* %7
br label %58
54: ; preds = %47
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %4
%57 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %56)
store i32 1, i32* %3
br label %81
58: ; preds = %51
br label %59
59: ; preds = %58, %46
store i32 0, i32* %6
br label %60
60: ; preds = %73, %59
%61 = load i32, i32* %6
%62 = icmp slt i32 %61, 11
br i1 %62, label %63, label %78
63: ; preds = %60
%64 = load i8*, i8** %4
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8, i8* %67
%69 = load i8*, i8** %5
%70 = load i32, i32* %6
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8 %68, i8* %72
br label %73
73: ; preds = %63
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
store i32 %77, i32* %7
br label %60
78: ; preds = %60
%79 = load i8*, i8** %5
%80 = getelementptr inbounds i8, i8* %79, i64 11
store i8 0, i8* %80
store i32 0, i32* %3
br label %81
81: ; preds = %78, %54
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@.str.1 = [9 x i8] c"https://\00"
@.str.2 = [5 x i8] c"www.\00"
@.str.3 = [12 x i8] c"youtube.com\00"
@.str.4 = [9 x i8] c"watch?v=\00"
@stderr = global i32 0
@.str.5 = [16 x i8] c"Invalid url %s\0A\00"
@.str.6 = [9 x i8] c"youtu.be\00"
@.str.7 = [16 x i8] c"Invalid URL %s\0A\00"
define i32 @extract_video_id(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i32 0, i32 8
br label %9
9: ; preds = %5, %2
%10 = phi i32 [ 7, %2 ], [ %8, %5 ]
%11 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = add nuw nsw i32 %10, 4
%14 = select i1 %12, i32 %10, i32 %13
%15 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %9
%18 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %33
23: ; preds = %17
%24 = add nuw nsw i32 %14, 20
br label %33
25: ; preds = %9
%26 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = add nuw nsw i32 %14, 9
br label %33
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %0)
br label %79
33: ; preds = %20, %23, %28
%34 = phi i32 [ %24, %23 ], [ %14, %20 ], [ %29, %28 ]
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = load i8, i8* %36
store i8 %37, i8* %1
%38 = add nuw nsw i64 %35, 1
%39 = getelementptr inbounds i8, i8* %0, i64 %38
%40 = load i8, i8* %39
%41 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %40, i8* %41
%42 = add nuw nsw i64 %35, 2
%43 = getelementptr inbounds i8, i8* %0, i64 %42
%44 = load i8, i8* %43
%45 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %44, i8* %45
%46 = add nuw nsw i64 %35, 3
%47 = getelementptr inbounds i8, i8* %0, i64 %46
%48 = load i8, i8* %47
%49 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %48, i8* %49
%50 = add nuw nsw i64 %35, 4
%51 = getelementptr inbounds i8, i8* %0, i64 %50
%52 = load i8, i8* %51
%53 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %52, i8* %53
%54 = add nuw nsw i64 %35, 5
%55 = getelementptr inbounds i8, i8* %0, i64 %54
%56 = load i8, i8* %55
%57 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %56, i8* %57
%58 = add nuw nsw i64 %35, 6
%59 = getelementptr inbounds i8, i8* %0, i64 %58
%60 = load i8, i8* %59
%61 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %60, i8* %61
%62 = add nuw nsw i64 %35, 7
%63 = getelementptr inbounds i8, i8* %0, i64 %62
%64 = load i8, i8* %63
%65 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %64, i8* %65
%66 = add nuw nsw i64 %35, 8
%67 = getelementptr inbounds i8, i8* %0, i64 %66
%68 = load i8, i8* %67
%69 = getelementptr inbounds i8, i8* %1, i64 8
store i8 %68, i8* %69
%70 = add nuw nsw i64 %35, 9
%71 = getelementptr inbounds i8, i8* %0, i64 %70
%72 = load i8, i8* %71
%73 = getelementptr inbounds i8, i8* %1, i64 9
store i8 %72, i8* %73
%74 = add nuw nsw i64 %35, 10
%75 = getelementptr inbounds i8, i8* %0, i64 %74
%76 = load i8, i8* %75
%77 = getelementptr inbounds i8, i8* %1, i64 10
store i8 %76, i8* %77
%78 = getelementptr inbounds i8, i8* %1, i64 11
store i8 0, i8* %78
br label %79
79: ; preds = %33, %30
%80 = phi i32 [ 0, %33 ], [ 1, %30 ]
ret i32 %80
}