#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*/ _gigs_log(char *);
double atof(char const *);
int errno;
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, double);
int main(int argc, char *argv[]) {
  double amt;
  double n = 1.0;
  unsigned long i;
  char msgbuf[32];
  char *membuf;
  if (argc > 1) {
    n = atof((const char *)argv[1]);
  }
  sprintf(msgbuf, "allocating %.2fGB", n);
  _gigs_log(msgbuf);
  if (NULL == (membuf = malloc((int)(sizeof(char) * (1048576 * 1024 * n))))) {
    int err = errno;
    _gigs_log("malloc failed");
    return 1;
  }
  _gigs_log("filling buffer");
  for (i = 0; i < (1048576 * 1024 * n); i++) {
    membuf[i] = 'z';
  }
  _gigs_log("exiting");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xea2(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    117f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x20(%rbp)
lea    -0x50(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
lea    0xea1(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x50(%rbp),%rdi
call   1060 <_gigs_log@plt>
movsd  0xe63(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
movsd  0xe4e(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x58(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11f5 <main+0xb5>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
lea    0xe5e(%rip),%rdi
call   1060 <_gigs_log@plt>
movl   $0x1,-0x4(%rbp)
jmp    1277 <main+0x137>
lea    0xe54(%rip),%rdi
call   1060 <_gigs_log@plt>
movq   $0x0,-0x28(%rbp)
movaps 0xe00(%rip),%xmm0
movq   -0x28(%rbp),%xmm1
punpckldq %xmm0,%xmm1
movapd 0xdff(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xdd0(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1264 <main+0x124>
mov    -0x58(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x7a,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1209 <main+0xc9>
lea    0xdf4(%rip),%rdi
call   1060 <_gigs_log@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
cmp    $0x2,%edi
jl     1145 <main+0x15>
mov    0x8(%rsi),%rdi
call   1030 <atof@plt>
jmp    114d <main+0x1d>
movsd  0xeb3(%rip),%xmm0
lea    0xeb4(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <_gigs_log@plt>
lea    0xeac(%rip),%rdi
call   1050 <_gigs_log@plt>
lea    0xeaf(%rip),%rdi
call   1050 <_gigs_log@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"allocating %.2fGB\00"
@errno = global i32 0
@.str.1 = [14 x i8] c"malloc failed\00"
@.str.2 = [15 x i8] c"filling buffer\00"
@.str.3 = [8 x i8] c"exiting\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca i64
%9 = alloca [32 x i8]
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 1.000000e+00, double* %7
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call double @atof(i8* %17)
store double %18, double* %7
br label %19
19: ; preds = %14, %2
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%21 = load double, double* %7
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %21)
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%24 = call i32 @_gigs_log(i8* %23)
%25 = load double, double* %7
%26 = fmul double 0x41D0000000000000, %25
%27 = fmul double 1.000000e+00, %26
%28 = fptosi double %27 to i32
%29 = call i8* @malloc(i32 %28)
store i8* %29, i8** %10
%30 = icmp eq i8* null, %29
br i1 %30, label %31, label %34
31: ; preds = %19
%32 = load i32, i32* @errno
store i32 %32, i32* %11
%33 = call i32 @_gigs_log(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %51
34: ; preds = %19
%35 = call i32 @_gigs_log(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* %8
br label %36
36: ; preds = %46, %34
%37 = load i64, i64* %8
%38 = uitofp i64 %37 to double
%39 = load double, double* %7
%40 = fmul double 0x41D0000000000000, %39
%41 = fcmp olt double %38, %40
br i1 %41, label %42, label %49
42: ; preds = %36
%43 = load i8*, i8** %10
%44 = load i64, i64* %8
%45 = getelementptr inbounds i8, i8* %43, i64 %44
store i8 122, i8* %45
br label %46
46: ; preds = %42
%47 = load i64, i64* %8
%48 = add i64 %47, 1
store i64 %48, i64* %8
br label %36
49: ; preds = %36
%50 = call i32 @_gigs_log(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %51
51: ; preds = %49, %31
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [18 x i8] c"allocating %.2fGB\00"
@errno = global i32 0
@.str.2 = [15 x i8] c"filling buffer\00"
@.str.3 = [8 x i8] c"exiting\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call double @atof(i8* %8)
br label %10
10: ; preds = %6, %2
%11 = phi double [ %9, %6 ], [ 1.000000e+00, %2 ]
%12 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %11)
%13 = call i32 @_gigs_log(i8* %4)
%14 = call i32 @_gigs_log(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @_gigs_log(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}