#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 *, size_t);
char *malloc(size_t);
int /*<<< orphan*/ printf(char *, size_t);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
void fill_some(size_t n, char ch) {
  size_t bytes = n * (size_t)1024 * (size_t)1024;
  char *b = malloc(bytes);
  if (!b) {
    fprintf(stderr, "Failed to allocate %zu MiB\n", n);
    exit(1);
  }
  printf("Allocating %zu MiBs\n", n);
  for (size_t i = 0; i < bytes; i += 1024) {
    b[i] = ch;
  }
  sleep(1);
}


x86 assembly (clang, -O0):
<fill_some>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
shl    $0xa,%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ad <fill_some+0x5d>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe62(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11f4 <fill_some+0xa4>
mov    -0x9(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x400,%rax
mov    %rax,-0x28(%rbp)
jmp    11c5 <fill_some+0x75>
mov    $0x1,%edi
call   1070 <sleep@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_some>:
push   %rax
mov    %rdi,%rsi
lea    0xed5(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
pop    %rax
jmp    1040 <sleep@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Failed to allocate %zu MiB\0A\00"
@.str.1 = [21 x i8] c"Allocating %zu MiBs\0A\00"
define void @fill_some(i64 %0, i8 signext %1) {
%3 = alloca i64
%4 = alloca i8
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i64 %0, i64* %3
store i8 %1, i8* %4
%8 = load i64, i64* %3
%9 = mul i64 %8, 1024
%10 = mul i64 %9, 1024
store i64 %10, i64* %5
%11 = load i64, i64* %5
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i64, i64* %3
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i64, i64* %3
%22 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %21)
store i64 0, i64* %7
br label %23
23: ; preds = %32, %20
%24 = load i64, i64* %7
%25 = load i64, i64* %5
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = load i8, i8* %4
%29 = load i8*, i8** %6
%30 = load i64, i64* %7
%31 = getelementptr inbounds i8, i8* %29, i64 %30
store i8 %28, i8* %31
br label %32
32: ; preds = %27
%33 = load i64, i64* %7
%34 = add i64 %33, 1024
store i64 %34, i64* %7
br label %23
35: ; preds = %23
%36 = call i32 @sleep(i32 1)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [21 x i8] c"Allocating %zu MiBs\0A\00"
define void @fill_some(i64 %0, i8 signext %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %0)
%4 = tail call i32 @sleep(i32 1)
ret void
}