#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*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(char *, int, int, int /*<<< orphan*/);
size_t fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  char buf[1024];
  size_t nBytes;
  int idx;
  for (idx = 0; idx < 10; idx++) {
    memset(buf, 0, sizeof(buf));
    nBytes = fread(buf, 1, 5, stdin);
    fprintf(stderr, "pong process: received \"%s\"\n", buf);
    if (nBytes != 5) {
      fprintf(stderr, "pong process: expected 5 bytes but got %d bytes\n",
              nBytes);
      exit(1);
    }
    if (strcmp(buf, "ping") != 0) {
      fprintf(stderr, "pong process: expected \"ping\" but got \"%s\"\n", buf);
      exit(1);
    }
    strcpy(buf, "pong");
    fprintf(stderr, "pong process: sending \"%s\"\n", buf);
    nBytes = fwrite(buf, 1, 5, stdout);
    if (nBytes != 5) {
      fprintf(stderr, "pong process: fwrite failed\n");
      exit(1);
    }
    fflush(stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x41c(%rbp)
cmpl   $0xa,-0x41c(%rbp)
jge    132a <main+0x1aa>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e17(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x5,%edx
call   1040 <fread@plt>
mov    %rax,-0x418(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpq   $0x5,-0x418(%rbp)
05
je     123d <main+0xbd>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    -0x418(%rbp),%rdx
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x410(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1282 <main+0x102>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x410(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2d0f(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x5,%edx
call   10a0 <fwrite@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x5,-0x418(%rbp)
05
je     1308 <main+0x188>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
jmp    11a3 <main+0x23>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    $0xa,%r14d
mov    %rsp,%rbx
mov    0x2e37(%rip),%r15
lea    0xedc(%rip),%r13
mov    0x2e21(%rip),%r12
nop
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1040 <fread@plt>
mov    %rax,%rbp
mov    (%r15),%edi
lea    0xe19(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
cmp    $0x5,%rbp
jne    126d <main+0xed>
mov    %rbx,%rdi
lea    0xe4d(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    127c <main+0xfc>
mov    %rbx,%rdi
lea    0xe6a(%rip),%rsi
call   1030 <strcpy@plt>
mov    (%r15),%edi
mov    %r13,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%r12),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   10a0 <fwrite@plt>
cmp    $0x5,%rax
jne    129a <main+0x11a>
mov    (%r12),%edi
call   1080 <fflush@plt>
add    $0xffffffff,%r14d
jne    11b0 <main+0x30>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15),%edi
lea    0xda6(%rip),%rsi
mov    %rbp,%rdx
jmp    1289 <main+0x109>
mov    (%r15),%edi
lea    0xdcd(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    (%r15),%edi
lea    0xdfc(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"pong process: received \22%s\22\0A\00"
@.str.1 = [49 x i8] c"pong process: expected 5 bytes but got %d bytes\0A\00"
@.str.2 = [5 x i8] c"ping\00"
@.str.3 = [44 x i8] c"pong process: expected \22ping\22 but got \22%s\22\0A\00"
@.str.4 = [5 x i8] c"pong\00"
@.str.5 = [28 x i8] c"pong process: sending \22%s\22\0A\00"
@stdout = global i32 0
@.str.6 = [29 x i8] c"pong process: fwrite failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %9
9: ; preds = %55, %2
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %58
12: ; preds = %9
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 1024)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i64 @fread(i8* %15, i32 1, i32 5, i32 %16)
store i64 %17, i64* %7
%18 = load i32, i32* @stderr
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i64, i64* %7
%22 = icmp ne i64 %21, 5
br i1 %22, label %23, label %28
23: ; preds = %12
%24 = load i32, i32* @stderr
%25 = load i64, i64* %7
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i64 %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %12
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %28
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%39 = call i32 @strcpy(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32, i32* @stderr
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%44 = load i32, i32* @stdout
%45 = call i64 @fwrite(i8* %43, i32 1, i32 5, i32 %44)
store i64 %45, i64* %7
%46 = load i64, i64* %7
%47 = icmp ne i64 %46, 5
br i1 %47, label %48, label %52
48: ; preds = %37
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %37
%53 = load i32, i32* @stdout
%54 = call i32 @fflush(i32 %53)
br label %55
55: ; preds = %52
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %9
58: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"pong process: received \22%s\22\0A\00"
@.str.1 = [49 x i8] c"pong process: expected 5 bytes but got %d bytes\0A\00"
@.str.2 = [5 x i8] c"ping\00"
@.str.3 = [44 x i8] c"pong process: expected \22ping\22 but got \22%s\22\0A\00"
@.str.4 = [5 x i8] c"pong\00"
@.str.5 = [28 x i8] c"pong process: sending \22%s\22\0A\00"
@stdout = global i32 0
@.str.6 = [29 x i8] c"pong process: fwrite failed\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %35
%6 = phi i32 [ 0, %2 ], [ %38, %35 ]
%7 = call i32 @memset(i8* %4, i32 0, i32 1024)
%8 = load i32, i32* @stdin
%9 = call i64 @fread(i8* %4, i32 1, i32 5, i32 %8)
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %4)
%12 = icmp eq i64 %9, 5
br i1 %12, label %17, label %13
13: ; preds = %5
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i64 %9)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %5
%18 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %17
%25 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%28 = load i32, i32* @stdout
%29 = call i64 @fwrite(i8* %4, i32 1, i32 5, i32 %28)
%30 = icmp eq i64 %29, 5
br i1 %30, label %35, label %31
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %24
%36 = load i32, i32* @stdout
%37 = call i32 @fflush(i32 %36)
%38 = add nuw nsw i32 %6, 1
%39 = icmp eq i32 %38, 10
br i1 %39, label %40, label %5
40: ; preds = %35
ret i32 0
}