#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*/ assert(int);
int /*<<< orphan*/ isspace(char const);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
void sendPong(const char *ping, int sockfd) {
  assert(NULL != ping);
  assert(0 < sockfd);
  char msg[1024] = {0}, output[1024] = {0};
  unsigned pos = 0;
  while (!isspace(ping[pos + 5]) && '\0' != ping[pos + 5]) {
    msg[pos] = ping[pos + 5];
    pos++;
  }
  sprintf(output, "PONG %s\r\n", msg);
  if (0 > send(sockfd, output, strlen(output), 0)) {
    perror("send error");
    pthread_exit(NULL);
  }
}


x86 assembly (clang, -O0):
<sendPong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movl   $0x0,-0x814(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x814(%rbp),%ecx
add    $0x5,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%edi
call   1060 <isspace@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x815(%rbp)
jne    1232 <sendPong+0xb2>
mov    -0x8(%rbp),%rax
mov    -0x814(%rbp),%ecx
add    $0x5,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
setne  %al
mov    %al,-0x815(%rbp)
mov    -0x815(%rbp),%al
test   $0x1,%al
jne    1245 <sendPong+0xc5>
jmp    1278 <sendPong+0xf8>
mov    -0x8(%rbp),%rax
mov    -0x814(%rbp),%ecx
add    $0x5,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x814(%rbp),%eax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    11e7 <sendPong+0x67>
lea    -0x810(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    0xd73(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x824(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x820(%rbp)
lea    -0x810(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x824(%rbp),%edi
mov    -0x820(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    12ee <sendPong+0x16e>
lea    0xd2a(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <pthread_exit@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendPong>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1070 <assert@plt>
xor    %edi,%edi
test   %r14d,%r14d
setg   %dil
call   1070 <assert@plt>
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x400(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movsbl 0x5(%r15),%edi
call   1060 <isspace@plt>
test   %eax,%eax
jne    1216 <sendPong+0x96>
lea    0x5(%r15),%rbx
mov    $0x6,%ebp
nopl   0x0(%rax)
movzbl (%rbx),%eax
test   %al,%al
je     1216 <sendPong+0x96>
lea    -0x6(%rbp),%ecx
mov    %ecx,%ecx
mov    %al,(%rsp,%rcx,1)
mov    %ebp,%eax
lea    (%r15,%rax,1),%rbx
movsbl (%r15,%rax,1),%edi
call   1060 <isspace@plt>
add    $0x1,%ebp
test   %eax,%eax
je     11f0 <sendPong+0x70>
lea    0xde3(%rip),%rsi
lea    0x400(%rsp),%rbx
mov    %rsp,%rdx
mov    %rbx,%rdi
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
test   %rax,%rax
js     125a <sendPong+0xda>
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda9(%rip),%rdi
call   1090 <perror@plt>
xor    %edi,%edi
call   1080 <pthread_exit@plt>
jmp    124c <sendPong+0xcc>

LLVM IR (-O0):
@.str = [10 x i8] c"PONG %s\0D\0A\00"
@.str.1 = [11 x i8] c"send error\00"
define void @sendPong(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = icmp ne i8* null, %8
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* %4
%13 = icmp slt i32 0, %12
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = bitcast [1024 x i8]* %5 to i8*
%17 = bitcast [1024 x i8]* %6 to i8*
store i32 0, i32* %7
br label %18
18: ; preds = %38, %2
%19 = load i8*, i8** %3
%20 = load i32, i32* %7
%21 = add i32 %20, 5
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @isspace(i8 signext %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %36, label %27
27: ; preds = %18
%28 = load i8*, i8** %3
%29 = load i32, i32* %7
%30 = add i32 %29, 5
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 0, %34
br label %36
36: ; preds = %27, %18
%37 = phi i1 [ false, %18 ], [ %35, %27 ]
br i1 %37, label %38, label %50
38: ; preds = %36
%39 = load i8*, i8** %3
%40 = load i32, i32* %7
%41 = add i32 %40, 5
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = load i8, i8* %43
%45 = load i32, i32* %7
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %46
store i8 %44, i8* %47
%48 = load i32, i32* %7
%49 = add i32 %48, 1
store i32 %49, i32* %7
br label %18
50: ; preds = %36
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%53 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %52)
%54 = load i32, i32* %4
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%57 = call i32 @strlen(i8* %56)
%58 = call i64 @send(i32 %54, i8* %55, i32 %57, i32 0)
%59 = icmp sgt i64 0, %58
br i1 %59, label %60, label %63
60: ; preds = %50
%61 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%62 = call i32 @pthread_exit(i32* null)
br label %63
63: ; preds = %60, %50
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"PONG %s\0D\0A\00"
@.str.1 = [11 x i8] c"send error\00"
define void @sendPong(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = icmp ne i8* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp sgt i32 %1, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds i8, i8* %0, i64 5
%14 = load i8, i8* %13
%15 = tail call i32 @isspace(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %2, %22
%18 = phi i8* [ %28, %22 ], [ %13, %2 ]
%19 = phi i32 [ %25, %22 ], [ 0, %2 ]
%20 = load i8, i8* %18
%21 = icmp eq i8 %20, 0
br i1 %21, label %32, label %22
22: ; preds = %17
%23 = zext i32 %19 to i64
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %23
store i8 %20, i8* %24
%25 = add i32 %19, 1
%26 = add i32 %19, 6
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i8, i8* %28
%30 = tail call i32 @isspace(i8 signext %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %17, label %32
32: ; preds = %17, %22, %2
%33 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %11)
%34 = call i32 @strlen(i8* %12)
%35 = call i64 @send(i32 %1, i8* %12, i32 %34, i32 0)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @pthread_exit(i32* null)
br label %40
40: ; preds = %37, %32
ret void
}