#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 EXIT_FAILURE;
int EXIT_SUCCESS;
size_t atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *malloc(size_t);
int /*<<< orphan*/ printf(char *, size_t, size_t);
scalar_t__ rand();
int /*<<< orphan*/ sleep(size_t);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 3) {
    fprintf(stderr, "%s <how much mem in mb> <for how long in s>\n", argv[0]);
    return EXIT_FAILURE;
  }
  size_t how_much = atoi(argv[1]);
  how_much = how_much > 1024 ? 1024 : how_much;
  how_much <<= 20;
  size_t how_long = atoi(argv[2]);
  printf("%d-%d\n", how_much, how_long);
  char *q, *p = malloc(how_much);
  for (q = p; q != p + how_much; q++) {
    *q = (char)rand();
  }
  sleep(how_long);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11ad <main+0x4d>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127a <main+0x11a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x400,-0x18(%rbp)
jbe    11da <main+0x7a>
mov    $0x400,%eax
mov    %rax,-0x38(%rbp)
jmp    11e2 <main+0x82>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
add    -0x18(%rbp),%rcx
cmp    %rcx,%rax
je     1265 <main+0x105>
mov    $0x0,%al
call   1080 <rand@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1230 <main+0xd0>
mov    -0x20(%rbp),%rdi
call   1070 <sleep@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11f5 <main+0x95>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
cmp    $0x400,%rax
mov    $0x400,%r13d
cmovb  %rax,%r13
mov    %r13,%r15
shl    $0x14,%r15
mov    0x10(%rbx),%rdi
call   1060 <atoi@plt>
mov    %rax,%r14
lea    0xe85(%rip),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    %r15,%rdi
call   1050 <malloc@plt>
test   %r13,%r13
je     11e4 <main+0x84>
mov    %rax,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1080 <rand@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11d0 <main+0x70>
mov    %r14,%rdi
call   1070 <sleep@plt>
mov    0x2ddd(%rip),%rax
jmp    1214 <main+0xb4>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdf8(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"%s <how much mem in mb> <for how long in s>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"%d-%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %60
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @atoi(i8* %22)
store i64 %23, i64* %6
%24 = load i64, i64* %6
%25 = icmp ugt i64 %24, 1024
br i1 %25, label %26, label %27
26: ; preds = %19
br label %29
27: ; preds = %19
%28 = load i64, i64* %6
br label %29
29: ; preds = %27, %26
%30 = phi i64 [ 1024, %26 ], [ %28, %27 ]
store i64 %30, i64* %6
%31 = load i64, i64* %6
%32 = shl i64 %31, 20
store i64 %32, i64* %6
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i64 @atoi(i8* %35)
store i64 %36, i64* %7
%37 = load i64, i64* %6
%38 = load i64, i64* %7
%39 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %37, i64 %38)
%40 = load i64, i64* %6
%41 = call i8* @malloc(i64 %40)
store i8* %41, i8** %9
%42 = load i8*, i8** %9
store i8* %42, i8** %8
br label %43
43: ; preds = %53, %29
%44 = load i8*, i8** %8
%45 = load i8*, i8** %9
%46 = load i64, i64* %6
%47 = getelementptr inbounds i8, i8* %45, i64 %46
%48 = icmp ne i8* %44, %47
br i1 %48, label %49, label %56
49: ; preds = %43
%50 = call i64 (...) @rand()
%51 = trunc i64 %50 to i8
%52 = load i8*, i8** %8
store i8 %51, i8* %52
br label %53
53: ; preds = %49
%54 = load i8*, i8** %8
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %8
br label %43
56: ; preds = %43
%57 = load i64, i64* %7
%58 = call i32 @sleep(i64 %57)
%59 = load i32, i32* @EXIT_SUCCESS
store i32 %59, i32* %3
br label %60
60: ; preds = %56, %12
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"%s <how much mem in mb> <for how long in s>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"%d-%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %30
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atoi(i8* %10)
%12 = icmp ult i64 %11, 1024
%13 = select i1 %12, i64 %11, i64 1024
%14 = shl nuw nsw i64 %13, 20
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i64 @atoi(i8* %16)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %14, i64 %17)
%19 = tail call i8* @malloc(i64 %14)
%20 = getelementptr inbounds i8, i8* %19, i64 %14
%21 = icmp eq i64 %13, 0
br i1 %21, label %28, label %22
22: ; preds = %8, %22
%23 = phi i8* [ %26, %22 ], [ %19, %8 ]
%24 = tail call i64 (...) @rand()
%25 = trunc i64 %24 to i8
store i8 %25, i8* %23
%26 = getelementptr inbounds i8, i8* %23, i64 1
%27 = icmp eq i8* %26, %20
br i1 %27, label %28, label %22
28: ; preds = %22, %8
%29 = tail call i32 @sleep(i64 %17)
br label %30
30: ; preds = %28, %4
%31 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_SUCCESS, %28 ]
%32 = load i32, i32* %31
ret i32 %32
}