#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 == 23 && memcmp(path + 1, "ContentDirectory/event", 22) == 0) {
    UpnpTryToSudirribe("ContentDirectory", TimeoutVal, URL, URLLength, session);
  } else if (pathlength == 24 &&
             memcmp(path + 1, "ConnectionManager/event", 23) == 0) {
    UpnpTryToSudirribe("ConnectionManager", 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   $0x17,-0xc(%rbp)
jne    1241 <UpnpSudirribeEvents+0xd1>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xdf3(%rip),%rsi
mov    $0x16,%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    0xde0(%rip),%rdi
call   1080 <UpnpTryToSudirribe@plt>
jmp    12b1 <UpnpSudirribeEvents+0x141>
cmpl   $0x18,-0xc(%rbp)
jne    128e <UpnpSudirribeEvents+0x11e>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xdce(%rip),%rsi
mov    $0x17,%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    0xdbc(%rip),%rdi
call   1080 <UpnpTryToSudirribe@plt>
jmp    12ac <UpnpSudirribeEvents+0x13c>
mov    0x10(%rbp),%rdi
lea    0xdb9(%rip),%rsi
mov    $0x38,%edx
mov    $0x1,%r8d
mov    %r8d,%ecx
call   1090 <ILibWebServer_Send_Raw@plt>
jmp    12b1 <UpnpSudirribeEvents+0x141>
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,%r12d
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r13
movslq %esi,%r14
lea    0x1(%r14),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r12d,%esi
call   1040 <ILibGetLong@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   1060 <memcpy@plt>
movb   $0x0,(%r15,%r14,1)
mov    %r15,%rdi
call   1030 <free@plt>
cmpq   $0x1c21,0x8(%rsp)
jl     11e1 <UpnpSudirribeEvents+0x71>
movq   $0x1c20,0x8(%rsp)
mov    0x50(%rsp),%r12
cmp    $0x18,%ebp
je     121b <UpnpSudirribeEvents+0xab>
cmp    $0x17,%ebp
jne    1238 <UpnpSudirribeEvents+0xc8>
add    $0x1,%r13
lea    0xe05(%rip),%rsi
mov    %r13,%rdi
mov    $0x16,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    1238 <UpnpSudirribeEvents+0xc8>
mov    0x8(%rsp),%rsi
lea    0xdfe(%rip),%rdi
jmp    1265 <UpnpSudirribeEvents+0xf5>
add    $0x1,%r13
lea    0xe02(%rip),%rsi
mov    %r13,%rdi
mov    $0x17,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     1259 <UpnpSudirribeEvents+0xe9>
lea    0xe13(%rip),%rsi
mov    %r12,%rdi
mov    $0x38,%edx
mov    $0x1,%ecx
mov    $0x1,%r8d
call   1090 <ILibWebServer_Send_Raw@plt>
jmp    1276 <UpnpSudirribeEvents+0x106>
mov    0x8(%rsp),%rsi
lea    0xddb(%rip),%rdi
mov    0x10(%rsp),%rdx
mov    0x4(%rsp),%ecx
mov    %r12,%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 = [23 x i8] c"ContentDirectory/event\00"
@.str.1 = [17 x i8] c"ContentDirectory\00"
@.str.2 = [24 x i8] c"ConnectionManager/event\00"
@.str.3 = [18 x i8] c"ConnectionManager\00"
@.str.4 = [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, 23
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 ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 22)
%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 ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %49, i8* %50, i32 %51, %struct.ILibWebServer_Session* %52)
br label %72
54: ; preds = %43, %40
%55 = load i32, i32* %9
%56 = icmp eq i32 %55, 24
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 ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 23)
%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 ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 %63, i8* %64, i32 %65, %struct.ILibWebServer_Session* %66)
br label %71
68: ; preds = %57, %54
%69 = load %struct.ILibWebServer_Session*, %struct.ILibWebServer_Session** %14
%70 = call i32 @ILibWebServer_Send_Raw(%struct.ILibWebServer_Session* %69, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i32 56, i32 1, i32 1)
br label %71
71: ; preds = %68, %62
br label %72
72: ; preds = %71, %48
ret void
}

LLVM IR (-O2):
%struct.ILibWebServer_Session = type { i32 }
@.str = [23 x i8] c"ContentDirectory/event\00"
@.str.1 = [17 x i8] c"ContentDirectory\00"
@.str.2 = [24 x i8] c"ConnectionManager/event\00"
@.str.3 = [18 x i8] c"ConnectionManager\00"
@.str.4 = [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 %36 [
i32 23, label %22
i32 24, label %29
]
22: ; preds = %21
%23 = getelementptr inbounds i8, i8* %0, i64 1
%24 = call i64 @memcmp(i8* %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 22)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %22
%27 = load i64, i64* %8
%28 = call i32 @UpnpTryToSudirribe(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %27, i8* %4, i32 %5, %struct.ILibWebServer_Session* %6)
br label %38
29: ; preds = %21
%30 = getelementptr inbounds i8, i8* %0, i64 1
%31 = call i64 @memcmp(i8* %30, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 23)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i64, i64* %8
%35 = call i32 @UpnpTryToSudirribe(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 %34, i8* %4, i32 %5, %struct.ILibWebServer_Session* %6)
br label %38
36: ; preds = %22, %21, %29
%37 = call i32 @ILibWebServer_Send_Raw(%struct.ILibWebServer_Session* %6, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i32 56, i32 1, i32 1)
br label %38
38: ; preds = %33, %36, %26
ret void
}