#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(void *);
void *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  void *ptr1, *ptr2;
  ptr1 = malloc(3000000);
  if (ptr1 != NULL)
    printf("\nFirst allocation of %d bytes successful.", 3000000);
  else {
    printf("\nAttempt to allocate %d bytes failed.\n", 3000000);
    exit(1);
  }
  ptr2 = malloc(3000000);
  if (ptr2 != NULL) {
    printf("\nSecond allocation of %d bytes successful.\n", 3000000);
    exit(0);
  }
  printf("\nSecond attempt to allocate %d bytes failed.", 3000000);
  free(ptr1);
  printf("\nFreeing first block.");
  ptr2 = malloc(3000000);
  if (ptr2 != NULL)
    printf("\nAfter free(), allocation of %d bytes successful.\n", 3000000);
  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)
mov    $0x2dc6c0,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1187 <main+0x47>
lea    0xe8a(%rip),%rdi
mov    $0x2dc6c0,%esi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a4 <main+0x64>
lea    0xe9c(%rip),%rdi
mov    $0x2dc6c0,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x2dc6c0,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d7 <main+0x97>
lea    0xe8d(%rip),%rdi
mov    $0x2dc6c0,%esi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0xe9f(%rip),%rdi
mov    $0x2dc6c0,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2dc6c0,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     122d <main+0xed>
lea    0xe9f(%rip),%rdi
mov    $0x2dc6c0,%esi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
mov    $0x2dc6c0,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeef(%rip),%rdi
mov    $0x2dc6c0,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"\0AFirst allocation of %d bytes successful.\00"
@.str.1 = [39 x i8] c"\0AAttempt to allocate %d bytes failed.\0A\00"
@.str.2 = [44 x i8] c"\0ASecond allocation of %d bytes successful.\0A\00"
@.str.3 = [45 x i8] c"\0ASecond attempt to allocate %d bytes failed.\00"
@.str.4 = [22 x i8] c"\0AFreeing first block.\00"
@.str.5 = [51 x i8] c"\0AAfter free(), allocation of %d bytes successful.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i8* @malloc(i32 3000000)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 3000000)
br label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 3000000)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %11
%17 = call i8* @malloc(i32 3000000)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 3000000)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %16
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 3000000)
%25 = load i8*, i8** %6
%26 = call i32 @free(i8* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%28 = call i8* @malloc(i32 3000000)
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), i32 3000000)
br label %33
33: ; preds = %31, %23
ret i32 0
}

LLVM IR (-O2):
@.str = [42 x i8] c"\0AFirst allocation of %d bytes successful.\00"
@.str.2 = [44 x i8] c"\0ASecond allocation of %d bytes successful.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 3000000)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 3000000)
%5 = tail call i32 @exit(i32 0)
unreachable
}