#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 */
typedef int /*<<< orphan*/ pattern;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(char *, unsigned long, int);
char *mk_alt(size_t size) {
  unsigned long int pattern = 0x0;
  for (size_t x = 0; x < (0x8 * sizeof(pattern)); x++) {
    pattern = (pattern << 1) | (x % 2);
  }
  char *ptr = (char *)malloc(size);
  assert(ptr != NULL);
  for (size_t i = 0; i < size; i += sizeof(pattern)) {
    memset(ptr + i, pattern, sizeof(pattern));
  }
  return ptr;
}


x86 assembly (clang, -O0):
<mk_alt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x40,-0x18(%rbp)
jae    117f <mk_alt+0x4f>
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    -0x18(%rbp),%rcx
and    $0x1,%rcx
or     %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114c <mk_alt+0x1c>
mov    -0x8(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11db <mk_alt+0xab>
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    11a6 <mk_alt+0x76>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mk_alt>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <malloc@plt>
mov    %rax,%r12
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
test   %r14,%r14
je     118a <mk_alt+0x5a>
xor    %ebx,%ebx
movabs $0x5555555555555555,%r15
55 55 55
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r12,%rbx,1),%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <memset@plt>
add    $0x8,%rbx
cmp    %r14,%rbx
jb     1170 <mk_alt+0x40>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @mk_alt(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i64 %0, i64* %2
store i64 0, i64* %3
store i64 0, i64* %4
br label %7
7: ; preds = %16, %1
%8 = load i64, i64* %4
%9 = icmp ult i64 %8, 64
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load i64, i64* %3
%12 = shl i64 %11, 1
%13 = load i64, i64* %4
%14 = urem i64 %13, 2
%15 = or i64 %12, %14
store i64 %15, i64* %3
br label %16
16: ; preds = %10
%17 = load i64, i64* %4
%18 = add i64 %17, 1
store i64 %18, i64* %4
br label %7
19: ; preds = %7
%20 = load i64, i64* %2
%21 = call i64 @malloc(i64 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
store i64 0, i64* %6
br label %27
27: ; preds = %37, %19
%28 = load i64, i64* %6
%29 = load i64, i64* %2
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = load i8*, i8** %5
%33 = load i64, i64* %6
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i64, i64* %3
%36 = call i32 @memset(i8* %34, i64 %35, i32 8)
br label %37
37: ; preds = %31
%38 = load i64, i64* %6
%39 = add i64 %38, 8
store i64 %39, i64* %6
br label %27
40: ; preds = %27
%41 = load i8*, i8** %5
ret i8* %41
}

LLVM IR (-O2):
define i8* @mk_alt(i64 %0) {
%2 = tail call i64 @malloc(i64 %0)
%3 = inttoptr i64 %2 to i8*
%4 = icmp ne i64 %2, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp eq i64 %0, 0
br i1 %7, label %8, label %9
8: ; preds = %9, %1
ret i8* %3
9: ; preds = %1, %9
%10 = phi i64 [ %13, %9 ], [ 0, %1 ]
%11 = getelementptr inbounds i8, i8* %3, i64 %10
%12 = tail call i32 @memset(i8* %11, i64 6148914691236517205, i32 8)
%13 = add i64 %10, 8
%14 = icmp ult i64 %13, %0
br i1 %14, label %9, label %8
}