#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
size_t strlen(char *);
int main() {
  char buf[8192];
  while (fgets(buf, sizeof(buf), stdin) != NULL) {
    size_t len = strlen(buf);
    buf[len - 1] = '\0';
    if (strcmp(buf, "PING") != 0) {
      abort();
    }
    fprintf(stderr, "%s\n", buf);
    printf("PONG\n");
    fflush(stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x2010(%rbp),%rdi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
mov    $0x2000,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     122b <main+0xbb>
lea    -0x2010(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x2018(%rbp)
mov    -0x2018(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x2010(%rbp,%rax,1)
lea    -0x2010(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     11f0 <main+0x80>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    -0x2010(%rbp),%rdx
lea    0xdfe(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xdf6(%rip),%rdi
call   1050 <printf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
jmp    1182 <main+0x12>
xor    %eax,%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2008,%rsp
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x2000,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1227 <main+0xb7>
lea    0xe56(%rip),%r14
mov    0x2e27(%rip),%rbp
lea    0xe4d(%rip),%r15
lea    0xe4a(%rip),%r12
mov    0x2e0a(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    123b <main+0xcb>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <fprintf@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    0x0(%r13),%edi
call   1090 <fflush@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x2000,%esi
call   1060 <fgets@plt>
test   %rax,%rax
jne    11d0 <main+0x60>
xor    %eax,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [5 x i8] c"PING\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [6 x i8] c"PONG\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [8192 x i8]
%3 = alloca i64
store i32 0, i32* %1
br label %4
4: ; preds = %20, %0
%5 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %5, i32 8192, i32 %6)
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %27
9: ; preds = %4
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = sub i64 %12, 1
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 %13
store i8 0, i8* %14
%15 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = call i32 (...) @abort()
unreachable
20: ; preds = %9
%21 = load i32, i32* @stderr
%22 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @stdout
%26 = call i32 @fflush(i32 %25)
br label %4
27: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [5 x i8] c"PING\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
@str = [5 x i8] c"PONG\00"
define i32 @main() {
%1 = alloca [8192 x i8]
%2 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32* @fgets(i8* %2, i32 8192, i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %23, label %6
6: ; preds = %0, %14
%7 = call i64 @strlen(i8* %2)
%8 = add i64 %7, -1
%9 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 %8
store i8 0, i8* %9
%10 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %6
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%18 = load i32, i32* @stdout
%19 = call i32 @fflush(i32 %18)
%20 = load i32, i32* @stdin
%21 = call i32* @fgets(i8* %2, i32 8192, i32 %20)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %6
23: ; preds = %14, %0
ret i32 0
}