#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*/ assert(int);
char *fetch_str(int);
int /*<<< orphan*/ memcpy(void *, char *, int);
int prefetch_strlen();
void fetch256(void *buf) {
  int l = prefetch_strlen();
  assert(l >= 0);
  char *s = fetch_str(l);
  if (l < 256) {
    memcpy(buf + 256 - l, s, l);
  } else {
    memcpy(buf, s + (l - 256), 256);
  }
}


x86 assembly (clang, -O0):
<fetch256>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <prefetch_strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xc(%rbp),%edi
call   1040 <fetch_str@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x100,-0xc(%rbp)
jge    11a8 <fetch256+0x68>
mov    -0x8(%rbp),%rdi
add    $0x100,%rdi
movslq -0xc(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <memcpy@plt>
jmp    11c7 <fetch256+0x87>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%eax
sub    $0x100,%eax
cltq
add    %rax,%rsi
mov    $0x100,%edx
call   1060 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fetch256>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <prefetch_strlen@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1050 <assert@plt>
mov    %ebx,%edi
call   1040 <fetch_str@plt>
cmp    $0xff,%ebx
jg     1182 <fetch256+0x42>
movslq %ebx,%rcx
sub    %rcx,%r14
add    $0x100,%r14
mov    %r14,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
jmp    1196 <fetch256+0x56>
add    $0xffffff00,%ebx
add    %rbx,%rax
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x100,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <memcpy@plt>

LLVM IR (-O0):
define void @fetch256(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i32 (...) @prefetch_strlen()
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %3
%11 = call i8* @fetch_str(i32 %10)
store i8* %11, i8** %4
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 256
br i1 %13, label %14, label %24
14: ; preds = %1
%15 = load i8*, i8** %2
%16 = getelementptr i8, i8* %15, i64 256
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = sub i64 0, %18
%20 = getelementptr i8, i8* %16, i64 %19
%21 = load i8*, i8** %4
%22 = load i32, i32* %3
%23 = call i32 @memcpy(i8* %20, i8* %21, i32 %22)
br label %32
24: ; preds = %1
%25 = load i8*, i8** %2
%26 = load i8*, i8** %4
%27 = load i32, i32* %3
%28 = sub nsw i32 %27, 256
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = call i32 @memcpy(i8* %25, i8* %30, i32 256)
br label %32
32: ; preds = %24, %14
ret void
}

LLVM IR (-O2):
define void @fetch256(i8* %0) {
%2 = tail call i32 (...) @prefetch_strlen()
%3 = xor i32 %2, -1
%4 = lshr i32 %3, 31
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i8* @fetch_str(i32 %2)
%7 = icmp slt i32 %2, 256
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = getelementptr i8, i8* %0, i64 256
%10 = sext i32 %2 to i64
%11 = sub nsw i64 0, %10
%12 = getelementptr i8, i8* %9, i64 %11
%13 = tail call i32 @memcpy(i8* %12, i8* %6, i32 %2)
br label %19
14: ; preds = %1
%15 = add nsw i32 %2, -256
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %6, i64 %16
%18 = tail call i32 @memcpy(i8* %0, i8* %17, i32 256)
br label %19
19: ; preds = %14, %8
ret void
}