#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(unsigned char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
unsigned char *malloc(size_t);
int /*<<< orphan*/ memcpy(unsigned char *, char *, int);
int /*<<< orphan*/ printf(char *, long long);
unsigned char *create_chess_block(long long offset, int sector_size,
                                  long long size, int counter) {
  char *pattern1 = "\xFF\x0";
  char *pattern2 = "\x0\xFF";
  int c;
  unsigned char *retval = malloc((size_t)size);
  assert(retval);
  if (size % 2) {
    exit(
        printf("sorry, test pattern do not fit in block size (%I64d)\n", size));
  }
  for (c = 0; c < size; c += 2) {
    if (counter % 2)
      memcpy(retval + c, pattern1, 2);
    else
      memcpy(retval + c, pattern2, 2);
  }
  return retval;
}


x86 assembly (clang, -O0):
<create_chess_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe8b(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
je     11c1 <create_chess_block+0x71>
mov    -0x18(%rbp),%rsi
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
mov    %eax,%edi
call   1070 <exit@plt>
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1234 <create_chess_block+0xe4>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1208 <create_chess_block+0xb8>
mov    -0x40(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
jmp    1221 <create_chess_block+0xd1>
mov    -0x40(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
jmp    1226 <create_chess_block+0xd6>
mov    -0x34(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
jmp    11c8 <create_chess_block+0x78>
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_chess_block>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rdx,%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <assert@plt>
test   $0x1,%r14b
jne    11c9 <create_chess_block+0x79>
test   %r14,%r14
jle    11ba <create_chess_block+0x6a>
test   $0x1,%bl
lea    0xe7e(%rip),%rax
lea    0xe74(%rip),%r12
cmove  %rax,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r15,%rbx,1),%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
add    $0x2,%rbx
cmp    %r14,%rbx
jl     11a0 <create_chess_block+0x50>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe36(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    %eax,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"\FF\00\00"
@.str.1 = [3 x i8] c"\00\FF\00"
@.str.2 = [54 x i8] c"sorry, test pattern do not fit in block size (%I64d)\0A\00"
define i8* @create_chess_block(i64 %0, i32 %1, i64 %2, i32 %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
store i64 %0, i64* %5
store i32 %1, i32* %6
store i64 %2, i64* %7
store i32 %3, i32* %8
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %10
%13 = load i64, i64* %7
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** %12
%15 = load i8*, i8** %12
%16 = call i32 @assert(i8* %15)
%17 = load i64, i64* %7
%18 = srem i64 %17, 2
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %4
%21 = load i64, i64* %7
%22 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i64 %21)
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %4
store i32 0, i32* %11
br label %25
25: ; preds = %49, %24
%26 = load i32, i32* %11
%27 = sext i32 %26 to i64
%28 = load i64, i64* %7
%29 = icmp slt i64 %27, %28
br i1 %29, label %30, label %52
30: ; preds = %25
%31 = load i32, i32* %8
%32 = srem i32 %31, 2
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = load i8*, i8** %12
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8*, i8** %9
%40 = call i32 @memcpy(i8* %38, i8* %39, i32 2)
br label %48
41: ; preds = %30
%42 = load i8*, i8** %12
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8*, i8** %10
%47 = call i32 @memcpy(i8* %45, i8* %46, i32 2)
br label %48
48: ; preds = %41, %34
br label %49
49: ; preds = %48
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 2
store i32 %51, i32* %11
br label %25
52: ; preds = %25
%53 = load i8*, i8** %12
ret i8* %53
}

LLVM IR (-O2):
@.str = [3 x i8] c"\FF\00\00"
@.str.1 = [3 x i8] c"\00\FF\00"
@.str.2 = [54 x i8] c"sorry, test pattern do not fit in block size (%I64d)\0A\00"
define i8* @create_chess_block(i64 %0, i32 %1, i64 %2, i32 %3) {
%5 = tail call i8* @malloc(i64 %2)
%6 = tail call i32 @assert(i8* %5)
%7 = and i64 %2, 1
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %4
%10 = icmp sgt i64 %2, 0
br i1 %10, label %11, label %24
11: ; preds = %9
%12 = and i32 %3, 1
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
br label %18
15: ; preds = %4
%16 = tail call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i64 %2)
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %11, %18
%19 = phi i64 [ 0, %11 ], [ %22, %18 ]
%20 = getelementptr inbounds i8, i8* %5, i64 %19
%21 = tail call i32 @memcpy(i8* %20, i8* %14, i32 2)
%22 = add nuw i64 %19, 2
%23 = icmp slt i64 %22, %2
br i1 %23, label %18, label %24
24: ; preds = %18, %9
ret i8* %5
}