#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 */
scalar_t__ calloc(unsigned long, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, unsigned long *);
int main(int argc, char *argv[]) {
  unsigned long num;
  int *ptr;
  printf("Enter the number of type int to allocate: ");
  scanf("%ld", &num);
  ptr = (int *)calloc(num, sizeof(long long));
  if (ptr != NULL)
    puts("Memory allocation was successful.");
  else
    puts("Memory allocation failed.");
  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)
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
lea    0xec2(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a0 <main+0x60>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
jmp    11ac <main+0x6c>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
call   1040 <printf@plt>
lea    0xed7(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%rdi
mov    $0x8,%esi
call   1050 <calloc@plt>
test   %rax,%rax
lea    0xedd(%rip),%rax
lea    0xeb4(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Enter the number of type int to allocate: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [34 x i8] c"Memory allocation was successful.\00"
@.str.3 = [26 x i8] c"Memory allocation failed.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %6)
%10 = load i64, i64* %6
%11 = call i64 @calloc(i64 %10, i32 8)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @puts(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %19
17: ; preds = %2
%18 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
ret i32 0
}

LLVM IR (-O2):
@.str = [43 x i8] c"Enter the number of type int to allocate: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [34 x i8] c"Memory allocation was successful.\00"
@.str.3 = [26 x i8] c"Memory allocation failed.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%7 = load i64, i64* %3
%8 = call i64 @calloc(i64 %7, i32 8)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0)
%11 = call i32 @puts(i8* dereferenceable(1) %10)
ret i32 0
}