#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 */
struct pollfd {
  int fd;
  int /*<<< orphan*/ events;
};

/* Variables and functions */
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ die(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
void pong(int s, int n) {
  char m[1];
  int i;
  struct pollfd fds[1];
  fds->fd = s;
  fds->events = POLLIN;
  for (i = 0; i < n; i++) {
    if (1 != recv(s, m, 1, 0))
      die("send");
    assert(m[0] == 'a' + i % 26);
    if (1 != send(s, m, 1, 0))
      die("recv");
  }
}


x86 assembly (clang, -O0):
<pong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1209 <pong+0xc9>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     11a1 <pong+0x61>
lea    0xe64(%rip),%rdi
call   1060 <die@plt>
movsbl -0x9(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
add    $0x61,%edx
cmp    %edx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     11f6 <pong+0xb6>
lea    0xe14(%rip),%rdi
call   1060 <die@plt>
jmp    11fb <pong+0xbb>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1167 <pong+0x27>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pong>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11f5 <pong+0xb5>
mov    %esi,%ebx
mov    %edi,%r13d
xor    %ebp,%ebp
mov    $0x61,%r12d
lea    0x7(%rsp),%r14
jmp    117c <pong+0x3c>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
add    $0x1,%r12d
add    $0xffffffff,%ebx
je     11f5 <pong+0xb5>
mov    %ebp,%eax
imul   $0x4ec4ec4f,%rax,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
mov    %r12d,%r15d
sub    %ecx,%r15d
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x1,%eax
je     11ba <pong+0x7a>
lea    0xe4b(%rip),%rdi
call   1060 <die@plt>
movsbl 0x7(%rsp),%eax
xor    %edi,%edi
cmp    %eax,%r15d
sete   %dil
call   1050 <assert@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x1,%eax
je     1170 <pong+0x30>
lea    0xe1a(%rip),%rdi
call   1060 <die@plt>
jmp    1170 <pong+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@.str = [5 x i8] c"send\00"
@.str.1 = [5 x i8] c"recv\00"
define void @pong(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1 x i8]
%6 = alloca i32
%7 = alloca [1 x %struct.pollfd]
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %7, i64 0, i64 0
%10 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %9, i32 0, i32 0
store i32 %8, i32* %10
%11 = load i32, i32* @POLLIN
%12 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %7, i64 0, i64 0
%13 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %12, i32 0, i32 1
store i32 %11, i32* %13
store i32 0, i32* %6
br label %14
14: ; preds = %42, %2
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %45
18: ; preds = %14
%19 = load i32, i32* %3
%20 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%21 = call i32 @recv(i32 %19, i8* %20, i32 1, i32 0)
%22 = icmp ne i32 1, %21
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i32, i32* %6
%30 = srem i32 %29, 26
%31 = add nsw i32 97, %30
%32 = icmp eq i32 %28, %31
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i32, i32* %3
%36 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%37 = call i32 @send(i32 %35, i8* %36, i32 1, i32 0)
%38 = icmp ne i32 1, %37
br i1 %38, label %39, label %41
39: ; preds = %25
%40 = call i32 @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %39, %25
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %14
45: ; preds = %14
ret void
}

LLVM IR (-O2):
@POLLIN = global i32 0
@.str = [5 x i8] c"send\00"
@.str.1 = [5 x i8] c"recv\00"
define void @pong(i32 %0, i32 %1) {
%3 = alloca [1 x i8]
%4 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %27
6: ; preds = %2, %24
%7 = phi i32 [ %25, %24 ], [ 0, %2 ]
%8 = call i32 @recv(i32 %0, i8* %4, i32 1, i32 0)
%9 = icmp eq i32 %8, 1
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = call i32 @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
%15 = urem i32 %7, 26
%16 = add nuw nsw i32 %15, 97
%17 = icmp eq i32 %16, %14
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = call i32 @send(i32 %0, i8* %4, i32 1, i32 0)
%21 = icmp eq i32 %20, 1
br i1 %21, label %24, label %22
22: ; preds = %12
%23 = call i32 @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %12, %22
%25 = add nuw nsw i32 %7, 1
%26 = icmp eq i32 %25, %1
br i1 %26, label %27, label %6
27: ; preds = %24, %2
ret void
}