#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*/ LNat_Str_To_Upper(char const *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sscanf(char const *, char *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
char *strstr(char const *, char *);
int Get_Description_Url(const char *ssdp_response, char **desc_url) {
  const char *fir_rn;
  const char *sec_rn;
  const char *end_loc_tag;
  int end_loc_offset;
  int desc_url_malloc_size;
  char *ssdp_upper_response = (char *)malloc(strlen(ssdp_response) + 1);
  if (NULL == ssdp_upper_response) {
    return -499;
  }
  (void)LNat_Str_To_Upper(ssdp_response, ssdp_upper_response);
  if (NULL == strstr(ssdp_response, "200 OK")) {
    free(ssdp_upper_response);
    return -797;
  }
  fir_rn = ssdp_upper_response;
  while (1) {
    if ((fir_rn = strstr(fir_rn, "\r\n")) == NULL) {
      break;
    }
    fir_rn += strlen("\r\n");
    if ((sec_rn = strstr(fir_rn, "\r\n")) == NULL) {
      break;
    }
    end_loc_tag = fir_rn + strlen("LOCATION:");
    end_loc_offset = end_loc_tag - ssdp_upper_response;
    if (!strncmp(fir_rn, "LOCATION:", strlen("LOCATION:"))) {
      desc_url_malloc_size = (sec_rn - end_loc_tag) + 1;
      *desc_url = (char *)malloc(desc_url_malloc_size);
      if (NULL == *desc_url) {
        free(ssdp_upper_response);
        return -499;
      }
      sscanf(ssdp_response + end_loc_offset, "%s", *desc_url);
      free(ssdp_upper_response);
      return 0;
    }
  }
  free(ssdp_upper_response);
  if (strlen(*desc_url) + 1 > 512) {
    free(*desc_url);
    return -695;
  }
  return -795;
}


x86 assembly (clang, -O0):
<Get_Description_Url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmp    -0x40(%rbp),%rax
jne    11af <Get_Description_Url+0x3f>
movl   $0xfffffe0d,-0x4(%rbp)
jmp    137c <Get_Description_Url+0x20c>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1080 <LNat_Str_To_Upper@plt>
mov    -0x10(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11ef <Get_Description_Url+0x7f>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffce3,-0x4(%rbp)
jmp    137c <Get_Description_Url+0x20c>
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    121a <Get_Description_Url+0xaa>
jmp    133a <Get_Description_Url+0x1ca>
lea    0xde6(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdc6(%rip),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1259 <Get_Description_Url+0xe9>
jmp    133a <Get_Description_Url+0x1ca>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    0xda2(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xd70(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    0xd5e(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1335 <Get_Description_Url+0x1c5>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jne    1302 <Get_Description_Url+0x192>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffe0d,-0x4(%rbp)
jmp    137c <Get_Description_Url+0x20c>
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xcf9(%rip),%rsi
call   1070 <sscanf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    137c <Get_Description_Url+0x20c>
jmp    11f7 <Get_Description_Url+0x87>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cmp    $0x200,%eax
jle    1375 <Get_Description_Url+0x205>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0xfffffd49,-0x4(%rbp)
jmp    137c <Get_Description_Url+0x20c>
movl   $0xfffffce5,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Get_Description_Url>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    $0xfffffe0d,%ecx
test   %rax,%rax
je     12c3 <Get_Description_Url+0x153>
mov    %rax,%r13
mov    %rbp,%rdi
mov    %rax,%rsi
call   1080 <LNat_Str_To_Upper@plt>
lea    0xe4c(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     12b6 <Get_Description_Url+0x146>
mov    %rbp,0x10(%rsp)
mov    %rbx,0x8(%rsp)
lea    0xe31(%rip),%rbp
lea    0xe2d(%rip),%r14
mov    %r13,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     1286 <Get_Description_Url+0x116>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     1286 <Get_Description_Url+0x116>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    11e0 <Get_Description_Url+0x70>
movslq %r12d,%rax
add    %rax,%rbx
sub    %ebx,%r15d
add    $0x1,%r15d
mov    %r15d,%edi
call   1060 <malloc@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
test   %rax,%rax
je     12d4 <Get_Description_Url+0x164>
sub    %r13d,%ebx
movslq %ebx,%rcx
mov    0x10(%rsp),%rdi
add    %rcx,%rdi
lea    0xda2(%rip),%rsi
mov    %rax,%rdx
call   1070 <sscanf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %ecx,%ecx
jmp    12c3 <Get_Description_Url+0x153>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rbx
mov    (%rbx),%rdi
call   1050 <strlen@plt>
mov    $0xfffffce5,%ecx
cmp    $0x200,%eax
jl     12c3 <Get_Description_Url+0x153>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    $0xfffffd49,%ecx
jmp    12c3 <Get_Description_Url+0x153>
mov    %r13,%rdi
call   1030 <free@plt>
mov    $0xfffffce3,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
call   1030 <free@plt>
mov    $0xfffffe0d,%ecx
jmp    12c3 <Get_Description_Url+0x153>

LLVM IR (-O0):
@.str = [7 x i8] c"200 OK\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [10 x i8] c"LOCATION:\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @Get_Description_Url(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, 1
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %11
%17 = load i8*, i8** %11
%18 = icmp eq i8* null, %17
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 -499, i32* %3
br label %103
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = load i8*, i8** %11
%23 = call i32 @LNat_Str_To_Upper(i8* %21, i8* %22)
%24 = load i8*, i8** %4
%25 = call i8* @strstr(i8* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i8* null, %25
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i8*, i8** %11
%29 = call i32 @free(i8* %28)
store i32 -797, i32* %3
br label %103
30: ; preds = %20
%31 = load i8*, i8** %11
store i8* %31, i8** %6
br label %32
32: ; preds = %30, %89
%33 = load i8*, i8** %6
%34 = call i8* @strstr(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %34, i8** %6
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %37
36: ; preds = %32
br label %90
37: ; preds = %32
%38 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%39 = load i8*, i8** %6
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8* %41, i8** %6
%42 = load i8*, i8** %6
%43 = call i8* @strstr(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %43, i8** %7
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %46
45: ; preds = %37
br label %90
46: ; preds = %37
%47 = load i8*, i8** %6
%48 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8* %50, i8** %8
%51 = load i8*, i8** %8
%52 = load i8*, i8** %11
%53 = ptrtoint i8* %51 to i64
%54 = ptrtoint i8* %52 to i64
%55 = sub i64 %53, %54
%56 = trunc i64 %55 to i32
store i32 %56, i32* %9
%57 = load i8*, i8** %6
%58 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%59 = call i32 @strncmp(i8* %57, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %89, label %61
61: ; preds = %46
%62 = load i8*, i8** %7
%63 = load i8*, i8** %8
%64 = ptrtoint i8* %62 to i64
%65 = ptrtoint i8* %63 to i64
%66 = sub i64 %64, %65
%67 = add nsw i64 %66, 1
%68 = trunc i64 %67 to i32
store i32 %68, i32* %10
%69 = load i32, i32* %10
%70 = call i64 @malloc(i32 %69)
%71 = inttoptr i64 %70 to i8*
%72 = load i8**, i8*** %5
store i8* %71, i8** %72
%73 = load i8**, i8*** %5
%74 = load i8*, i8** %73
%75 = icmp eq i8* null, %74
br i1 %75, label %76, label %79
76: ; preds = %61
%77 = load i8*, i8** %11
%78 = call i32 @free(i8* %77)
store i32 -499, i32* %3
br label %103
79: ; preds = %61
%80 = load i8*, i8** %4
%81 = load i32, i32* %9
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = load i8**, i8*** %5
%85 = load i8*, i8** %84
%86 = call i32 @sscanf(i8* %83, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %85)
%87 = load i8*, i8** %11
%88 = call i32 @free(i8* %87)
store i32 0, i32* %3
br label %103
89: ; preds = %46
br label %32
90: ; preds = %45, %36
%91 = load i8*, i8** %11
%92 = call i32 @free(i8* %91)
%93 = load i8**, i8*** %5
%94 = load i8*, i8** %93
%95 = call i32 @strlen(i8* %94)
%96 = add nsw i32 %95, 1
%97 = icmp sgt i32 %96, 512
br i1 %97, label %98, label %102
98: ; preds = %90
%99 = load i8**, i8*** %5
%100 = load i8*, i8** %99
%101 = call i32 @free(i8* %100)
store i32 -695, i32* %3
br label %103
102: ; preds = %90
store i32 -795, i32* %3
br label %103
103: ; preds = %102, %98, %79, %76, %27, %19
%104 = load i32, i32* %3
ret i32 %104
}

LLVM IR (-O2):
@.str = [7 x i8] c"200 OK\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
@.str.2 = [10 x i8] c"LOCATION:\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @Get_Description_Url(i8* %0, i8** nocapture %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %57, label %8
8: ; preds = %2
%9 = tail call i32 @LNat_Str_To_Upper(i8* %0, i8* %6)
%10 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @free(i8* %6)
br label %57
14: ; preds = %8, %24
%15 = phi i8* [ %21, %24 ], [ %6, %8 ]
%16 = tail call i8* @strstr(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %49, label %18
18: ; preds = %14
%19 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %16, i64 %20
%22 = tail call i8* @strstr(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %49, label %24
24: ; preds = %18
%25 = tail call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 @strncmp(i8* %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %14
29: ; preds = %24
%30 = sext i32 %25 to i64
%31 = getelementptr inbounds i8, i8* %21, i64 %30
%32 = ptrtoint i8* %31 to i64
%33 = ptrtoint i8* %22 to i64
%34 = sub i64 %33, %32
%35 = trunc i64 %34 to i32
%36 = add i32 %35, 1
%37 = tail call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %1
%39 = icmp eq i64 %37, 0
br i1 %39, label %40, label %42
40: ; preds = %29
%41 = tail call i32 @free(i8* %6)
br label %57
42: ; preds = %29
%43 = sub i64 %32, %5
%44 = shl i64 %43, 32
%45 = ashr exact i64 %44, 32
%46 = getelementptr inbounds i8, i8* %0, i64 %45
%47 = tail call i32 @sscanf(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%48 = tail call i32 @free(i8* %6)
br label %57
49: ; preds = %18, %14
%50 = tail call i32 @free(i8* %6)
%51 = load i8*, i8** %1
%52 = tail call i32 @strlen(i8* %51)
%53 = icmp sgt i32 %52, 511
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i8*, i8** %1
%56 = tail call i32 @free(i8* %55)
br label %57
57: ; preds = %49, %2, %54, %42, %40, %12
%58 = phi i32 [ -797, %12 ], [ -695, %54 ], [ -499, %40 ], [ 0, %42 ], [ -499, %2 ], [ -795, %49 ]
ret i32 %58
}