#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 /*<<< orphan*/ read_util(int, char **, int);
int /*<<< orphan*/ write_util(int, char **, int);
void read_write_data(int readfd, int writefd, size_t size) {
  char data[512];
  size_t i;
  int len;
  i = 0;
  while (i < size) {
    len = size - i;
    len = ((len < 512) ? len : 512);
    read_util(readfd, &data, len);
    write_util(writefd, &data, len);
    i += len;
  }
}


x86 assembly (clang, -O0):
<read_write_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movq   $0x0,-0x218(%rbp)
mov    -0x218(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11e3 <read_write_data+0xc3>
mov    -0x10(%rbp),%rax
sub    -0x218(%rbp),%rax
mov    %eax,-0x21c(%rbp)
cmpl   $0x200,-0x21c(%rbp)
jge    1183 <read_write_data+0x63>
mov    -0x21c(%rbp),%eax
mov    %eax,-0x220(%rbp)
jmp    1193 <read_write_data+0x73>
mov    $0x200,%eax
mov    %eax,-0x220(%rbp)
jmp    1193 <read_write_data+0x73>
mov    -0x220(%rbp),%eax
mov    %eax,-0x21c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    -0x21c(%rbp),%edx
call   1040 <read_util@plt>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    -0x21c(%rbp),%edx
call   1030 <write_util@plt>
movslq -0x21c(%rbp),%rax
add    -0x218(%rbp),%rax
mov    %rax,-0x218(%rbp)
jmp    1140 <read_write_data+0x20>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_write_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
test   %rdx,%rdx
je     1188 <read_write_data+0x68>
mov    %rdx,%r13
mov    %esi,%r14d
mov    %edi,%r15d
xor    %ebx,%ebx
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13d,%ebp
sub    %ebx,%ebp
cmp    $0x200,%ebp
mov    $0x200,%eax
cmovge %eax,%ebp
mov    %r15d,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <read_util@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1030 <write_util@plt>
movslq %ebp,%rax
add    %rax,%rbx
cmp    %r13,%rbx
jb     1150 <read_write_data+0x30>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @read_write_data(i32 %0, i32 %1, i64 %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = icmp eq i64 %2, 0
br i1 %6, label %20, label %7
7: ; preds = %3
%8 = bitcast [512 x i8]* %4 to i8**
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %18, %9 ]
%11 = sub i64 %2, %10
%12 = trunc i64 %11 to i32
%13 = icmp slt i32 %12, 512
%14 = select i1 %13, i32 %12, i32 512
%15 = call i32 @read_util(i32 %0, i8** %8, i32 %14)
%16 = call i32 @write_util(i32 %1, i8** %8, i32 %14)
%17 = sext i32 %14 to i64
%18 = add i64 %10, %17
%19 = icmp ult i64 %18, %2
br i1 %19, label %9, label %20
20: ; preds = %9, %3
ret void
}