#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 */
char *alloc_workbuf(size_t);
size_t atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  size_t size;
  char *memhog = NULL;
  if (argc != 2) {
    fprintf(stderr, "Usage: memhog <size in GB>\n");
    exit(-1);
  }
  size = atoi(argv[1]);
  memhog = alloc_workbuf(size * 1024 * 1024 * 1024UL);
  if (!memhog) {
    fprintf(stderr, "Could not allocate %ld GB\n", size);
    exit(-1);
  }
  while (memhog)
    sleep(10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1199 <main+0x49>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0xa,%rdi
shl    $0xa,%rdi
shl    $0xa,%rdi
call   1030 <alloc_workbuf@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f3 <main+0xa3>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    11f8 <main+0xa8>
cmpq   $0x0,-0x20(%rbp)
je     1212 <main+0xc2>
mov    $0xa,%edi
call   1070 <sleep@plt>
jmp    11f8 <main+0xa8>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    118c <main+0x3c>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %rax,%rbx
mov    %rax,%rdi
shl    $0x1e,%rdi
call   1030 <alloc_workbuf@plt>
test   %rax,%rax
je     11ad <main+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
call   1070 <sleep@plt>
jmp    1180 <main+0x30>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: memhog <size in GB>\0A\00"
@.str.1 = [27 x i8] c"Could not allocate %ld GB\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @atoi(i8* %17)
store i64 %18, i64* %6
%19 = load i64, i64* %6
%20 = mul i64 %19, 1024
%21 = mul i64 %20, 1024
%22 = mul i64 %21, 1024
%23 = call i8* @alloc_workbuf(i64 %22)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %31, label %26
26: ; preds = %14
%27 = load i32, i32* @stderr
%28 = load i64, i64* %6
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %28)
%30 = call i32 @exit(i32 -1)
unreachable
31: ; preds = %14
br label %32
32: ; preds = %35, %31
%33 = load i8*, i8** %7
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @sleep(i32 10)
br label %32
37: ; preds = %32
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: memhog <size in GB>\0A\00"
@.str.1 = [27 x i8] c"Could not allocate %ld GB\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atoi(i8* %10)
%12 = shl i64 %11, 30
%13 = tail call i8* @alloc_workbuf(i64 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %11)
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %8, %19
%20 = tail call i32 @sleep(i32 10)
br label %19
}