#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 */
void *calloc(int, size_t);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, size_t);
void *xcalloc(size_t size) {
  if (size > 10485760) {
    printf("Big calloc %u!\n", size);
  }
  void *m = calloc(1, size);
  if (m == NULL) {
    printf("Out of Memory! @ calloc size %u\n", size);
    exit(1);
  }
  return m;
}


x86 assembly (clang, -O0):
<xcalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0xa00000,-0x8(%rbp)
jbe    115a <xcalloc+0x2a>
mov    -0x8(%rbp),%rsi
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1191 <xcalloc+0x61>
mov    -0x8(%rbp),%rsi
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcalloc>:
push   %rbx
mov    %rdi,%rbx
cmp    $0xa00001,%rdi
jb     114c <xcalloc+0x1c>
lea    0xebc(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1040 <calloc@plt>
test   %rax,%rax
je     1160 <xcalloc+0x30>
pop    %rbx
ret
lea    0xea9(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"Big calloc %u!\0A\00"
@.str.1 = [33 x i8] c"Out of Memory! @ calloc size %u\0A\00"
define i8* @xcalloc(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = icmp ugt i64 %4, 10485760
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i64, i64* %2
%8 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 %7)
br label %9
9: ; preds = %6, %1
%10 = load i64, i64* %2
%11 = call i8* @calloc(i32 1, i64 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i64, i64* %2
%16 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = load i8*, i8** %3
ret i8* %19
}

LLVM IR (-O2):
@.str = [16 x i8] c"Big calloc %u!\0A\00"
@.str.1 = [33 x i8] c"Out of Memory! @ calloc size %u\0A\00"
define i8* @xcalloc(i64 %0) {
%2 = icmp ugt i64 %0, 10485760
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 %0)
br label %5
5: ; preds = %3, %1
%6 = tail call i8* @calloc(i32 1, i64 %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5
ret i8* %6
}