#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 /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
char *inet_ntoa(int /*<<< orphan*/);
unsigned int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ process(char *, int, char *, unsigned int, unsigned int,
                           char *, unsigned int);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
void getpacket(int fd, unsigned int sport, char *destination,
               unsigned int dport, char *source) {
  char buf[65536];
  struct sockaddr_in sin;
  socklen_t sinlen = sizeof(sin);
  ssize_t len;
  len = recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&sin, &sinlen);
  if (len == -1) {
    perror("recvfrom() failed");
  } else {
    char *ip;
    unsigned int port;
    if (sinlen != sizeof(sin)) {
      ip = "?";
      port = 0;
    } else {
      ip = inet_ntoa(sin.sin_addr);
      port = ntohs(sin.sin_port);
    }
    if (source) {
      if (strcmp(source, ip)) {
        fprintf(stderr, "Wrong sender [%s] - [%s]\n", source, ip);
        return;
      }
    }
    process(buf, len, ip, port, sport, destination, dport);
  }
}


x86 assembly (clang, -O0):
<getpacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10050,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x8,-0x1002c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10020(%rbp),%rsi
lea    -0x10028(%rbp),%r8
mov    $0x10000,%edx
xor    %ecx,%ecx
lea    -0x1002c(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x10030(%rbp)
cmpl   $0xffffffff,-0x10030(%rbp)
jne    11de <getpacket+0x6e>
lea    0xe2c(%rip),%rdi
call   1090 <perror@plt>
jmp    12ab <getpacket+0x13b>
movslq -0x1002c(%rbp),%rax
cmp    $0x8,%rax
je     120c <getpacket+0x9c>
lea    0xe1c(%rip),%rax
mov    %rax,-0x10038(%rbp)
movl   $0x0,-0x1003c(%rbp)
jmp    122f <getpacket+0xbf>
mov    -0x10024(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x10038(%rbp)
mov    -0x10028(%rbp),%edi
call   1080 <ntohs@plt>
mov    %eax,-0x1003c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     127e <getpacket+0x10e>
mov    -0x20(%rbp),%rdi
mov    -0x10038(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1279 <getpacket+0x109>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10038(%rbp),%rcx
lea    0xda5(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12ab <getpacket+0x13b>
jmp    127e <getpacket+0x10e>
lea    -0x10020(%rbp),%rdi
mov    -0x10030(%rbp),%esi
mov    -0x10038(%rbp),%rdx
mov    -0x1003c(%rbp),%ecx
mov    -0x8(%rbp),%r8d
mov    -0x10(%rbp),%r9
mov    -0x14(%rbp),%eax
mov    %eax,(%rsp)
call   1040 <process@plt>
add    $0x10050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpacket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10028,%rsp
mov    %r8,%r13
mov    %ecx,%ebx
mov    %rdx,%r15
mov    %esi,%r12d
movl   $0x8,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    $0x10000,%edx
xor    %ecx,%ecx
call   1070 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     1250 <getpacket+0xe0>
mov    %eax,%ebp
mov    %r15,0x18(%rsp)
cmpl   $0x8,0xc(%rsp)
jne    11e5 <getpacket+0x75>
mov    0x14(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%r14
mov    0x10(%rsp),%edi
call   1080 <ntohs@plt>
mov    %eax,%r15d
test   %r13,%r13
jne    11f4 <getpacket+0x84>
jmp    1221 <getpacket+0xb1>
xor    %r15d,%r15d
lea    0xe23(%rip),%r14
test   %r13,%r13
je     1221 <getpacket+0xb1>
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1221 <getpacket+0xb1>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1060 <fprintf@plt>
jmp    123e <getpacket+0xce>
mov    %ebx,(%rsp)
lea    0x20(%rsp),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    0x18(%rsp),%r9
call   1040 <process@plt>
add    $0x10028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda9(%rip),%rdi
call   1090 <perror@plt>
jmp    123e <getpacket+0xce>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"recvfrom() failed\00"
@.str.1 = [2 x i8] c"?\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Wrong sender [%s] - [%s]\0A\00"
define void @getpacket(i32 %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [65536 x i8]
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
store i32 8, i32* %13
%17 = load i32, i32* %6
%18 = getelementptr inbounds [65536 x i8], [65536 x i8]* %11, i64 0, i64 0
%19 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%20 = call i32 @recvfrom(i32 %17, i8* %18, i32 65536, i32 0, %struct.sockaddr* %19, i32* %13)
store i32 %20, i32* %14
%21 = load i32, i32* %14
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %5
%24 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %60
25: ; preds = %5
%26 = load i32, i32* %13
%27 = sext i32 %26 to i64
%28 = icmp ne i64 %27, 8
br i1 %28, label %29, label %30
29: ; preds = %25
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %15
store i32 0, i32* %16
br label %37
30: ; preds = %25
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%32 = load i32, i32* %31
%33 = call i8* @inet_ntoa(i32 %32)
store i8* %33, i8** %15
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @ntohs(i32 %35)
store i32 %36, i32* %16
br label %37
37: ; preds = %30, %29
%38 = load i8*, i8** %10
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %51
40: ; preds = %37
%41 = load i8*, i8** %10
%42 = load i8*, i8** %15
%43 = call i64 @strcmp(i8* %41, i8* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %10
%48 = load i8*, i8** %15
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %47, i8* %48)
br label %60
50: ; preds = %40
br label %51
51: ; preds = %50, %37
%52 = getelementptr inbounds [65536 x i8], [65536 x i8]* %11, i64 0, i64 0
%53 = load i32, i32* %14
%54 = load i8*, i8** %15
%55 = load i32, i32* %16
%56 = load i32, i32* %7
%57 = load i8*, i8** %8
%58 = load i32, i32* %9
%59 = call i32 @process(i8* %52, i32 %53, i8* %54, i32 %55, i32 %56, i8* %57, i32 %58)
br label %60
60: ; preds = %45, %51, %23
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"recvfrom() failed\00"
@.str.1 = [2 x i8] c"?\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Wrong sender [%s] - [%s]\0A\00"
define void @getpacket(i32 %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca [65536 x i8]
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in* %7 to i8*
%11 = bitcast i32* %8 to i8*
store i32 8, i32* %8
%12 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%13 = call i32 @recvfrom(i32 %0, i8* %9, i32 65536, i32 0, %struct.sockaddr* %12, i32* %8)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %5
%16 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %39
17: ; preds = %5
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 8
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1
%22 = load i32, i32* %21
%23 = call i8* @inet_ntoa(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @ntohs(i32 %25)
br label %27
27: ; preds = %17, %20
%28 = phi i8* [ %23, %20 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %17 ]
%29 = phi i32 [ %26, %20 ], [ 0, %17 ]
%30 = icmp eq i8* %4, null
br i1 %30, label %37, label %31
31: ; preds = %27
%32 = call i64 @strcmp(i8* %4, i8* %28)
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %28)
br label %39
37: ; preds = %31, %27
%38 = call i32 @process(i8* %9, i32 %13, i8* %28, i32 %29, i32 %1, i8* %2, i32 %3)
br label %39
39: ; preds = %15, %37, %34
ret void
}