#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void flushall(int yes) {
  static char *buffer = NULL;
  static char val = 1;
  if (yes) {
    if (buffer == NULL) {
      buffer = (char *)malloc(1 << 24 * sizeof(char));
      if (buffer == NULL) {
        fprintf(stderr, "flushall.c: malloc of %d bytes failed.\n", 1 << 24);
        exit(1);
      }
    }
    memset(buffer, val++, 1 << 24);
  } else {
    if (buffer) {
      free(buffer);
      buffer = NULL;
    }
  }
}


x86 assembly (clang, -O0):
<flushall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11e5 <flushall+0x95>
cmpq   $0x0,0x2eeb(%rip)
jne    11bb <flushall+0x6b>
mov    $0x1000000,%edi
call   1060 <malloc@plt>
mov    %rax,0x2ed4(%rip)
cmpq   $0x0,0x2ecc(%rip)
jne    11b6 <flushall+0x66>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    $0x1000000,%edx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11bb <flushall+0x6b>
mov    0x2e96(%rip),%rdi
mov    0x2e80(%rip),%al
mov    %al,%cl
add    $0x1,%cl
mov    %cl,0x2e75(%rip)
movsbl %al,%esi
mov    $0x1000000,%edx
call   1040 <memset@plt>
jmp    120f <flushall+0xbf>
cmpq   $0x0,0x2e6b(%rip)
je     120a <flushall+0xba>
mov    0x2e5e(%rip),%rdi
call   1030 <free@plt>
movq   $0x0,0x2e4e(%rip)
jmp    120f <flushall+0xbf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flushall>:
push   %rax
mov    %edi,%eax
mov    0x2efe(%rip),%rdi
test   %eax,%eax
je     1197 <flushall+0x47>
test   %rdi,%rdi
jne    117c <flushall+0x2c>
mov    $0x1000000,%edi
call   1060 <malloc@plt>
mov    %rax,%rdi
mov    %rax,0x2ee1(%rip)
test   %rax,%rax
je     11ae <flushall+0x5e>
movsbl 0x2ec5(%rip),%esi
lea    0x1(%rsi),%eax
mov    %al,0x2ebc(%rip)
mov    $0x1000000,%edx
pop    %rax
jmp    1040 <memset@plt>
test   %rdi,%rdi
je     11ac <flushall+0x5c>
call   1030 <free@plt>
movq   $0x0,0x2eac(%rip)
pop    %rax
ret
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
mov    $0x1000000,%edx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@flushall.buffer = internal global i8* null
@flushall.val = internal global i8 1
@stderr = global i32 0
@.str = [40 x i8] c"flushall.c: malloc of %d bytes failed.\0A\00"
define void @flushall(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp ne i32 %3, 0
br i1 %4, label %5, label %24
5: ; preds = %1
%6 = load i8*, i8** @flushall.buffer
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = call i64 @malloc(i32 16777216)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** @flushall.buffer
%11 = load i8*, i8** @flushall.buffer
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 16777216)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %8
br label %18
18: ; preds = %17, %5
%19 = load i8*, i8** @flushall.buffer
%20 = load i8, i8* @flushall.val
%21 = add i8 %20, 1
store i8 %21, i8* @flushall.val
%22 = sext i8 %20 to i32
%23 = call i32 @memset(i8* %19, i32 %22, i32 16777216)
br label %31
24: ; preds = %1
%25 = load i8*, i8** @flushall.buffer
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i8*, i8** @flushall.buffer
%29 = call i32 @free(i8* %28)
store i8* null, i8** @flushall.buffer
br label %30
30: ; preds = %27, %24
br label %31
31: ; preds = %30, %18
ret void
}

LLVM IR (-O2):
@flushall.buffer = internal unnamed_addr global i8* null
@flushall.val = internal unnamed_addr global i8 1
@stderr = global i32 0
@.str = [40 x i8] c"flushall.c: malloc of %d bytes failed.\0A\00"
define void @flushall(i32 %0) {
%2 = icmp eq i32 %0, 0
%3 = load i8*, i8** @flushall.buffer
%4 = icmp eq i8* %3, null
br i1 %2, label %20, label %5
5: ; preds = %1
br i1 %4, label %6, label %14
6: ; preds = %5
%7 = tail call i64 @malloc(i32 16777216)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** @flushall.buffer
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 16777216)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %6, %5
%15 = phi i8* [ %8, %6 ], [ %3, %5 ]
%16 = load i8, i8* @flushall.val
%17 = add i8 %16, 1
store i8 %17, i8* @flushall.val
%18 = sext i8 %16 to i32
%19 = tail call i32 @memset(i8* %15, i32 %18, i32 16777216)
br label %23
20: ; preds = %1
br i1 %4, label %23, label %21
21: ; preds = %20
%22 = tail call i32 @free(i8* %3)
store i8* null, i8** @flushall.buffer
br label %23
23: ; preds = %20, %21, %14
ret void
}