#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 atoi(char const *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getprogname();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
size_t strlen(char *);
int main(int argc, const char *argv[]) {
  if (argc < 2) {
    fprintf(stderr, "usage: %s nping\n", getprogname());
    return 1;
  }
  int n = atoi(argv[1]);
  int i;
  for (i = 0; i < n; i++) {
    printf("PING\n");
    fflush(stdout);
    char buf[8192];
    if (fgets(buf, sizeof(buf), stdin) == NULL) {
      abort();
    }
    size_t len = strlen(buf);
    buf[len - 1] = '\0';
    if (strcmp(buf, "PONG") != 0) {
      abort();
    }
    fprintf(stderr, "%s\n", buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ea <main+0x5a>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x202c(%rbp)
mov    $0x0,%al
call   1050 <getprogname@plt>
mov    -0x202c(%rbp),%edi
mov    %rax,%rdx
lea    0xe27(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cd <main+0x13d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12c6 <main+0x136>
lea    0xdfd(%rip),%rdi
call   1060 <printf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
lea    -0x2020(%rbp),%rdi
mov    0x2db3(%rip),%rax
mov    (%rax),%edx
mov    $0x2000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    1252 <main+0xc2>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x2020(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x2028(%rbp)
mov    -0x2028(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x2020(%rbp,%rax,1)
lea    -0x2020(%rbp),%rdi
lea    0xd91(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     129c <main+0x10c>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    -0x2020(%rbp),%rdx
lea    0xd69(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1201 <main+0x71>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2008,%rsp
cmp    $0x1,%edi
jg     11d1 <main+0x41>
mov    0x2e2b(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1060 <getprogname@plt>
lea    0xe43(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1090 <fprintf@plt>
mov    $0x1,%eax
jmp    1271 <main+0xe1>
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
xor    %eax,%eax
test   %ebp,%ebp
jle    1271 <main+0xe1>
mov    0x2dfb(%rip),%r15
mov    %rsp,%rbx
lea    0xe1a(%rip),%r12
mov    0x2dda(%rip),%r14
lea    0xe11(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe03(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x2000,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     1283 <main+0xf3>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1283 <main+0xf3>
mov    (%r14),%edi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1090 <fprintf@plt>
add    $0xffffffff,%ebp
jne    1210 <main+0x80>
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):
@stderr = global i32 0
@.str = [17 x i8] c"usage: %s nping\0A\00"
@.str.1 = [6 x i8] c"PING\0A\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.2 = [5 x i8] c"PONG\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [8192 x i8]
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i8* (...) @getprogname()
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %54
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
store i32 0, i32* %7
br label %21
21: ; preds = %50, %16
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %53
25: ; preds = %21
%26 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = call i32 @fflush(i32 %27)
%29 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%30 = load i32, i32* @stdin
%31 = call i32* @fgets(i8* %29, i32 8192, i32 %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = call i32 (...) @abort()
unreachable
35: ; preds = %25
%36 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%37 = call i64 @strlen(i8* %36)
store i64 %37, i64* %9
%38 = load i64, i64* %9
%39 = sub i64 %38, 1
%40 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 %39
store i8 0, i8* %40
%41 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %35
%45 = call i32 (...) @abort()
unreachable
46: ; preds = %35
%47 = load i32, i32* @stderr
%48 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%49 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %46
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %21
53: ; preds = %21
store i32 0, i32* %3
br label %54
54: ; preds = %53, %12
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"usage: %s nping\0A\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.2 = [5 x i8] c"PONG\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@str = [5 x i8] c"PING\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8192 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i8* (...) @getprogname()
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %39
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %39
14: ; preds = %9
%15 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
br label %16
16: ; preds = %14, %34
%17 = phi i32 [ 0, %14 ], [ %37, %34 ]
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%19 = load i32, i32* @stdout
%20 = call i32 @fflush(i32 %19)
%21 = load i32, i32* @stdin
%22 = call i32* @fgets(i8* %15, i32 8192, i32 %21)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %16
%27 = call i64 @strlen(i8* %15)
%28 = add i64 %27, -1
%29 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 %28
store i8 0, i8* %29
%30 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %26
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%37 = add nuw nsw i32 %17, 1
%38 = icmp eq i32 %37, %12
br i1 %38, label %39, label %16
39: ; preds = %34, %9, %5
%40 = phi i32 [ 1, %5 ], [ 0, %9 ], [ 0, %34 ]
ret i32 %40
}