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

/* Variables and functions */
int Read(int, char *, int);
int /*<<< orphan*/ ready(int, int);
void receiver(unsigned int num_packets, int in_fd, int ready_out, int wakefd) {
  unsigned int i;
  ready(ready_out, wakefd);
  for (i = 0; i < num_packets; i++) {
    char data[100];
    int ret, done = 0;
  again:
    ret = Read(in_fd, data + done, 100 - done);
    done += ret;
    if (done < 100)
      goto again;
  }
}


x86 assembly (clang, -O0):
<receiver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <ready@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11bd <receiver+0x9d>
movl   $0x0,-0x88(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
movslq -0x88(%rbp),%rax
add    %rax,%rsi
mov    $0x64,%edx
sub    -0x88(%rbp),%edx
call   1030 <Read@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
add    -0x88(%rbp),%eax
mov    %eax,-0x88(%rbp)
cmpl   $0x64,-0x88(%rbp)
jge    11aa <receiver+0x8a>
jmp    115f <receiver+0x3f>
jmp    11af <receiver+0x8f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1149 <receiver+0x29>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receiver>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
mov    %edx,%edi
mov    %ecx,%esi
call   1040 <ready@plt>
test   %r14d,%r14d
je     1175 <receiver+0x55>
xor    %r15d,%r15d
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %eax,%rbp
lea    (%rsp,%rbp,1),%rsi
mov    $0x64,%edx
sub    %ebp,%edx
mov    %ebx,%edi
call   1030 <Read@plt>
add    %ebp,%eax
cmp    $0x64,%eax
jl     1150 <receiver+0x30>
add    $0x1,%r15d
cmp    %r14d,%r15d
jne    1140 <receiver+0x20>
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @receiver(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [100 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = call i32 @ready(i32 %13, i32 %14)
store i32 0, i32* %9
br label %16
16: ; preds = %37, %4
%17 = load i32, i32* %9
%18 = load i32, i32* %5
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %40
20: ; preds = %16
store i32 0, i32* %12
br label %21
21: ; preds = %35, %20
%22 = load i32, i32* %6
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%24 = load i32, i32* %12
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i32, i32* %12
%28 = sub nsw i32 100, %27
%29 = call i32 @Read(i32 %22, i8* %26, i32 %28)
store i32 %29, i32* %11
%30 = load i32, i32* %11
%31 = load i32, i32* %12
%32 = add nsw i32 %31, %30
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = icmp slt i32 %33, 100
br i1 %34, label %35, label %36
35: ; preds = %21
br label %21
36: ; preds = %21
br label %37
37: ; preds = %36
%38 = load i32, i32* %9
%39 = add i32 %38, 1
store i32 %39, i32* %9
br label %16
40: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @receiver(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [100 x i8]
%6 = tail call i32 @ready(i32 %2, i32 %3)
%7 = icmp eq i32 %0, 0
br i1 %7, label %23, label %8
8: ; preds = %4
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
br label %10
10: ; preds = %8, %20
%11 = phi i32 [ 0, %8 ], [ %21, %20 ]
br label %12
12: ; preds = %12, %10
%13 = phi i32 [ 0, %10 ], [ %18, %12 ]
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %14
%16 = sub nsw i32 100, %13
%17 = call i32 @Read(i32 %1, i8* %15, i32 %16)
%18 = add nsw i32 %17, %13
%19 = icmp slt i32 %18, 100
br i1 %19, label %12, label %20
20: ; preds = %12
%21 = add nuw i32 %11, 1
%22 = icmp eq i32 %21, %0
br i1 %22, label %23, label %10
23: ; preds = %20, %4
ret void
}