#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 */
struct ILibWebServer_Session {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ILibGetLong(char *, int, long *);
int /*<<< orphan*/ ILibWebServer_Send_Raw(struct ILibWebServer_Session *,
                                          char *, int, int, int);
int /*<<< orphan*/ UpnpTryToSudirribe(char *, long, char *, int,
                                      struct ILibWebServer_Session *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
void UpnpSudirribeEvents(char *path, int pathlength, char *Timeout,
                         int TimeoutLength, char *URL, int URLLength,
                         struct ILibWebServer_Session *session) {
  long TimeoutVal;
  char *buffer = (char *)malloc(1 + sizeof(char) * pathlength);
  ILibGetLong(Timeout, TimeoutLength, &TimeoutVal);
  memcpy(buffer, path, pathlength);
  buffer[pathlength] = '\0';
  free(buffer);
  if (TimeoutVal > 7200) {
    TimeoutVal = 7200;
  }
  if (pathlength == 38 &&
      memcmp(path + 1, "MediaRenderer_ConnectionManager/event", 37) == 0) {
    UpnpTryToSudirribe("MediaRenderer_ConnectionManager", TimeoutVal, URL,
                       URLLength, session);
  } else if (pathlength == 37 &&
             memcmp(path + 1, "MediaRenderer_RenderingControl/event", 36) ==
                 0) {
    UpnpTryToSudirribe("MediaRenderer_RenderingControl", TimeoutVal, URL,
                       URLLength, session);
  } else if (pathlength == 32 &&
             memcmp(path + 1, "MediaRenderer_AVTransport/event", 31) == 0) {
    UpnpTryToSudirribe("MediaRenderer_AVTransport", TimeoutVal, URL, URLLength,
                       session);
  } else {
    ILibWebServer_Send_Raw(
        session,
        "HTTP/1.1 412 Invalid Service Name\r\nContent-Length: 0\r\n\r\n", 56, 1,
        1);
  }
}


x86 assembly (clang, -O0):
<UpnpSudirribeEvents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x38(%rbp),%rdx
call   1040 <ILibGetLong@plt>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x40(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x1c20,-0x38(%rbp)
jle    11f4 <UpnpSudirribeEvents+0x84>
movq   $0x1c20,-0x38(%rbp)
cmpl   $0x26,-0xc(%rbp)
jne    1241 <UpnpSudirribeEvents+0xd1>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xdf3(%rip),%rsi
mov    $0x25,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    1241 <UpnpSudirribeEvents+0xd1>
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    0x10(%rbp),%r8
lea    0xdef(%rip),%rdi
call   1080 <UpnpTryToSudirribe@plt>
jmp    1303 <UpnpSudirribeEvents+0x193>
cmpl   $0x25,-0xc(%rbp)
jne    128e <UpnpSudirribeEvents+0x11e>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xdec(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    128e <UpnpSudirribeEvents+0x11e>
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    0x10(%rbp),%r8
lea    0xde7(%rip),%rdi
call   1080 <UpnpTryToSudirribe@plt>
jmp    12fe <UpnpSudirribeEvents+0x18e>
cmpl   $0x20,-0xc(%rbp)
jne    12db <UpnpSudirribeEvents+0x16b>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xde3(%rip),%rsi
mov    $0x1f,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    12db <UpnpSudirribeEvents+0x16b>
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    0x10(%rbp),%r8
lea    0xdd9(%rip),%rdi
call   1080 <UpnpTryToSudirribe@plt>
jmp    12f9 <UpnpSudirribeEvents+0x189>
mov    0x10(%rbp),%rdi
lea    0xdde(%rip),%rsi
mov    $0x38,%edx
mov    $0x1,%r8d
mov    %r8d,%ecx
call   1090 <ILibWebServer_Send_Raw@plt>
jmp    12fe <UpnpSudirribeEvents+0x18e>
jmp    1303 <UpnpSudirribeEvents+0x193>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UpnpSudirribeEvents>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0x4(%rsp)
mov    %r8,0x10(%rsp)
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %esi,%ebx
mov    %rdi,%r13
movslq %esi,%r15
lea    0x1(%r15),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
lea    0x8(%rsp),%rdx
mov    %rbp,%rdi
mov    %r14d,%esi
call   1040 <ILibGetLong@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1060 <memcpy@plt>
movb   $0x0,(%r12,%r15,1)
mov    %r12,%rdi
call   1030 <free@plt>
cmpq   $0x1c21,0x8(%rsp)
jl     11e1 <UpnpSudirribeEvents+0x71>
movq   $0x1c20,0x8(%rsp)
mov    0x50(%rsp),%r14
cmp    $0x20,%ebx
je     1220 <UpnpSudirribeEvents+0xb0>
cmp    $0x25,%ebx
je     124b <UpnpSudirribeEvents+0xdb>
cmp    $0x26,%ebx
jne    1268 <UpnpSudirribeEvents+0xf8>
add    $0x1,%r13
lea    0xe00(%rip),%rsi
mov    %r13,%rdi
mov    $0x25,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    1268 <UpnpSudirribeEvents+0xf8>
mov    0x8(%rsp),%rsi
lea    0xe08(%rip),%rdi
jmp    1295 <UpnpSudirribeEvents+0x125>
add    $0x1,%r13
lea    0xe5f(%rip),%rsi
mov    %r13,%rdi
mov    $0x1f,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    1268 <UpnpSudirribeEvents+0xf8>
mov    0x8(%rsp),%rsi
lea    0xe61(%rip),%rdi
jmp    1295 <UpnpSudirribeEvents+0x125>
add    $0x1,%r13
lea    0xdf0(%rip),%rsi
mov    %r13,%rdi
mov    $0x24,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     1289 <UpnpSudirribeEvents+0x119>
lea    0xe55(%rip),%rsi
mov    %r14,%rdi
mov    $0x38,%edx
mov    $0x1,%ecx
mov    $0x1,%r8d
call   1090 <ILibWebServer_Send_Raw@plt>
jmp    12a6 <UpnpSudirribeEvents+0x136>
mov    0x8(%rsp),%rsi
lea    0xdd6(%rip),%rdi
mov    0x10(%rsp),%rdx
mov    0x4(%rsp),%ecx
mov    %r14,%r8
call   1080 <UpnpTryToSudirribe@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ILibWebServer_Session = type { i32 }
@.str = [38 x i8] c"MediaRenderer_ConnectionManager/event\00"
@.str.1 = [32 x i8] c"MediaRenderer_ConnectionManager\00"
@.str.2 = [37 x i8] c"MediaRenderer_RenderingControl/event\00"
@.str.3 = [31 x i8] c"MediaRenderer_RenderingControl\00"
@.str.4 = [32 x i8] c"MediaRenderer_AVTransport/event\00"
@.str.5 = [26 x i8] c"MediaRenderer_AVTransport\00"
@.str.6 = [57 x i8] c"HTTP/1.1 412 Invalid Service Name\0D\0AContent-Length: 0\0D\0A\0D\0A\00"
define void @UpnpSudirribeEvents(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5, %struct.ILibWebServer_Session* %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca %struct.ILibWebServer_Session*
%15 = alloca i64
%16 = alloca i8*
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i32 %5, i32* %13
store %struct.ILibWebServer_Session* %6, %struct.ILibWebServer_Session** %14
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = mul i64 1, %18
%20 = add i64 1, %19
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %16
%24 = load i8*, i8** %10
%25 = load i32, i32* %11
%26 = call i32 @ILibGetLong(i8* %24, i32 %25, i64* %15)
%27 = load i8*, i8** %16
%28 = load i8*, i8** %8
%29 = load i32, i32* %9
%30 = call i32 @memcpy(i8* %27, i8* %28, i32 %29)
%31 = load i8*, i8** %16
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %16
%36 = call i32 @free(i8* %35)
%37 = load i64, i64* %15
%38 = icmp sgt i64 %37, 7200
br i1 %38, label %39, label %40
39: ; preds = %7
store i64 7200, i64* %15
br label %40
40: ; preds = %39, %7
%41 = load i32, i32* %9
%42 = icmp eq i32 %41, 38
br i1 %42, label %43, label %54
43: ; preds = %40
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = call i64 @memcmp(i8* %45, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 37)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %43
%49 = load i64, i64* %15
%50 = load i8*, i8** %12
%51 = load i32, i32* %13
%52 = load %struct.ILibWebServer_Session*, %struct.ILibWebServer_Session** %14
%53 = call i32 @UpnpTryToSudirribe(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i64 %49, i8* %50, i32 %51, %struct.ILibWebServer_Session* %52)
br label %87
54: ; preds = %43, %40
%55 = load i32, i32* %9
%56 = icmp eq i32 %55, 37
br i1 %56, label %57, label %68
57: ; preds = %54
%58 = load i8*, i8** %8
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = call i64 @memcmp(i8* %59, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 36)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %57
%63 = load i64, i64* %15
%64 = load i8*, i8** %12
%65 = load i32, i32* %13
%66 = load %struct.ILibWebServer_Session*, %struct.ILibWebServer_Session** %14
%67 = call i32 @UpnpTryToSudirribe(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %63, i8* %64, i32 %65, %struct.ILibWebServer_Session* %66)
br label %86
68: ; preds = %57, %54
%69 = load i32, i32* %9
%70 = icmp eq i32 %69, 32
br i1 %70, label %71, label %82
71: ; preds = %68
%72 = load i8*, i8** %8
%73 = getelementptr inbounds i8, i8* %72, i64 1
%74 = call i64 @memcmp(i8* %73, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 31)
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %82
76: ; preds = %71
%77 = load i64, i64* %15
%78 = load i8*, i8** %12
%79 = load i32, i32* %13
%80 = load %struct.ILibWebServer_Session*, %struct.ILibWebServer_Session** %14
%81 = call i32 @UpnpTryToSudirribe(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i64 %77, i8* %78, i32 %79, %struct.ILibWebServer_Session* %80)
br label %85
82: ; preds = %71, %68
%83 = load %struct.ILibWebServer_Session*, %struct.ILibWebServer_Session** %14
%84 = call i32 @ILibWebServer_Send_Raw(%struct.ILibWebServer_Session* %83, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.6, i64 0, i64 0), i32 56, i32 1, i32 1)
br label %85
85: ; preds = %82, %76
br label %86
86: ; preds = %85, %62
br label %87
87: ; preds = %86, %48
ret void
}

LLVM IR (-O2):
%struct.ILibWebServer_Session = type { i32 }
@.str = [38 x i8] c"MediaRenderer_ConnectionManager/event\00"
@.str.1 = [32 x i8] c"MediaRenderer_ConnectionManager\00"
@.str.2 = [37 x i8] c"MediaRenderer_RenderingControl/event\00"
@.str.3 = [31 x i8] c"MediaRenderer_RenderingControl\00"
@.str.4 = [32 x i8] c"MediaRenderer_AVTransport/event\00"
@.str.5 = [26 x i8] c"MediaRenderer_AVTransport\00"
@.str.6 = [57 x i8] c"HTTP/1.1 412 Invalid Service Name\0D\0AContent-Length: 0\0D\0A\0D\0A\00"
define void @UpnpSudirribeEvents(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5, %struct.ILibWebServer_Session* %6) {
%8 = alloca i64
%9 = bitcast i64* %8 to i8*
%10 = sext i32 %1 to i64
%11 = add i32 %1, 1
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = call i32 @ILibGetLong(i8* %2, i32 %3, i64* %8)
%15 = call i32 @memcpy(i8* %13, i8* %0, i32 %1)
%16 = getelementptr inbounds i8, i8* %13, i64 %10
store i8 0, i8* %16
%17 = call i32 @free(i8* %13)
%18 = load i64, i64* %8
%19 = icmp sgt i64 %18, 7200
br i1 %19, label %20, label %21
20: ; preds = %7
store i64 7200, i64* %8
br label %21
21: ; preds = %20, %7
switch i32 %1, label %43 [
i32 38, label %22
i32 37, label %29
i32 32, label %36
]
22: ; preds = %21
%23 = getelementptr inbounds i8, i8* %0, i64 1
%24 = call i64 @memcmp(i8* %23, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 37)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %43
26: ; preds = %22
%27 = load i64, i64* %8
%28 = call i32 @UpnpTryToSudirribe(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i64 %27, i8* %4, i32 %5, %struct.ILibWebServer_Session* %6)
br label %45
29: ; preds = %21
%30 = getelementptr inbounds i8, i8* %0, i64 1
%31 = call i64 @memcmp(i8* %30, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 36)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %29
%34 = load i64, i64* %8
%35 = call i32 @UpnpTryToSudirribe(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %34, i8* %4, i32 %5, %struct.ILibWebServer_Session* %6)
br label %45
36: ; preds = %21
%37 = getelementptr inbounds i8, i8* %0, i64 1
%38 = call i64 @memcmp(i8* %37, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 31)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i64, i64* %8
%42 = call i32 @UpnpTryToSudirribe(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i64 %41, i8* %4, i32 %5, %struct.ILibWebServer_Session* %6)
br label %45
43: ; preds = %29, %22, %21, %36
%44 = call i32 @ILibWebServer_Send_Raw(%struct.ILibWebServer_Session* %6, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.6, i64 0, i64 0), i32 56, i32 1, i32 1)
br label %45
45: ; preds = %33, %43, %40, %26
ret void
}