#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 */
scalar_t__ hls_url_get_first_session(char *, char *);
scalar_t__ malloc(int);
scalar_t__ memcmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
char *strstr(char *, char *);
int hls_merge_url(char *parent_url, char *child_url, char **desturl) {
  char sessionstr[1024];
  unsigned char resvalue = -1;
  if (0 == memcmp(child_url, "http://", strlen("http://"))) {
    *desturl = (char *)malloc(1024);
    memset(*desturl, '\0', 1024);
    strcpy(*desturl, child_url);
    resvalue = 0;
  } else {
    if (hls_url_get_first_session(child_url, sessionstr) == 0) {
      char *begin = strstr(parent_url, sessionstr);
      if (begin) {
        resvalue = 0;
        *desturl = (char *)malloc(1024);
        memset(*desturl, '\0', 1024);
        strncpy(*desturl, parent_url, begin - parent_url);
        strcat(*desturl, child_url);
      } else {
        begin = strrchr(parent_url, '/');
        if (begin) {
          resvalue = 0;
          *desturl = (char *)malloc(1024);
          memset(*desturl, '\0', 1024);
          strncpy(*desturl, parent_url, begin - parent_url + 1);
          strcat(*desturl, child_url);
        }
      }
    }
  }
  return resvalue;
}


x86 assembly (clang, -O0):
<hls_merge_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0xff,-0x421(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x438(%rbp)
lea    0xe30(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x438(%rbp),%rdi
mov    %eax,%edx
lea    0xe1b(%rip),%rsi
call   1080 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    123b <hls_merge_url+0x9b>
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
movb   $0x0,-0x421(%rbp)
jmp    1371 <hls_merge_url+0x1d1>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   10b0 <hls_url_get_first_session@plt>
cmp    $0x0,%rax
jne    136c <hls_merge_url+0x1cc>
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   10c0 <strstr@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
je     12dd <hls_merge_url+0x13d>
movb   $0x0,-0x421(%rbp)
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x430(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcat@plt>
jmp    1367 <hls_merge_url+0x1c7>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
je     1362 <hls_merge_url+0x1c2>
movb   $0x0,-0x421(%rbp)
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x430(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcat@plt>
jmp    1367 <hls_merge_url+0x1c7>
jmp    136c <hls_merge_url+0x1cc>
jmp    1371 <hls_merge_url+0x1d1>
movzbl -0x421(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hls_merge_url>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xe41(%rip),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1080 <memcmp@plt>
test   %rax,%rax
je     122b <hls_merge_url+0x8b>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   10b0 <hls_url_get_first_session@plt>
mov    $0xff,%ebp
test   %rax,%rax
jne    12a9 <hls_merge_url+0x109>
mov    %rsp,%rsi
mov    %r15,%rdi
call   10c0 <strstr@plt>
test   %rax,%rax
je     1256 <hls_merge_url+0xb6>
mov    %rax,%r12
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,(%r14)
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    (%r14),%rdi
sub    %r15d,%r12d
jmp    1293 <hls_merge_url+0xf3>
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,(%r14)
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    (%r14),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    12a9 <hls_merge_url+0x109>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     12a9 <hls_merge_url+0x109>
mov    %rax,%r12
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,(%r14)
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    (%r14),%rdi
sub    %r15d,%r12d
add    $0x1,%r12d
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
mov    (%r14),%rdi
mov    %rbx,%rsi
call   10a0 <strcat@plt>
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
define i32 @hls_merge_url(i8* %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca [1024 x i8]
%8 = alloca i8
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
store i8 -1, i8* %8
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = call i64 @memcmp(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp eq i64 0, %12
br i1 %13, label %14, label %25
14: ; preds = %3
%15 = call i64 @malloc(i32 1024)
%16 = inttoptr i64 %15 to i8*
%17 = load i8**, i8*** %6
store i8* %16, i8** %17
%18 = load i8**, i8*** %6
%19 = load i8*, i8** %18
%20 = call i32 @memset(i8* %19, i8 signext 0, i32 1024)
%21 = load i8**, i8*** %6
%22 = load i8*, i8** %21
%23 = load i8*, i8** %5
%24 = call i32 @strcpy(i8* %22, i8* %23)
store i8 0, i8* %8
br label %87
25: ; preds = %3
%26 = load i8*, i8** %5
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = call i64 @hls_url_get_first_session(i8* %26, i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %86
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%33 = call i8* @strstr(i8* %31, i8* %32)
store i8* %33, i8** %9
%34 = load i8*, i8** %9
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %57
36: ; preds = %30
store i8 0, i8* %8
%37 = call i64 @malloc(i32 1024)
%38 = inttoptr i64 %37 to i8*
%39 = load i8**, i8*** %6
store i8* %38, i8** %39
%40 = load i8**, i8*** %6
%41 = load i8*, i8** %40
%42 = call i32 @memset(i8* %41, i8 signext 0, i32 1024)
%43 = load i8**, i8*** %6
%44 = load i8*, i8** %43
%45 = load i8*, i8** %4
%46 = load i8*, i8** %9
%47 = load i8*, i8** %4
%48 = ptrtoint i8* %46 to i64
%49 = ptrtoint i8* %47 to i64
%50 = sub i64 %48, %49
%51 = trunc i64 %50 to i32
%52 = call i32 @strncpy(i8* %44, i8* %45, i32 %51)
%53 = load i8**, i8*** %6
%54 = load i8*, i8** %53
%55 = load i8*, i8** %5
%56 = call i32 @strcat(i8* %54, i8* %55)
br label %85
57: ; preds = %30
%58 = load i8*, i8** %4
%59 = call i8* @strrchr(i8* %58, i8 signext 47)
store i8* %59, i8** %9
%60 = load i8*, i8** %9
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %84
62: ; preds = %57
store i8 0, i8* %8
%63 = call i64 @malloc(i32 1024)
%64 = inttoptr i64 %63 to i8*
%65 = load i8**, i8*** %6
store i8* %64, i8** %65
%66 = load i8**, i8*** %6
%67 = load i8*, i8** %66
%68 = call i32 @memset(i8* %67, i8 signext 0, i32 1024)
%69 = load i8**, i8*** %6
%70 = load i8*, i8** %69
%71 = load i8*, i8** %4
%72 = load i8*, i8** %9
%73 = load i8*, i8** %4
%74 = ptrtoint i8* %72 to i64
%75 = ptrtoint i8* %73 to i64
%76 = sub i64 %74, %75
%77 = add nsw i64 %76, 1
%78 = trunc i64 %77 to i32
%79 = call i32 @strncpy(i8* %70, i8* %71, i32 %78)
%80 = load i8**, i8*** %6
%81 = load i8*, i8** %80
%82 = load i8*, i8** %5
%83 = call i32 @strcat(i8* %81, i8* %82)
br label %84
84: ; preds = %62, %57
br label %85
85: ; preds = %84, %36
br label %86
86: ; preds = %85, %25
br label %87
87: ; preds = %86, %14
%88 = load i8, i8* %8
%89 = zext i8 %88 to i32
ret i32 %89
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
define i32 @hls_merge_url(i8* %0, i8* %1, i8** nocapture %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = tail call i64 @memcmp(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %3
%10 = tail call i64 @malloc(i32 1024)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %2
%12 = tail call i32 @memset(i8* %11, i8 signext 0, i32 1024)
%13 = load i8*, i8** %2
%14 = tail call i32 @strcpy(i8* %13, i8* %1)
br label %49
15: ; preds = %3
%16 = call i64 @hls_url_get_first_session(i8* %1, i8* %5)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %49
18: ; preds = %15
%19 = call i8* @strstr(i8* dereferenceable(1) %0, i8* %5)
%20 = icmp eq i8* %19, null
br i1 %20, label %33, label %21
21: ; preds = %18
%22 = call i64 @malloc(i32 1024)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %2
%24 = call i32 @memset(i8* %23, i8 signext 0, i32 1024)
%25 = load i8*, i8** %2
%26 = ptrtoint i8* %19 to i64
%27 = ptrtoint i8* %0 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
%30 = call i32 @strncpy(i8* %25, i8* %0, i32 %29)
%31 = load i8*, i8** %2
%32 = call i32 @strcat(i8* %31, i8* %1)
br label %49
33: ; preds = %18
%34 = call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%35 = icmp eq i8* %34, null
br i1 %35, label %49, label %36
36: ; preds = %33
%37 = call i64 @malloc(i32 1024)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %2
%39 = call i32 @memset(i8* %38, i8 signext 0, i32 1024)
%40 = load i8*, i8** %2
%41 = ptrtoint i8* %34 to i64
%42 = ptrtoint i8* %0 to i64
%43 = sub i64 %41, %42
%44 = trunc i64 %43 to i32
%45 = add i32 %44, 1
%46 = call i32 @strncpy(i8* %40, i8* %0, i32 %45)
%47 = load i8*, i8** %2
%48 = call i32 @strcat(i8* %47, i8* %1)
br label %49
49: ; preds = %21, %36, %33, %15, %9
%50 = phi i32 [ 0, %9 ], [ 255, %15 ], [ 0, %21 ], [ 0, %36 ], [ 255, %33 ]
ret i32 %50
}