#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*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ ProcessUDPPacket(unsigned char *, int);
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ close(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int recvfrom(int, unsigned char *, int, int /*<<< orphan*/,
             int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void *ssdp_main() {
  unsigned char *buffer = (unsigned char *)malloc(4096);
  puts("Starting...\n");
  int sock_raw = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
  if (sock_raw < 0) {
    puts("Socket Error");
    return NULL;
  }
  puts("Socket created\n");
  while (1) {
    int data_size = recvfrom(sock_raw, buffer, 4096, 0, NULL, NULL);
    if (data_size < 0) {
      printf("Recvfrom error, failed to get packets\n");
      return NULL;
    }
    ProcessUDPPacket(buffer, data_size);
  }
  close(sock_raw);
  printf("Finished");
  return NULL;
}


x86 assembly (clang, -O0):
<ssdp_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c8 <ssdp_main+0x68>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    1226 <ssdp_main+0xc6>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1070 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1215 <ssdp_main+0xb5>
lea    0xe27(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1226 <ssdp_main+0xc6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1040 <ProcessUDPPacket@plt>
jmp    11d4 <ssdp_main+0x74>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssdp_main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1000,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11d0 <ssdp_main+0x80>
mov    %eax,%ebp
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <recvfrom@plt>
test   %eax,%eax
js     11c7 <ssdp_main+0x77>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <ProcessUDPPacket@plt>
jmp    11a0 <ssdp_main+0x50>
lea    0xe5c(%rip),%rdi
jmp    11d7 <ssdp_main+0x87>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Starting...\0A\00"
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [13 x i8] c"Socket Error\00"
@.str.2 = [16 x i8] c"Socket created\0A\00"
@.str.3 = [39 x i8] c"Recvfrom error, failed to get packets\0A\00"
define i8* @ssdp_main() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = call i64 @malloc(i32 4096)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %2
%7 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_RAW
%10 = load i32, i32* @IPPROTO_UDP
%11 = call i32 @socket(i32 %8, i32 %9, i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %1
br label %30
16: ; preds = %0
%17 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %26
%19 = load i32, i32* %3
%20 = load i8*, i8** %2
%21 = call i32 @recvfrom(i32 %19, i8* %20, i32 4096, i32 0, i32* null, i32* null)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %1
br label %30
26: ; preds = %18
%27 = load i8*, i8** %2
%28 = load i32, i32* %4
%29 = call i32 @ProcessUDPPacket(i8* %27, i32 %28)
br label %18
30: ; preds = %24, %14
%31 = load i8*, i8** %1
ret i8* %31
}

LLVM IR (-O2):
@.str = [13 x i8] c"Starting...\0A\00"
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [13 x i8] c"Socket Error\00"
@.str.2 = [16 x i8] c"Socket created\0A\00"
@str = [38 x i8] c"Recvfrom error, failed to get packets\00"
define noalias i8* @ssdp_main() {
%1 = tail call i64 @malloc(i32 4096)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_RAW
%6 = load i32, i32* @IPPROTO_UDP
%7 = tail call i32 @socket(i32 %4, i32 %5, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %22
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @recvfrom(i32 %7, i8* %2, i32 4096, i32 0, i32* null, i32* null)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %17, %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %22
17: ; preds = %11, %17
%18 = phi i32 [ %20, %17 ], [ %13, %11 ]
%19 = tail call i32 @ProcessUDPPacket(i8* %2, i32 %18)
%20 = tail call i32 @recvfrom(i32 %7, i8* %2, i32 4096, i32 0, i32* null, i32* null)
%21 = icmp slt i32 %20, 0
br i1 %21, label %15, label %17
22: ; preds = %15, %9
ret i8* null
}