#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 */
typedef int /*<<< orphan*/ returnHost;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ send_data(int, char *);
int /*<<< orphan*/ slog(int /*<<< orphan*/, int, char *);
int strlen(char *);
void send_keepalive(int sock, char *buf) {
  char *str = "PING ";
  int found, i, x;
  for (i = 0; i < strlen(buf); i++) {
    if (buf[i] == str[0]) {
      found = 1;
      for (x = 1; x < 4; x++)
        if (buf[i + x] != str[x])
          found = 0;
      if (found) {
        int count = 0;
        for (x = (i + strlen(str)); x < strlen(buf); x++)
          count++;
        char returnHost[count + 5];
        bzero(returnHost, sizeof(returnHost));
        returnHost[0] = 'P';
        returnHost[1] = 'O';
        returnHost[2] = 'N';
        returnHost[3] = 'G';
        returnHost[4] = ' ';
        count = 0;
        for (x = (i + strlen(str)); x < strlen(buf); x++) {
          returnHost[count + 5] = buf[x];
          count++;
        }
        if (send_data(sock, returnHost)) {
          slog(0, 1, "Answering with PONG");
          return;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<send_keepalive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
cmp    %ecx,%eax
jge    1376 <send_keepalive+0x236>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1363 <send_keepalive+0x223>
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11ef <send_keepalive+0xaf>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11dc <send_keepalive+0x9c>
movl   $0x0,-0x1c(%rbp)
jmp    11e1 <send_keepalive+0xa1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <send_keepalive+0x66>
cmpl   $0x0,-0x1c(%rbp)
je     135e <send_keepalive+0x21e>
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
cmp    %ecx,%eax
jge    124c <send_keepalive+0x10c>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1219 <send_keepalive+0xd9>
mov    -0x28(%rbp),%eax
add    $0x5,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    %eax,%esi
call   1060 <bzero@plt>
mov    -0x58(%rbp),%rax
movb   $0x50,(%rax)
movb   $0x4f,0x1(%rax)
movb   $0x4e,0x2(%rax)
movb   $0x47,0x3(%rax)
movb   $0x20,0x4(%rax)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
cmp    %ecx,%eax
jge    1301 <send_keepalive+0x1c1>
mov    -0x58(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
mov    -0x28(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12b3 <send_keepalive+0x173>
mov    -0x58(%rbp),%rsi
mov    -0x4(%rbp),%edi
call   1040 <send_data@plt>
cmp    $0x0,%rax
je     1336 <send_keepalive+0x1f6>
xor    %edi,%edi
mov    $0x1,%esi
lea    0xce1(%rip),%rdx
call   1050 <slog@plt>
movl   $0x1,-0x3c(%rbp)
jmp    133d <send_keepalive+0x1fd>
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x3c(%rbp),%eax
test   %eax,%eax
je     1359 <send_keepalive+0x219>
jmp    1354 <send_keepalive+0x214>
jmp    1376 <send_keepalive+0x236>
jmp    135e <send_keepalive+0x21e>
jmp    1363 <send_keepalive+0x223>
jmp    1368 <send_keepalive+0x228>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1161 <send_keepalive+0x21>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_keepalive>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r13
mov    %edi,-0x2c(%rbp)
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    12a0 <send_keepalive+0x160>
xor    %r15d,%r15d
jmp    1187 <send_keepalive+0x47>
nopl   0x0(%rax)
add    $0x1,%r15
mov    %r13,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%r15
jge    12a0 <send_keepalive+0x160>
cmpb   $0x50,0x0(%r13,%r15,1)
jne    1170 <send_keepalive+0x30>
cmpb   $0x47,0x3(%r13,%r15,1)
jne    1170 <send_keepalive+0x30>
cmpb   $0x4e,0x2(%r13,%r15,1)
jne    1170 <send_keepalive+0x30>
cmpb   $0x49,0x1(%r13,%r15,1)
jne    1170 <send_keepalive+0x30>
lea    0xe52(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
lea    (%r12,%r15,1),%ebx
mov    %r13,%rdi
call   1030 <strlen@plt>
xor    %r14d,%r14d
cmp    %eax,%ebx
jge    11ea <send_keepalive+0xaa>
add    %r15d,%r12d
xor    %ebx,%ebx
xchg   %ax,%ax
lea    0x1(%rbx),%r14d
mov    %r13,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rbx,1),%ecx
add    $0x1,%ecx
mov    %r14d,%ebx
cmp    %eax,%ecx
jl     11d0 <send_keepalive+0x90>
mov    %rsp,-0x38(%rbp)
mov    %r14d,%ebx
add    $0x5,%r14d
mov    %rsp,%r12
mov    %r12,-0x40(%rbp)
add    $0x14,%rbx
and    $0xfffffffffffffff0,%rbx
sub    %rbx,%r12
mov    %r12,%rsp
mov    %r12,%rdi
mov    %r14d,%esi
call   1060 <bzero@plt>
movl   $0x474e4f50,(%r12)
47
neg    %rbx
mov    -0x40(%rbp),%rax
movb   $0x20,0x4(%rax,%rbx,1)
lea    0xdd0(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
add    %r15d,%ebx
mov    %r13,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebx
jge    1270 <send_keepalive+0x130>
movslq %ebx,%rbx
lea    0x5(%r12),%r14
xchg   %ax,%ax
movzbl 0x0(%r13,%rbx,1),%eax
mov    %al,(%r14)
add    $0x1,%rbx
mov    %r13,%rdi
call   1030 <strlen@plt>
cltq
add    $0x1,%r14
cmp    %rax,%rbx
jl     1250 <send_keepalive+0x110>
mov    -0x2c(%rbp),%edi
mov    %r12,%rsi
call   1040 <send_data@plt>
test   %rax,%rax
jne    1289 <send_keepalive+0x149>
mov    -0x38(%rbp),%rsp
jmp    1170 <send_keepalive+0x30>
lea    0xd76(%rip),%rdx
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <slog@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"PING \00"
@.str.1 = [20 x i8] c"Answering with PONG\00"
define void @send_keepalive(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %5
store i32 0, i32* %7
br label %13
13: ; preds = %124, %2
%14 = load i32, i32* %7
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %127
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %24, %28
br i1 %29, label %30, label %123
30: ; preds = %18
store i32 1, i32* %6
store i32 1, i32* %8
br label %31
31: ; preds = %52, %30
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 4
br i1 %33, label %34, label %55
34: ; preds = %31
%35 = load i8*, i8** %4
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = add nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %35, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = load i8*, i8** %5
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %42, %48
br i1 %49, label %50, label %51
50: ; preds = %34
store i32 0, i32* %6
br label %51
51: ; preds = %50, %34
br label %52
52: ; preds = %51
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %31
55: ; preds = %31
%56 = load i32, i32* %6
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %122
58: ; preds = %55
store i32 0, i32* %9
%59 = load i32, i32* %7
%60 = load i8*, i8** %5
%61 = call i32 @strlen(i8* %60)
%62 = add nsw i32 %59, %61
store i32 %62, i32* %8
br label %63
63: ; preds = %71, %58
%64 = load i32, i32* %8
%65 = load i8*, i8** %4
%66 = call i32 @strlen(i8* %65)
%67 = icmp slt i32 %64, %66
br i1 %67, label %68, label %74
68: ; preds = %63
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %71
71: ; preds = %68
%72 = load i32, i32* %8
%73 = add nsw i32 %72, 1
store i32 %73, i32* %8
br label %63
74: ; preds = %63
%75 = load i32, i32* %9
%76 = add nsw i32 %75, 5
%77 = zext i32 %76 to i64
%78 = call i8* @llvm.stacksave()
store i8* %78, i8** %10
%79 = alloca i8, i64 %77
store i64 %77, i64* %11
%80 = trunc i64 %77 to i32
%81 = call i32 @bzero(i8* %79, i32 %80)
%82 = getelementptr inbounds i8, i8* %79, i64 0
store i8 80, i8* %82
%83 = getelementptr inbounds i8, i8* %79, i64 1
store i8 79, i8* %83
%84 = getelementptr inbounds i8, i8* %79, i64 2
store i8 78, i8* %84
%85 = getelementptr inbounds i8, i8* %79, i64 3
store i8 71, i8* %85
%86 = getelementptr inbounds i8, i8* %79, i64 4
store i8 32, i8* %86
store i32 0, i32* %9
%87 = load i32, i32* %7
%88 = load i8*, i8** %5
%89 = call i32 @strlen(i8* %88)
%90 = add nsw i32 %87, %89
store i32 %90, i32* %8
br label %91
91: ; preds = %108, %74
%92 = load i32, i32* %8
%93 = load i8*, i8** %4
%94 = call i32 @strlen(i8* %93)
%95 = icmp slt i32 %92, %94
br i1 %95, label %96, label %111
96: ; preds = %91
%97 = load i8*, i8** %4
%98 = load i32, i32* %8
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %97, i64 %99
%101 = load i8, i8* %100
%102 = load i32, i32* %9
%103 = add nsw i32 %102, 5
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i8, i8* %79, i64 %104
store i8 %101, i8* %105
%106 = load i32, i32* %9
%107 = add nsw i32 %106, 1
store i32 %107, i32* %9
br label %108
108: ; preds = %96
%109 = load i32, i32* %8
%110 = add nsw i32 %109, 1
store i32 %110, i32* %8
br label %91
111: ; preds = %91
%112 = load i32, i32* %3
%113 = call i64 @send_data(i32 %112, i8* %79)
%114 = icmp ne i64 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %111
%116 = call i32 @slog(i32 0, i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %12
br label %118
117: ; preds = %111
store i32 0, i32* %12
br label %118
118: ; preds = %117, %115
%119 = load i8*, i8** %10
%120 = load i32, i32* %12
switch i32 %120, label %128 [
i32 0, label %121
i32 1, label %127
]
121: ; preds = %118
br label %122
122: ; preds = %121, %55
br label %123
123: ; preds = %122, %18
br label %124
124: ; preds = %123
%125 = load i32, i32* %7
%126 = add nsw i32 %125, 1
store i32 %126, i32* %7
br label %13
127: ; preds = %118, %13
ret void
128: ; preds = %118
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"PING \00"
@.str.1 = [20 x i8] c"Answering with PONG\00"
define void @send_keepalive(i32 %0, i8* %1) {
%3 = call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %77
5: ; preds = %2, %73
%6 = phi i64 [ %10, %73 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %1, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 80
%10 = add nuw nsw i64 %6, 1
br i1 %9, label %11, label %73
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %1, i64 %10
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 73
%15 = add nuw nsw i64 %6, 2
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 78
%19 = add nuw nsw i64 %6, 3
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 71
%23 = select i1 %22, i1 true, i1 %18
%24 = select i1 %23, i1 true, i1 %14
br i1 %24, label %73, label %25
25: ; preds = %11
%26 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%27 = trunc i64 %6 to i32
%28 = add nsw i32 %26, %27
%29 = call i32 @strlen(i8* %1)
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %38
31: ; preds = %25, %31
%32 = phi i32 [ %34, %31 ], [ 0, %25 ]
%33 = phi i32 [ %35, %31 ], [ %28, %25 ]
%34 = add nuw nsw i32 %32, 1
%35 = add nsw i32 %33, 1
%36 = call i32 @strlen(i8* %1)
%37 = icmp slt i32 %35, %36
br i1 %37, label %31, label %38
38: ; preds = %31, %25
%39 = phi i32 [ 0, %25 ], [ %34, %31 ]
%40 = add nuw nsw i32 %39, 5
%41 = zext i32 %40 to i64
%42 = call i8* @llvm.stacksave()
%43 = alloca i8, i64 %41
%44 = call i32 @bzero(i8* %43, i32 %40)
store i8 80, i8* %43
%45 = getelementptr inbounds i8, i8* %43, i64 1
store i8 79, i8* %45
%46 = getelementptr inbounds i8, i8* %43, i64 2
store i8 78, i8* %46
%47 = getelementptr inbounds i8, i8* %43, i64 3
store i8 71, i8* %47
%48 = getelementptr inbounds i8, i8* %43, i64 4
store i8 32, i8* %48
%49 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%50 = add i32 %49, %27
%51 = call i32 @strlen(i8* %1)
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %67
53: ; preds = %38
%54 = sext i32 %50 to i64
br label %55
55: ; preds = %53, %55
%56 = phi i64 [ %54, %53 ], [ %63, %55 ]
%57 = phi i64 [ 0, %53 ], [ %62, %55 ]
%58 = getelementptr inbounds i8, i8* %1, i64 %56
%59 = load i8, i8* %58
%60 = add nuw nsw i64 %57, 5
%61 = getelementptr inbounds i8, i8* %43, i64 %60
store i8 %59, i8* %61
%62 = add nuw nsw i64 %57, 1
%63 = add nsw i64 %56, 1
%64 = call i32 @strlen(i8* %1)
%65 = sext i32 %64 to i64
%66 = icmp slt i64 %63, %65
br i1 %66, label %55, label %67
67: ; preds = %55, %38
%68 = call i64 @send_data(i32 %0, i8* %43)
%69 = icmp eq i64 %68, 0
br i1 %69, label %72, label %70
70: ; preds = %67
%71 = call i32 @slog(i32 0, i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %77
72: ; preds = %67
br label %73
73: ; preds = %5, %72, %11
%74 = call i32 @strlen(i8* %1)
%75 = sext i32 %74 to i64
%76 = icmp slt i64 %10, %75
br i1 %76, label %5, label %77
77: ; preds = %73, %2, %70
ret void
}