#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*/ memcpy(unsigned char *, unsigned char const *, long);
void fileio_copy_blocks(unsigned char *dptr, const unsigned char *sptr,
                        long size, int block) {
  long len;
  while (size > 0) {
    if (size > 128)
      *dptr = block++;
    else
      *dptr = 0xff;
    len = (size > 128) ? 128 : size;
    memcpy(dptr + 1, sptr, len);
    dptr += 129;
    sptr += 128;
    size -= 128;
  }
}


x86 assembly (clang, -O0):
<fileio_copy_blocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    11cf <fileio_copy_blocks+0xbf>
cmpq   $0x80,-0x18(%rbp)
jle    1158 <fileio_copy_blocks+0x48>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
jmp    115f <fileio_copy_blocks+0x4f>
mov    -0x8(%rbp),%rax
movb   $0xff,(%rax)
cmpq   $0x80,-0x18(%rbp)
jle    117b <fileio_copy_blocks+0x6b>
mov    $0x80,%eax
mov    %rax,-0x30(%rbp)
jmp    1183 <fileio_copy_blocks+0x73>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x81,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x80,%rax
mov    %rax,-0x18(%rbp)
jmp    1127 <fileio_copy_blocks+0x17>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileio_copy_blocks>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdx,%rdx
jle    1175 <fileio_copy_blocks+0x65>
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rbp
mov    $0x80,%r12d
nop
cmp    $0x81,%rbx
mov    %rbx,%rdx
cmovae %r12,%rdx
mov    $0xff,%eax
cmovae %r14d,%eax
sbb    $0xffffffff,%r14d
mov    %al,0x0(%rbp)
lea    0x1(%rbp),%rdi
mov    %r15,%rsi
call   1030 <memcpy@plt>
sub    $0xffffffffffffff80,%r15
lea    -0x80(%rbx),%rax
add    $0x81,%rbp
cmp    $0x80,%rbx
mov    %rax,%rbx
ja     1130 <fileio_copy_blocks+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @fileio_copy_blocks(i8* %0, i8* %1, i64 %2, i32 %3) {
%5 = icmp sgt i64 %2, 0
br i1 %5, label %6, label %23
6: ; preds = %4, %6
%7 = phi i8* [ %19, %6 ], [ %0, %4 ]
%8 = phi i32 [ %16, %6 ], [ %3, %4 ]
%9 = phi i64 [ %21, %6 ], [ %2, %4 ]
%10 = phi i8* [ %20, %6 ], [ %1, %4 ]
%11 = icmp ugt i64 %9, 128
%12 = trunc i32 %8 to i8
%13 = select i1 %11, i64 128, i64 %9
%14 = select i1 %11, i8 %12, i8 -1
%15 = zext i1 %11 to i32
%16 = add nsw i32 %8, %15
store i8 %14, i8* %7
%17 = getelementptr inbounds i8, i8* %7, i64 1
%18 = tail call i32 @memcpy(i8* %17, i8* %10, i64 %13)
%19 = getelementptr inbounds i8, i8* %7, i64 129
%20 = getelementptr inbounds i8, i8* %10, i64 128
%21 = add nsw i64 %9, -128
%22 = icmp ugt i64 %9, 128
br i1 %22, label %6, label %23
23: ; preds = %6, %4
ret void
}