#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 */
unsigned int cache_size();
unsigned char *malloc(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int);
void fallback_clearcache(void) {
  static unsigned char *clearmem;
  unsigned cs = cache_size();
  unsigned i;
  if (!clearmem)
    clearmem = malloc(cs);
  if (!clearmem) {
    printf("Warning: cannot allocate %u bytes of clear cache buffer\n", cs);
    return;
  }
  for (i = 0; i < cs; i += 32)
    clearmem[i] = 1;
}


x86 assembly (clang, -O0):
<fallback_clearcache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <cache_size@plt>
mov    %eax,-0x4(%rbp)
cmpq   $0x0,0x2ef6(%rip)
jne    115f <fallback_clearcache+0x2f>
mov    -0x4(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,0x2ee1(%rip)
cmpq   $0x0,0x2ed9(%rip)
jne    1181 <fallback_clearcache+0x51>
mov    -0x4(%rbp),%esi
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
jmp    11b0 <fallback_clearcache+0x80>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11b0 <fallback_clearcache+0x80>
mov    0x2ea5(%rip),%rax
mov    -0x8(%rbp),%ecx
movb   $0x1,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x8(%rbp)
jmp    1188 <fallback_clearcache+0x58>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fallback_clearcache>:
push   %rbx
xor    %eax,%eax
call   1050 <cache_size@plt>
mov    %eax,%ebx
mov    0x2eff(%rip),%rax
test   %rax,%rax
jne    115d <fallback_clearcache+0x2d>
mov    %ebx,%edi
call   1040 <malloc@plt>
mov    %rax,0x2eec(%rip)
test   %rax,%rax
je     11ef <fallback_clearcache+0xbf>
test   %ebx,%ebx
je     11ed <fallback_clearcache+0xbd>
mov    %ebx,%esi
add    $0xffffffffffffffff,%rsi
mov    %rsi,%rdx
shr    $0x5,%rdx
add    $0x1,%rdx
mov    %edx,%ecx
and    $0x7,%ecx
cmp    $0xe0,%rsi
jae    1188 <fallback_clearcache+0x58>
xor    %esi,%esi
jmp    11d0 <fallback_clearcache+0xa0>
and    $0xfffffffffffffff8,%rdx
xor    %esi,%esi
xchg   %ax,%ax
movb   $0x1,(%rax,%rsi,1)
movb   $0x1,0x20(%rax,%rsi,1)
movb   $0x1,0x40(%rax,%rsi,1)
movb   $0x1,0x60(%rax,%rsi,1)
movb   $0x1,0x80(%rax,%rsi,1)
01
movb   $0x1,0xa0(%rax,%rsi,1)
01
movb   $0x1,0xc0(%rax,%rsi,1)
01
movb   $0x1,0xe0(%rax,%rsi,1)
01
add    $0x100,%rsi
add    $0xfffffffffffffff8,%rdx
jne    1190 <fallback_clearcache+0x60>
test   %rcx,%rcx
je     11ed <fallback_clearcache+0xbd>
add    %rsi,%rax
shl    $0x5,%rcx
xor    %edx,%edx
xchg   %ax,%ax
movb   $0x1,(%rax,%rdx,1)
add    $0x20,%rdx
cmp    %rdx,%rcx
jne    11e0 <fallback_clearcache+0xb0>
pop    %rbx
ret
lea    0xe0a(%rip),%rdi
mov    %ebx,%esi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@fallback_clearcache.clearmem = internal global i8* null
@.str = [57 x i8] c"Warning: cannot allocate %u bytes of clear cache buffer\0A\00"
define void @fallback_clearcache() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @cache_size()
store i32 %3, i32* %1
%4 = load i8*, i8** @fallback_clearcache.clearmem
%5 = icmp ne i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = load i32, i32* %1
%8 = call i8* @malloc(i32 %7)
store i8* %8, i8** @fallback_clearcache.clearmem
br label %9
9: ; preds = %6, %0
%10 = load i8*, i8** @fallback_clearcache.clearmem
%11 = icmp ne i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* %1
%14 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %28
15: ; preds = %9
store i32 0, i32* %2
br label %16
16: ; preds = %25, %15
%17 = load i32, i32* %2
%18 = load i32, i32* %1
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i8*, i8** @fallback_clearcache.clearmem
%22 = load i32, i32* %2
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 1, i8* %24
br label %25
25: ; preds = %20
%26 = load i32, i32* %2
%27 = add i32 %26, 32
store i32 %27, i32* %2
br label %16
28: ; preds = %12, %16
ret void
}

LLVM IR (-O2):
@fallback_clearcache.clearmem = internal unnamed_addr global i8* null
@.str = [57 x i8] c"Warning: cannot allocate %u bytes of clear cache buffer\0A\00"
define void @fallback_clearcache() {
%1 = tail call i32 (...) @cache_size()
%2 = load i8*, i8** @fallback_clearcache.clearmem
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i8* @malloc(i32 %1)
store i8* %5, i8** @fallback_clearcache.clearmem
%6 = icmp eq i8* %5, null
br i1 %6, label %19, label %7
7: ; preds = %0, %4
%8 = phi i8* [ %5, %4 ], [ %2, %0 ]
%9 = icmp eq i32 %1, 0
br i1 %9, label %52, label %10
10: ; preds = %7
%11 = zext i32 %1 to i64
%12 = add nsw i64 %11, -1
%13 = lshr i64 %12, 5
%14 = add nuw nsw i64 %13, 1
%15 = and i64 %14, 7
%16 = icmp ult i64 %12, 224
br i1 %16, label %42, label %17
17: ; preds = %10
%18 = and i64 %14, 1152921504606846968
br label %21
19: ; preds = %4
%20 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %52
21: ; preds = %21, %17
%22 = phi i64 [ 0, %17 ], [ %39, %21 ]
%23 = phi i64 [ 0, %17 ], [ %40, %21 ]
%24 = getelementptr inbounds i8, i8* %8, i64 %22
store i8 1, i8* %24
%25 = or i64 %22, 32
%26 = getelementptr inbounds i8, i8* %8, i64 %25
store i8 1, i8* %26
%27 = or i64 %22, 64
%28 = getelementptr inbounds i8, i8* %8, i64 %27
store i8 1, i8* %28
%29 = or i64 %22, 96
%30 = getelementptr inbounds i8, i8* %8, i64 %29
store i8 1, i8* %30
%31 = or i64 %22, 128
%32 = getelementptr inbounds i8, i8* %8, i64 %31
store i8 1, i8* %32
%33 = or i64 %22, 160
%34 = getelementptr inbounds i8, i8* %8, i64 %33
store i8 1, i8* %34
%35 = or i64 %22, 192
%36 = getelementptr inbounds i8, i8* %8, i64 %35
store i8 1, i8* %36
%37 = or i64 %22, 224
%38 = getelementptr inbounds i8, i8* %8, i64 %37
store i8 1, i8* %38
%39 = add nuw nsw i64 %22, 256
%40 = add i64 %23, 8
%41 = icmp eq i64 %40, %18
br i1 %41, label %42, label %21
42: ; preds = %21, %10
%43 = phi i64 [ 0, %10 ], [ %39, %21 ]
%44 = icmp eq i64 %15, 0
br i1 %44, label %52, label %45
45: ; preds = %42, %45
%46 = phi i64 [ %49, %45 ], [ %43, %42 ]
%47 = phi i64 [ %50, %45 ], [ 0, %42 ]
%48 = getelementptr inbounds i8, i8* %8, i64 %46
store i8 1, i8* %48
%49 = add nuw nsw i64 %46, 32
%50 = add i64 %47, 1
%51 = icmp eq i64 %50, %15
br i1 %51, label %52, label %45
52: ; preds = %42, %45, %7, %19
ret void
}