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

/* Variables and functions */
int /*<<< orphan*/ barf(char *);
int /*<<< orphan*/ ready(int, int);
int write(int, char *, int);
void sender(int out_fd[20], int ready_out, int wakefd) {
  char data[100];
  unsigned int i, j;
  ready(ready_out, wakefd);
  for (i = 0; i < 100; i++) {
    for (j = 0; j < 20; j++) {
      int ret;
      unsigned long done = 0;
    again:
      ret = write(out_fd[j], data + done, sizeof(data) - done);
      if (ret < 0)
        barf("SENDER: write");
      done += ret;
      if (done < sizeof(data))
        goto again;
    }
  }
}


x86 assembly (clang, -O0):
<sender>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <ready@plt>
movl   $0x0,-0x84(%rbp)
cmpl   $0x64,-0x84(%rbp)
jae    122d <sender+0xfd>
movl   $0x0,-0x88(%rbp)
cmpl   $0x14,-0x88(%rbp)
jae    1214 <sender+0xe4>
movq   $0x0,-0x98(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x88(%rbp),%ecx
mov    (%rax,%rcx,4),%edi
lea    -0x80(%rbp),%rsi
add    -0x98(%rbp),%rsi
mov    $0x64,%eax
sub    -0x98(%rbp),%rax
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
jge    11d3 <sender+0xa3>
lea    0xe32(%rip),%rdi
call   1030 <barf@plt>
movslq -0x8c(%rbp),%rax
add    -0x98(%rbp),%rax
mov    %rax,-0x98(%rbp)
cmpq   $0x64,-0x98(%rbp)
64
jae    11fb <sender+0xcb>
jmp    1189 <sender+0x59>
jmp    1200 <sender+0xd0>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1171 <sender+0x41>
jmp    1219 <sender+0xe9>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    115a <sender+0x2a>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sender>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%r12
mov    %esi,%edi
mov    %edx,%esi
call   1050 <ready@plt>
xor    %r15d,%r15d
lea    0xeac(%rip),%r14
jmp    116a <sender+0x3a>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15d
cmp    $0x64,%r15d
je     11b0 <sender+0x80>
xor    %r13d,%r13d
jmp    117a <sender+0x4a>
nop
add    $0x1,%r13
cmp    $0x14,%r13
je     1160 <sender+0x30>
xor    %ebx,%ebx
jmp    118c <sender+0x5c>
xchg   %ax,%ax
movslq %ebp,%rax
add    %rax,%rbx
cmp    $0x64,%rbx
jae    1170 <sender+0x40>
mov    (%r12,%r13,4),%edi
lea    (%rsp,%rbx,1),%rsi
mov    $0x64,%edx
sub    %ebx,%edx
call   1040 <write@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1180 <sender+0x50>
mov    %r14,%rdi
call   1030 <barf@plt>
jmp    1180 <sender+0x50>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"SENDER: write\00"
define void @sender(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = call i32 @ready(i32 %12, i32 %13)
store i32 0, i32* %8
br label %15
15: ; preds = %53, %3
%16 = load i32, i32* %8
%17 = icmp ult i32 %16, 100
br i1 %17, label %18, label %56
18: ; preds = %15
store i32 0, i32* %9
br label %19
19: ; preds = %49, %18
%20 = load i32, i32* %9
%21 = icmp ult i32 %20, 20
br i1 %21, label %22, label %52
22: ; preds = %19
store i64 0, i64* %11
br label %23
23: ; preds = %47, %22
%24 = load i32*, i32** %4
%25 = load i32, i32* %9
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%30 = load i64, i64* %11
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i64, i64* %11
%33 = sub i64 100, %32
%34 = trunc i64 %33 to i32
%35 = call i32 @write(i32 %28, i8* %31, i32 %34)
store i32 %35, i32* %10
%36 = load i32, i32* %10
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %23
%39 = call i32 @barf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %40
40: ; preds = %38, %23
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = load i64, i64* %11
%44 = add i64 %43, %42
store i64 %44, i64* %11
%45 = load i64, i64* %11
%46 = icmp ult i64 %45, 100
br i1 %46, label %47, label %48
47: ; preds = %40
br label %23
48: ; preds = %40
br label %49
49: ; preds = %48
%50 = load i32, i32* %9
%51 = add i32 %50, 1
store i32 %51, i32* %9
br label %19
52: ; preds = %19
br label %53
53: ; preds = %52
%54 = load i32, i32* %8
%55 = add i32 %54, 1
store i32 %55, i32* %8
br label %15
56: ; preds = %15
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"SENDER: write\00"
define void @sender(i32* nocapture %0, i32 %1, i32 %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @ready(i32 %1, i32 %2)
br label %7
7: ; preds = %3, %29
%8 = phi i32 [ 0, %3 ], [ %30, %29 ]
br label %9
9: ; preds = %7, %26
%10 = phi i64 [ 0, %7 ], [ %27, %26 ]
%11 = getelementptr inbounds i32, i32* %0, i64 %10
br label %12
12: ; preds = %9, %22
%13 = phi i64 [ %24, %22 ], [ 0, %9 ]
%14 = load i32, i32* %11
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %13
%16 = trunc i64 %13 to i32
%17 = sub nuw nsw i32 100, %16
%18 = call i32 @write(i32 %14, i8* %15, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = tail call i32 @barf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %12
%23 = sext i32 %18 to i64
%24 = add nsw i64 %13, %23
%25 = icmp ult i64 %24, 100
br i1 %25, label %12, label %26
26: ; preds = %22
%27 = add nuw nsw i64 %10, 1
%28 = icmp eq i64 %27, 20
br i1 %28, label %29, label %9
29: ; preds = %26
%30 = add nuw nsw i32 %8, 1
%31 = icmp eq i32 %30, 100
br i1 %31, label %32, label %7
32: ; preds = %29
ret void
}