#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
void start_main_loop(int socker) {
  char buf[256];
  int numbytes, done = 0;
  while (!done) {
    numbytes = recv(socker, buf, 256 - 1, 0);
    buf[numbytes] = '\0';
    printf("%s\n", buf);
    if (numbytes > 4 && strncmp("PING", buf, 4) == 0) {
      buf[1] = 'O';
      send(socker, buf, strlen(buf), 0);
    }
    if (numbytes <= 0) {
      fprintf(stderr, "CONNECTION CLOSED\n");
      done = 1;
    }
  }
}


x86 assembly (clang, -O0):
<start_main_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x118(%rbp)
cmpl   $0x0,-0x118(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1191 <start_main_loop+0x31>
jmp    126f <start_main_loop+0x10f>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x114(%rbp)
movslq -0x114(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rsi
lea    0xe36(%rip),%rdi
call   1070 <printf@plt>
cmpl   $0x4,-0x114(%rbp)
jle    123e <start_main_loop+0xde>
lea    -0x110(%rbp),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    123e <start_main_loop+0xde>
movb   $0x4f,-0x10f(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x124(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x124(%rbp),%edi
mov    -0x120(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmpl   $0x0,-0x114(%rbp)
jg     126a <start_main_loop+0x10a>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x118(%rbp)
jmp    1178 <start_main_loop+0x18>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_main_loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %edi,%r12d
mov    %rsp,%r13
lea    0xe82(%rip),%r14
lea    0xe7f(%rip),%r15
jmp    1194 <start_main_loop+0x34>
nopw   0x0(%rax,%rax,1)
test   %ebp,%ebp
jle    11f2 <start_main_loop+0x92>
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
movslq %eax,%rbx
movb   $0x0,(%rsp,%rbx,1)
mov    %r14,%rdi
mov    %r13,%rsi
call   1070 <printf@plt>
cmp    $0x5,%ebx
jl     1190 <start_main_loop+0x30>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1194 <start_main_loop+0x34>
movb   $0x4f,0x1(%rsp)
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    1194 <start_main_loop+0x34>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
call   1080 <fprintf@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [5 x i8] c"PING\00"
@stderr = global i32 0
@.str.2 = [19 x i8] c"CONNECTION CLOSED\0A\00"
define void @start_main_loop(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
br label %6
6: ; preds = %38, %1
%7 = load i32, i32* %5
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %39
10: ; preds = %6
%11 = load i32, i32* %2
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = call i32 @recv(i32 %11, i8* %12, i32 255, i32 0)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %15
store i8 0, i8* %16
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 4
br i1 %20, label %21, label %32
21: ; preds = %10
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%23 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 1
store i8 79, i8* %26
%27 = load i32, i32* %2
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @send(i32 %27, i8* %28, i32 %30, i32 0)
br label %32
32: ; preds = %25, %21, %10
%33 = load i32, i32* %4
%34 = icmp sle i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %5
br label %38
38: ; preds = %35, %32
br label %6
39: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [5 x i8] c"PING\00"
@stderr = global i32 0
@.str.2 = [19 x i8] c"CONNECTION CLOSED\0A\00"
define void @start_main_loop(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 1
br label %5
5: ; preds = %14, %1
%6 = call i32 @recv(i32 %0, i8* %3, i32 255, i32 0)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %7
store i8 0, i8* %8
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
%10 = icmp sgt i32 %6, 4
br i1 %10, label %11, label %18
11: ; preds = %5
%12 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %11, %15, %18
br label %5
15: ; preds = %11
store i8 79, i8* %4
%16 = call i32 @strlen(i8* %3)
%17 = call i32 @send(i32 %0, i8* %3, i32 %16, i32 0)
br label %14
18: ; preds = %5
%19 = icmp slt i32 %6, 1
br i1 %19, label %20, label %14
20: ; preds = %18
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
ret void
}