void *setup(void) {
  unsigned int i;
  char *mem;
  mem = malloc(64 * 1024 * 1024);
  if (!mem)
    err(1, "allocating %i bytes", 64 * 1024 * 1024);
  for (i = 0; i < 64 * 1024 * 1024; i += getpagesize())
    mem[i] = i;
  return mem;
}


x86 assembly (clang, -O0):
<setup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x4000000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1169 <setup+0x39>
mov    $0x1,%edi
lea    0xea3(%rip),%rsi
mov    $0x4000000,%edx
mov    $0x0,%al
call   1030 <err@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x4000000,-0x4(%rbp)
jae    119e <setup+0x6e>
mov    -0x4(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    $0x0,%al
call   1050 <getpagesize@plt>
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1170 <setup+0x40>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup>:
push   %rbp
push   %rbx
push   %rax
mov    $0x4000000,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    115d <setup+0x2d>
lea    0xeb4(%rip),%rsi
mov    $0x1,%edi
mov    $0x4000000,%edx
xor    %eax,%eax
call   1030 <err@plt>
xor    %ebp,%ebp
nop
mov    %ebp,%eax
mov    %bpl,(%rbx,%rax,1)
xor    %eax,%eax
call   1050 <getpagesize@plt>
add    %eax,%ebp
cmp    $0x4000000,%ebp
jb     1160 <setup+0x30>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"allocating %i bytes\00"
define i8* @setup() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i8* @malloc(i64 67108864)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @err to i32 (i32, i8*, i32, ...)*)(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 67108864)
br label %8
8: ; preds = %6, %0
store i32 0, i32* %1
br label %9
9: ; preds = %19, %8
%10 = load i32, i32* %1
%11 = icmp ult i32 %10, 67108864
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i32, i32* %1
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %2
%16 = load i32, i32* %1
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 %14, i8* %18
br label %19
19: ; preds = %12
%20 = call i32 (...) @getpagesize()
%21 = load i32, i32* %1
%22 = add i32 %21, %20
store i32 %22, i32* %1
br label %9
23: ; preds = %9
%24 = load i8*, i8** %2
ret i8* %24
}

LLVM IR (-O2):
@.str = [20 x i8] c"allocating %i bytes\00"
define i8* @setup() {
%1 = tail call dereferenceable_or_null(67108864) i8* @malloc(i64 67108864)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @err to i32 (i32, i8*, i32, ...)*)(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 67108864)
br label %5
5: ; preds = %3, %0
br label %6
6: ; preds = %5, %6
%7 = phi i32 [ %12, %6 ], [ 0, %5 ]
%8 = trunc i32 %7 to i8
%9 = zext i32 %7 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %8, i8* %10
%11 = tail call i32 (...) @getpagesize()
%12 = add i32 %11, %7
%13 = icmp ult i32 %12, 67108864
br i1 %13, label %6, label %14
14: ; preds = %6
ret i8* %1
}