#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 sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct iphdr {
  int ihl;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int);
void *announcement(void *args) {
  int rsfd = socket(AF_INET, SOCK_RAW, 146);
  if (rsfd < 0) {
    perror("socket() ");
    pthread_exit(0);
  }
  char buf[1024];
  struct sockaddr_in addr;
  int len = sizeof addr;
  struct iphdr *ip;
  while (1) {
    if (recvfrom(rsfd, buf, 1024, 0, (struct sockaddr *)&addr, &len) < 0) {
      perror("recvfrom() ");
      continue;
    }
    ip = (struct iphdr *)buf;
    int iphdrlen = ip->ihl * 4;
    char *message = buf + iphdrlen;
    printf("%s\n", message);
  }
}


x86 assembly (clang, -O0):
<announcement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    $0x92,%edx
call   1070 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    119b <announcement+0x4b>
lea    0xe71(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1040 <pthread_exit@plt>
movl   $0x4,-0x41c(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
lea    -0x418(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x41c(%rbp),%r9
call   1050 <recvfrom@plt>
cmp    $0x0,%rax
jge    11e4 <announcement+0x94>
lea    0xe30(%rip),%rdi
call   1060 <perror@plt>
jmp    11a5 <announcement+0x55>
lea    -0x410(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%eax
mov    %eax,-0x42c(%rbp)
lea    -0x410(%rbp),%rax
movslq -0x42c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1030 <printf@plt>
jmp    11a5 <announcement+0x55>

x86 assembly (clang, -O2):
<announcement>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    $0x92,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11eb <announcement+0x9b>
movl   $0x4,0x4(%rsp)
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0x4(%rsp),%r12
lea    0xe69(%rip),%r13
lea    0xe6e(%rip),%rbp
jmp    11c5 <announcement+0x75>
nopw   0x0(%rax,%rax,1)
movslq 0x10(%rsp),%rax
lea    (%rsp,%rax,4),%rsi
add    $0x10,%rsi
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1050 <recvfrom@plt>
test   %rax,%rax
jns    11b0 <announcement+0x60>
mov    %r13,%rdi
call   1060 <perror@plt>
jmp    11c5 <announcement+0x75>
lea    0xe0e(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1040 <pthread_exit@plt>
jmp    1183 <announcement+0x33>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.iphdr = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str = [10 x i8] c"socket() \00"
@.str.1 = [12 x i8] c"recvfrom() \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i8* @announcement(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca %struct.iphdr*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %2
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_RAW
%12 = call i32 @socket(i32 %10, i32 %11, i32 146)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @pthread_exit(i32 0)
br label %18
18: ; preds = %15, %1
store i32 4, i32* %6
br label %19
19: ; preds = %18, %25, %27
%20 = load i32, i32* %3
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%22 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%23 = call i64 @recvfrom(i32 %20, i8* %21, i32 1024, i32 0, %struct.sockaddr* %22, i32* %6)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %19
27: ; preds = %19
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%29 = bitcast i8* %28 to %struct.iphdr*
store %struct.iphdr* %29, %struct.iphdr** %7
%30 = load %struct.iphdr*, %struct.iphdr** %7
%31 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = mul nsw i32 %32, 4
store i32 %33, i32* %8
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %19
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str = [10 x i8] c"socket() \00"
@.str.1 = [12 x i8] c"recvfrom() \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define noalias i8* @announcement(i8* nocapture readnone %0) {
%2 = alloca [1024 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_RAW
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 146)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @pthread_exit(i32 0)
br label %12
12: ; preds = %9, %1
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%14 = bitcast %struct.sockaddr_in* %3 to i8*
%15 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%16 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%17 = bitcast [1024 x i8]* %2 to i32*
br label %18
18: ; preds = %23, %12
%19 = call i64 @recvfrom(i32 %7, i8* %13, i32 1024, i32 0, %struct.sockaddr* %16, i32* %4)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %24
br label %18
24: ; preds = %18
%25 = load i32, i32* %17
%26 = shl nsw i32 %25, 2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %27
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %23
}