#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ strtol(char const *, int /*<<< orphan*/ *, int);
int main(int argc, char const *argv[]) {
  if (argc != 2) {
    perror("Need one argument");
    exit(1);
  }
  int size = (int)strtol(argv[1], NULL, 10) * 1000000000;
  char *memory;
  memory = malloc(size * sizeof(char));
  if (memory == NULL) {
    perror("Space not avaible");
    exit(1);
  }
  for (long int i = 0; i < size; i++) {
    memory[i] = 'a';
  }
  free(memory);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1186 <main+0x36>
lea    0xe89(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
imul   $0x3b9aca00,%eax,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d9 <main+0x89>
lea    0xe48(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jge    120f <main+0xbf>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x61,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11e1 <main+0x91>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11bc <main+0x5c>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rbx
imul   $0x3b9aca00,%ebx,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11c5 <main+0x65>
mov    %rax,%r14
test   %ebx,%ebx
jle    11ad <main+0x4d>
cmp    $0x2,%ebp
mov    $0x1,%edx
cmovge %ebp,%edx
mov    %r14,%rdi
mov    $0x61,%esi
call   1040 <memset@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe3d(%rip),%rdi
jmp    11cc <main+0x6c>
lea    0xe46(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Need one argument\00"
@.str.1 = [18 x i8] c"Space not avaible\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 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 @strtol(i8* %17, i32* null, i32 10)
%19 = trunc i64 %18 to i32
%20 = mul nsw i32 %19, 1000000000
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 1
%24 = trunc i64 %23 to i32
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %14
%29 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %14
store i64 0, i64* %8
br label %32
32: ; preds = %41, %31
%33 = load i64, i64* %8
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %37, label %44
37: ; preds = %32
%38 = load i8*, i8** %7
%39 = load i64, i64* %8
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 97, i8* %40
br label %41
41: ; preds = %37
%42 = load i64, i64* %8
%43 = add nsw i64 %42, 1
store i64 %43, i64* %8
br label %32
44: ; preds = %32
%45 = load i8*, i8** %7
%46 = call i32 @free(i8* %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Need one argument\00"
@.str.1 = [18 x i8] c"Space not avaible\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strtol(i8* nocapture %9, i32* null, i32 10)
%11 = trunc i64 %10 to i32
%12 = mul nsw i32 %11, 1000000000
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %7
%16 = icmp sgt i32 %11, 0
br i1 %16, label %17, label %23
17: ; preds = %15
%18 = call i32 @llvm.smax.i32(i32 %12, i32 1)
%19 = zext i32 %18 to i64
br label %23
20: ; preds = %7
%21 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %17, %15
%24 = tail call i32 @free(i8* %13)
ret i32 0
}